Container for InSlots and OutSlots. More...
#include <InstantIO/Namespace.h>
Classes | |
class | ExternalRoute |
Represents an external route. More... | |
class | LabeledInSlot |
Combines an InSlot, a label, and a reference counter. More... | |
class | LabeledOutSlot |
Combines an OutSlot, a label, and a reference counter. More... | |
class | LabeledSlot |
Combines a Slot and a label. More... | |
class | Listener |
Allows to receive information about the status of a Namespace. More... | |
class | Route |
Represents a route. More... | |
Public Member Functions | |
void | addListener (Listener &listener) |
Adds a Listener to the Namespace. | |
void | removeListener (Listener &listener) |
Removes a Listener from the Namespace. | |
virtual void | enable () |
Enables the Namespace. | |
virtual void | disable () |
Disables the Namespace. | |
bool | enabled () const |
Returns if the Namespace is enabled or disabled. | |
const std::string & | getLabel () const |
Returns the label of the Namespace. | |
virtual std::string | typeName () const |
Returns the type name of the Namespace. | |
void | clear () |
Removes all routes, external routes and subnamespaces from this Namespace. | |
virtual bool | saveState () const |
Returns if the contents of this Namespace should be saved. | |
bool | dirty () const |
Returns if this Namespaces has unsaved changes. | |
void | setDirty (bool dirty) |
Sets the status of the dirty flag. | |
void | setBaseURL (const Hermes::URL &url) |
Sets the base URL of the Namespace. | |
const Hermes::URL & | getBaseURL () const |
Returns the base URL of the Namespace. | |
Medusa::Mutex * | upMutex () const |
Returns the mutex that protects the Namespace. | |
void | setFieldValues (const std::string ¶mLine) |
Sets the values of fields from a line of parameters. | |
virtual void | setFieldValue (const std::string &name, const std::string &value) |
Sets the value of a field. | |
virtual std::string | getFieldValue (const std::string &name) const |
Returns the value of a field. | |
virtual void | getFieldNames (std::vector< std::string > &names) const |
Returns the names of all fields. | |
Constructors and destructor | |
Namespace () | |
Creates a new Namespace object. | |
virtual | ~Namespace () |
Destroys a Namespace object. | |
Protected Member Functions | |
virtual void | initialize () |
Gets called when the Namespace is enabled. | |
virtual void | shutdown () |
Gets called when the Namespace is disabled. | |
LabeledOutSlotVector::iterator | findOutSlot (const std::string &label, BasicOutSlot *outSlot) |
Tries to find an OutSlot in the vector of OutSlots contained in this Namespace. | |
void | getRoutedOutSlots (const std::string &label, LabeledOutSlotVector &outSlotVector) |
Returns all OutSlots that have routes to a given InSlot label. | |
void | getExportedOutSlots (const std::string &label, LabeledOutSlotVector &outSlotVector) |
Returns all OutSlots that match a given external label. | |
LabeledInSlotVector::iterator | findInSlot (const std::string &label, BasicInSlot *inSlot) |
Tries to find an InSlot in the vector of InSlots contained in this Namespace. | |
void | getRoutedInSlots (const std::string &label, LabeledInSlotVector &inSlotVector) |
Returns all InSlots that have routes to a given OutSlot label. | |
void | getExportedInSlots (const std::string &label, LabeledInSlotVector &inSlotVector) |
Returns all InSlots that match a given external label. | |
ExternalRouteVector::iterator | findExternalRoute (const std::string &internal, const std::string &external) |
Tries to find an external route in the vector of external routes contained in this Namespace. | |
void | removeExternalRoute (const ExternalRouteVector::const_iterator &it) |
Removes an external route from the Namespace. | |
RouteVector::iterator | findRoute (const std::string &from, const std::string &to) |
Tries to find a route in the vector of routes contained in this Namespace. | |
void | removeRoute (const RouteVector::const_iterator &it) |
Removes a route from the Namespace. | |
std::string | createUniqueLabel (const std::string &label) const |
Creates a unique name for a child Namespace. | |
Protected Attributes | |
Medusa::Mutex * | upMutex_ |
Up-Locks the Namespace object. | |
Medusa::Mutex * | downMutex_ |
Down-Locks the Namespace object. | |
Namespace * | parentNamespace_ |
The parent Namespace of the Namespace. | |
bool | enabled_ |
The "enabled" flag - true when the Namespace is enabled. | |
std::string | label_ |
The label of the Namespace. | |
LabeledOutSlotVector | outSlots_ |
The Vector that contains all OutSlots of the Namespace. | |
LabeledInSlotVector | inSlots_ |
The Vector that contains all InSlots of the Namespace. | |
ExternalRouteVector | externalRoutes_ |
Contains all external routes of the Namespace. | |
RouteVector | routes_ |
Contains all routes of the Namespace. | |
NamespaceMap | namespaces_ |
Contains all child Namespaces of the Namespace. | |
Slot interface | |
| |
typedef std::vector< LabeledSlot > | LabeledSlotVector |
Defines the vector of labeled Slots. | |
virtual void | removeSlot (const std::string &label, Slot *slot) |
Removes a Slot from the Namespace. | |
virtual void | getSlots (const std::string &label, Slot::Direction direction, LabeledSlotVector &slotVector) |
Returns all slots that match a label and a direction. | |
Outslot interface | |
| |
typedef std::vector < LabeledOutSlot > | LabeledOutSlotVector |
Defines the vector of OutSlots. | |
virtual void | addOutSlot (const std::string &label, BasicOutSlot *outSlot) |
Adds an OutSlot to the Namespace. | |
virtual void | removeOutSlot (const std::string &label, BasicOutSlot *outSlot) |
Removes an OutSlot from the Namespace. | |
virtual void | getOutSlots (const std::string &label, LabeledOutSlotVector &outSlotVector) |
Returns all OutSlots that match a label. | |
Inslot interface | |
| |
typedef std::vector < LabeledInSlot > | LabeledInSlotVector |
Defines the vector of InSlots. | |
virtual void | addInSlot (const std::string &label, BasicInSlot *inSlot) |
Adds an InSlot to the Namespace. | |
virtual void | removeInSlot (const std::string &label, BasicInSlot *inSlot) |
Removes an InSlot from the Namespace. | |
virtual void | getInSlots (const std::string &label, LabeledInSlotVector &inSlotVector) |
Returns all InSlots that match a label. | |
External routes interface | |
| |
typedef std::vector < ExternalRoute * > | ExternalRouteVector |
Defines the vector of external routes. | |
void | addExternalRoute (const std::string &internal, const std::string &external) |
Adds an external route to the Namespace. | |
void | removeExternalRoute (const std::string &internal, const std::string &external) |
Removes an external route from the Namespace. | |
void | getExternalRoutes (ExternalRouteVector &externalRoutes) const |
Returns all external routes of the Namespace. | |
ExternalRouteVector | getExternalRoutesForInternal (const std::string &internal) const |
Returns all external routes that match a given internal label. | |
void | clearExternalRoutes () |
Removes all external routes from the Namespace. | |
route interface | |
| |
typedef std::vector< Route > | RouteVector |
Defines the vector of routes. | |
void | addRoute (const std::string &from, const std::string &to) |
Adds a route to the Namespace. | |
void | removeRoute (const std::string &from, const std::string &to) |
Removes a route from the Namespace. | |
void | getRoutes (RouteVector &routes) const |
Returns all routes of the Namespace. | |
void | getRoutesFrom (const std::string &from, RouteVector &routes) |
Returns all routes that match a given "from" label. | |
void | getRoutesTo (const std::string &to, RouteVector &routes) |
Returns all routes that match a given "to" label. | |
void | clearRoutes () |
Removes all routes from the Namespace. | |
namespace interface | |
| |
typedef std::map< std::string, Namespace * > | NamespaceMap |
Defines the map that holds all subnamespaces. | |
const std::string & | addNamespace (std::auto_ptr< Namespace > ns) |
Adds a subnamespace to this Namespace. | |
const std::string & | addNamespace (std::auto_ptr< Node > ns) |
Adds a subnamespace to this Namespace. | |
const std::string & | addNamespace (const std::string &label, std::auto_ptr< Namespace > ns) |
Adds a Subnamespace to this Namespace. | |
const std::string & | addNamespace (const std::string &label, std::auto_ptr< Node > ns) |
Adds a Subnamespace to this Namespace. | |
std::auto_ptr< Namespace > | removeNamespace (const std::string &label) |
Removes a Subnamespace from this Namespace. | |
Namespace * | getNamespace (const std::string &label) const |
Returns a subnamespace that matches a given label. | |
NamespaceMap & | getNamespaces () |
Returns all subnamespaces contained in this Namespace. | |
const NamespaceMap & | getNamespaces () const |
Returns all subnamespaces contained in this Namespace. | |
void | clearNamespaces () |
Removes all subnamespaces from this Namespace. |
Container for InSlots and OutSlots.
Namespace objects are used to automatically connect InSlots and OutSlots. InSlots and OutSlots connect to each other when they
So, when you use the InstantIO system to exchange data values between different software components, you usually create a Namespace, add your InSlots and OutSlots to that namespace, and create routes between these InSlots and OutSlots. The following piece of code demonstrates how to connect an OutSlot "out" to an InSlot "in":
include <InstantIO/Namespace.h> include <InstantIO/OutSlot.h> include <InstantIO/InSlot.h> ... // Create the namespace InstantIO::Namespace namespace;
// Create the outslot and add it to the namespace InstantIO::OutSlot<int> outSlot; namespace.addOutSlot("out", outSlot);
// Create the inslot and add it to the namespace InstantIO::InSlot<int> inSlot; namespace.addInSlot("in", inSlot);
// Create a route that maps "out" to "in" namespace.addRoute("out", "in");
// Enable the namespace namespace.enable(); ...
In this example, the OutSlot and the InSlot get connected when the namespace is enabled. A namespace is disabled by default. A namespace connects OutSlots and InSlots only when it is enabled. It is perfectly ok to enable the namespace before you add any OutSlots, InSlots and routes. In this case OutSlots and InSlots get connected as soon as all preconditions to connect the are fulfilled.
In the example above, we created a new Namespace object. But when there are lots of different software components that need to exchange data, it gets difficult to provide them with the same namespace object. For this reason, a special descendant of the Namespace class exists: The Root singleton. Exactly one instance of this class exists in an application. So all software components can obtain this single instance and add their OutSlots and InSlots to it. The following piece of code demonstrates how to do that:
include <InstantIO/Root.h> ... // Get the root namespace InstantIO::Namespace &root = InstantIO::Root::the();
// Add OutSlots and InSlots to the root namespace root.addOutSlot("out", outSlot); root.addInSlot("in", inSlot); ...
The Root singleton is enabled by default.
Besides of adding slots and routes to namespaces, you can also add subnamespaces. Subnamespaces are normal Namespace objects, i.e. you can add slots and routes to them. By using so-called "external routes", you can export OutSlots and InSlots from subnamespaces to their parent namespace. The following piece of code demonstrates how to create a subnamespace, and how to export the slots in the subname to the parent namespace.
... // Get the root namespace InstantIO::Namespace &root = InstantIO::Root::the();
// Create a subnamespace std::auto_ptr<InstantIO::Namespace> subnamespace = new InstantIO::Namespace;
// Create the outslot and add it to the subnamespace InstantIO::OutSlot<int> outSlot; subnamespace->addOutSlot("subout", outSlot);
// Create the inslot and add it to the subnamespace InstantIO::InSlot<int> inSlot; subnamespace->addInSlot("subin", inSlot);
// Export the outslot as "out" to the root namespace subnamespace->addExternalRoute("subout", "out");
// Export the inslot as "in" to the root namespace subnamespace->addExternalRoute("subin", "in");
// Create a route that maps "out" to "in" in the root // namespace root.addRoute("out", "in");
// Add the subnamespace to the root namespace root.addNamespace("label", subnamespace); ...
In the example above, the outslot and the inslot get connected, because there is a route from "out" to "in", and the outslot and the inslot are exported under these labels into the root namespace.
Subnamespaces inherit the enabled/disabled state of their parent namespace. I.e. when you add a namespace to an enabled namespace, it gets enabled, and when you add a namespace to a disabled namespace, it gets disabled. When you enabled or disable a parent namespace, the subnamespaces get enabled or disabled likewise.
InstantIO::Namespace::Namespace | ( | ) |
Creates a new Namespace object.
The Namespace is disabled by default and contains no slots, subnamespaces or routes.
void InstantIO::Namespace::addListener | ( | Listener & | listener | ) |
void InstantIO::Namespace::removeListener | ( | Listener & | listener | ) |
Removes a Listener from the Namespace.
listener | The listener. |
virtual void InstantIO::Namespace::enable | ( | ) | [virtual] |
virtual void InstantIO::Namespace::disable | ( | ) | [virtual] |
bool InstantIO::Namespace::enabled | ( | ) | const |
Returns if the Namespace is enabled or disabled.
Namespaces only connect their OutSlots and InSlots when they are enabled.
const std::string& InstantIO::Namespace::getLabel | ( | ) | const [inline] |
Returns the label of the Namespace.
virtual std::string InstantIO::Namespace::typeName | ( | ) | const [virtual] |
virtual bool InstantIO::Namespace::saveState | ( | ) | const [virtual] |
Returns if the contents of this Namespace should be saved.
The default implementation of this method always returns true. Overwrite this method when you implement a Node whoose contents should not be saved.
bool InstantIO::Namespace::dirty | ( | ) | const |
Returns if this Namespaces has unsaved changes.
void InstantIO::Namespace::setDirty | ( | bool | dirty | ) |
Sets the status of the dirty flag.
The dirty flag is set (true) when the Namespaces has unsaved changes.
dirty | true when the Namespace needs to be saved, false otherwise. When you set the dirty flag to true, this method also sets the dirty flags of all parent namespaces to true. When you set the dirty flag to false, this method also sets the dirty flag of all children namespaces to false. |
void InstantIO::Namespace::setBaseURL | ( | const Hermes::URL & | url | ) |
Sets the base URL of the Namespace.
The base URL is used by Nodes to resolve relative URLs.
url | The base URL. |
const Hermes::URL& InstantIO::Namespace::getBaseURL | ( | ) | const |
Returns the base URL of the Namespace.
The base URL is used by Nodes to resolve relative URLs.
Medusa::Mutex* InstantIO::Namespace::upMutex | ( | ) | const [inline] |
Returns the mutex that protects the Namespace.
void InstantIO::Namespace::setFieldValues | ( | const std::string & | paramLine | ) |
Sets the values of fields from a line of parameters.
The parameter line is a set of key-value parameters like this: "key1=value1 key2=value2". This method extracts the key-value pairs and calls setFieldValue(key, value).
paramLine | A string consisting of key-value pairs. |
virtual void InstantIO::Namespace::setFieldValue | ( | const std::string & | name, | |
const std::string & | value | |||
) | [virtual] |
Sets the value of a field.
name | The name of the field. | |
value | The new value of the field. |
Reimplemented in InstantIO::Node.
virtual std::string InstantIO::Namespace::getFieldValue | ( | const std::string & | name | ) | const [virtual] |
Returns the value of a field.
name | The name of the field. |
Reimplemented in InstantIO::Node.
virtual void InstantIO::Namespace::getFieldNames | ( | std::vector< std::string > & | names | ) | const [virtual] |
Returns the names of all fields.
names | A vector that gets filled with the names. |
Reimplemented in InstantIO::Node.
virtual void InstantIO::Namespace::removeSlot | ( | const std::string & | label, | |
Slot * | slot | |||
) | [virtual] |
virtual void InstantIO::Namespace::getSlots | ( | const std::string & | label, | |
Slot::Direction | direction, | |||
LabeledSlotVector & | slotVector | |||
) | [virtual] |
Returns all slots that match a label and a direction.
label | The label used for filtering the slots. | |
direction | The direction of the slots you are interested in. | |
slotVector | A vector that gets filled with the matching slots. |
virtual void InstantIO::Namespace::addOutSlot | ( | const std::string & | label, | |
BasicOutSlot * | outSlot | |||
) | [virtual] |
virtual void InstantIO::Namespace::removeOutSlot | ( | const std::string & | label, | |
BasicOutSlot * | outSlot | |||
) | [virtual] |
virtual void InstantIO::Namespace::getOutSlots | ( | const std::string & | label, | |
LabeledOutSlotVector & | outSlotVector | |||
) | [virtual] |
Returns all OutSlots that match a label.
label | The label used for filtering the OutSlots. | |
outSlotVector | A vector that gets filled with the matching OutSlots. |
virtual void InstantIO::Namespace::addInSlot | ( | const std::string & | label, | |
BasicInSlot * | inSlot | |||
) | [virtual] |
virtual void InstantIO::Namespace::removeInSlot | ( | const std::string & | label, | |
BasicInSlot * | inSlot | |||
) | [virtual] |
virtual void InstantIO::Namespace::getInSlots | ( | const std::string & | label, | |
LabeledInSlotVector & | inSlotVector | |||
) | [virtual] |
Returns all InSlots that match a label.
label | The label used for filtering the InSlots. | |
inSlotVector | A vector that gets filled with the matching InSlots. |
void InstantIO::Namespace::addExternalRoute | ( | const std::string & | internal, | |
const std::string & | external | |||
) |
Adds an external route to the Namespace.
External routes are used to export slots to the parent namespace. All slots whose label matches the internal label of the route are exported to the parent namespace under the external label of the route.
internal | The internal label. | |
external | The external label. |
void InstantIO::Namespace::removeExternalRoute | ( | const std::string & | internal, | |
const std::string & | external | |||
) |
Removes an external route from the Namespace.
All slots that are exported to the parent namespace by this route are removed from the parent namespace.
internal | The internal label. | |
external | The external label. |
void InstantIO::Namespace::getExternalRoutes | ( | ExternalRouteVector & | externalRoutes | ) | const |
Returns all external routes of the Namespace.
externalRoutes | A vector that gets filled with all external routes of the Namespace. |
ExternalRouteVector InstantIO::Namespace::getExternalRoutesForInternal | ( | const std::string & | internal | ) | const |
Returns all external routes that match a given internal label.
internal | The internal label. |
void InstantIO::Namespace::addRoute | ( | const std::string & | from, | |
const std::string & | to | |||
) |
Adds a route to the Namespace.
All OutSlots in the Namespace that match the "from" label of the route are connected to all InSlots in the Namespace that match the "to" label and have the same data type.
from | The "from" label. | |
to | The "to" label. |
void InstantIO::Namespace::removeRoute | ( | const std::string & | from, | |
const std::string & | to | |||
) |
Removes a route from the Namespace.
All OutSlots and InSlots that are connected by this route are disconnected.
from | The "from" label. | |
to | The "to" label. |
void InstantIO::Namespace::getRoutes | ( | RouteVector & | routes | ) | const |
Returns all routes of the Namespace.
routes | A vector that gets filled with all routes contained in the Namespace. |
void InstantIO::Namespace::getRoutesFrom | ( | const std::string & | from, | |
RouteVector & | routes | |||
) |
Returns all routes that match a given "from" label.
from | The "from" label. | |
routes | A Vector of Route objects that gets filled with all Routes that match the given "from" label. |
void InstantIO::Namespace::getRoutesTo | ( | const std::string & | to, | |
RouteVector & | routes | |||
) |
Returns all routes that match a given "to" label.
to | The "to" label. | |
routes | A Vector of Route objects that gets filled with all Routes that match the given "to" label. |
const std::string& InstantIO::Namespace::addNamespace | ( | std::auto_ptr< Namespace > | ns | ) | [inline] |
Adds a subnamespace to this Namespace.
ns | The child Namespace. |
const std::string& InstantIO::Namespace::addNamespace | ( | std::auto_ptr< Node > | ns | ) |
Adds a subnamespace to this Namespace.
ns | The child Namespace. |
const std::string& InstantIO::Namespace::addNamespace | ( | const std::string & | label, | |
std::auto_ptr< Namespace > | ns | |||
) |
Adds a Subnamespace to this Namespace.
label | The label of the child Namespace. | |
ns | The child Namespace. |
const std::string& InstantIO::Namespace::addNamespace | ( | const std::string & | label, | |
std::auto_ptr< Node > | ns | |||
) |
Adds a Subnamespace to this Namespace.
label | The label of the child Namespace. | |
ns | The child Namespace. |
std::auto_ptr<Namespace> InstantIO::Namespace::removeNamespace | ( | const std::string & | label | ) |
Removes a Subnamespace from this Namespace.
label | The label of the child Namespace. |
InvalidNamespaceException | when a namespace of this label does not exist in the Namespace. |
Namespace* InstantIO::Namespace::getNamespace | ( | const std::string & | label | ) | const |
Returns a subnamespace that matches a given label.
label | The label of the subnamespace. |
InvalidNamespaceException | when a subnamespace with the given label does not exist. |
NamespaceMap& InstantIO::Namespace::getNamespaces | ( | ) | [inline] |
Returns all subnamespaces contained in this Namespace.
const NamespaceMap& InstantIO::Namespace::getNamespaces | ( | ) | const [inline] |
Returns all subnamespaces contained in this Namespace.
virtual void InstantIO::Namespace::initialize | ( | ) | [protected, virtual] |
Gets called when the Namespace is enabled.
Override this method when you need to do your own initializations when the Namespace is enabled. The default implementation does nothing.
Reimplemented in InstantIO::Node.
virtual void InstantIO::Namespace::shutdown | ( | ) | [protected, virtual] |
Gets called when the Namespace is disabled.
Override this method when you need to do your own deinitializations when the Namespace is disabled. The default implementation does nothing.
Reimplemented in InstantIO::Node.
LabeledOutSlotVector::iterator InstantIO::Namespace::findOutSlot | ( | const std::string & | label, | |
BasicOutSlot * | outSlot | |||
) | [protected] |
void InstantIO::Namespace::getRoutedOutSlots | ( | const std::string & | label, | |
LabeledOutSlotVector & | outSlotVector | |||
) | [protected] |
void InstantIO::Namespace::getExportedOutSlots | ( | const std::string & | label, | |
LabeledOutSlotVector & | outSlotVector | |||
) | [protected] |
Returns all OutSlots that match a given external label.
label | The external label. | |
outSlotVector | A Vector of LabeledOutSlot objects that contains the OutSlots that match the given external label. |
LabeledInSlotVector::iterator InstantIO::Namespace::findInSlot | ( | const std::string & | label, | |
BasicInSlot * | inSlot | |||
) | [protected] |
void InstantIO::Namespace::getRoutedInSlots | ( | const std::string & | label, | |
LabeledInSlotVector & | inSlotVector | |||
) | [protected] |
void InstantIO::Namespace::getExportedInSlots | ( | const std::string & | label, | |
LabeledInSlotVector & | inSlotVector | |||
) | [protected] |
Returns all InSlots that match a given external label.
label | The external label. | |
inSlotVector | A Vector of LabeledInSlot objects that contains the InSlots that match the given external label. |
ExternalRouteVector::iterator InstantIO::Namespace::findExternalRoute | ( | const std::string & | internal, | |
const std::string & | external | |||
) | [protected] |
Tries to find an external route in the vector of external routes contained in this Namespace.
internal | The internal label of the route. | |
external | The external label of the route. |
void InstantIO::Namespace::removeExternalRoute | ( | const ExternalRouteVector::const_iterator & | it | ) | [protected] |
Removes an external route from the Namespace.
All slots that are exported to the parent namespace by this route are removed from the parent namespace.
it | Iterator pointing to the route in the vector of external routes. |
RouteVector::iterator InstantIO::Namespace::findRoute | ( | const std::string & | from, | |
const std::string & | to | |||
) | [protected] |
Tries to find a route in the vector of routes contained in this Namespace.
from | The "from" label of the route. | |
to | The "to" label of the route. |
void InstantIO::Namespace::removeRoute | ( | const RouteVector::const_iterator & | it | ) | [protected] |
Removes a route from the Namespace.
All OutSlots and InSlots that are connected by this route are disconnected.
it | Iterator pointing to the route in the route vector. |
std::string InstantIO::Namespace::createUniqueLabel | ( | const std::string & | label | ) | const [protected] |
Creates a unique name for a child Namespace.
label | The label of the child Namespace. |
Medusa::Mutex* InstantIO::Namespace::upMutex_ [protected] |
Up-Locks the Namespace object.
Medusa::Mutex* InstantIO::Namespace::downMutex_ [protected] |
Down-Locks the Namespace object.
bool InstantIO::Namespace::enabled_ [protected] |
The "enabled" flag - true when the Namespace is enabled.