API
4.0
For C++ developers
|
A Socket formalizes the dependency between a Component and another object (typically another Component) without owning that object. More...
Public Member Functions | |
virtual | ~AbstractSocket () |
virtual AbstractSocket * | clone () const =0 |
Create a dynamically-allocated copy. More... | |
const std::string & | getName () const |
SimTK::Stage | getConnectAtStage () const |
Get the system Stage when the connection should be made. More... | |
bool | isListSocket () const |
Can this Socket have more than one connectee? More... | |
unsigned | getNumConnectees () const |
The number of slots to fill in order to satisfy this socket. More... | |
virtual bool | isConnected () const =0 |
Derived classes must satisfy this Interface. More... | |
virtual std::string | getConnecteeTypeName () const =0 |
Get the type of object this socket connects to. More... | |
virtual const Object & | getConnecteeAsObject () const |
Generic access to the connectee. More... | |
virtual void | connect (const Object &connectee)=0 |
Connect this Socket to the provided connectee object. More... | |
virtual void | findAndConnect (const ComponentPath &connectee) |
Find the connectee using a search with a partial path. More... | |
void | findAndConnect (const std::string &connectee) |
Same as findAndConnect(const ComponentPath&), but using a string argument. More... | |
virtual void | finalizeConnection (const Component &root) |
Connect this Socket according to its connectee path property given a root Component to search its subcomponents for the connect_to Component. More... | |
virtual void | disconnect ()=0 |
Clear references to connectees. More... | |
void | setConnecteePath (const std::string &name) |
Set connectee path. More... | |
void | setConnecteePath (const std::string &name, unsigned ix) |
Set connectee path of a connectee among a list of connectees. More... | |
const std::string & | getConnecteePath () const |
Get connectee path. More... | |
const std::string & | getConnecteePath (unsigned ix) const |
Get connectee path of a connectee among a list of connectees. More... | |
void | appendConnecteePath (const std::string &name) |
void | clearConnecteePath () |
Clear all connectee paths in the connectee path property. More... | |
const Component & | getOwner () const |
Get owner component of this socket. More... | |
Protected Member Functions | |
AbstractSocket (const std::string &name, const PropertyIndex &connecteePathIndex, const SimTK::Stage &connectAtStage, Component &owner) | |
Create a Socket with specified name and stage at which it should be connected. More... | |
void | setOwner (Component &o) |
Set an internal pointer to the Component that contains this Socket. More... | |
bool | hasOwner () const |
This will be false immediately after copy construction or assignment. More... | |
void | checkConnecteePathProperty () |
Check if entries of the connectee path property's value is valid (if it contains spaces, etc.); if so, print out a warning. More... | |
const Property< std::string > & | getConnecteePathProp () const |
Const access to the connectee path property from the Component in which this Socket resides. More... | |
Property< std::string > & | updConnecteePathProp () |
Writable access to the connectee path property from the Component in which this Socket resides. More... | |
A Socket formalizes the dependency between a Component and another object (typically another Component) without owning that object.
While Components can be composites (of multiple components) they often depend on unrelated objects/components that are defined and owned elsewhere. The object that satisfies the requirements of the Socket we term the "connectee". When a Socket is satisfied by a connectee we have a successful "connection" or is said to be connected.
The purpose of a Socket is to specify: 1) the connectee type that the Component is dependent on, 2) by when (what stage) the socket must be connected in order for the component to function, 3) the name of a connectee that can be found at run-time to satisfy the socket, and 4) whether or not it is connected. A Socket maintains a reference to the instance (connectee) until it is disconnected.
For example, a Joint has two Sockets for the parent and child Bodies that it joins. The type for the socket is a PhysicalFrame and any attempt to connect to a non-Body (or frame rigidly attached to a Body) will throw an exception. The connectAt Stage is Topology. That is, the Joint's connection to a Body must be performed at the Topology system stage, and any attempt to change the connection status will invalidate that Stage and above.
Other Components like a Marker or a Probe that do not change the system topology or add new states could potentially be connected at later stages like Model or Instance.
Programmatically, the connectee can be specified as an object reference or via a connectee path:
Use finalizeConnection() to synchronize the object reference and connectee name. It is preferable to use connect() instead of setConnecteePath(). If both are set, then the object reference overrides the connectee path.
The connectee path appears in XML files and is how a connection is maintained across serialization (writing to an XML file) and deserialization (reading from an XML file).
|
inlinevirtual |
|
inlineprotected |
Create a Socket with specified name and stage at which it should be connected.
|
inline |
|
inlineprotected |
Check if entries of the connectee path property's value is valid (if it contains spaces, etc.); if so, print out a warning.
References OpenSim::ComponentPath::getComponentName(), and OpenSim::Path::isLegalPathElement().
|
inline |
Clear all connectee paths in the connectee path property.
|
pure virtual |
Create a dynamically-allocated copy.
You must manage the memory for the returned pointer. This function exists to facilitate the use of SimTK::ClonePtr<AbstractSocket>.
Implemented in OpenSim::Input< T >, OpenSim::AbstractInput, and OpenSim::Socket< T >.
|
pure virtual |
Connect this Socket to the provided connectee object.
If this is a list socket, the connectee is appended to the list of connectees; otherwise, the provided connectee replaces the single connectee.
Implemented in OpenSim::AbstractInput, and OpenSim::Socket< T >.
|
pure virtual |
Clear references to connectees.
The connectee path property is not affected. Calling finalizeConnection() will use the connectee path property to satisfy the socket.
Implemented in OpenSim::Input< T >, and OpenSim::Socket< T >.
|
inlinevirtual |
Connect this Socket according to its connectee path property given a root Component to search its subcomponents for the connect_to Component.
Reimplemented in OpenSim::Input< T >, and OpenSim::Socket< T >.
|
inlinevirtual |
Find the connectee using a search with a partial path.
Use this if you do not want to specify an exact path (maybe you don't quite know where the connectee is located).
Reimplemented in OpenSim::Socket< T >.
|
inline |
Same as findAndConnect(const ComponentPath&), but using a string argument.
|
inline |
Get the system Stage when the connection should be made.
|
inlinevirtual |
Generic access to the connectee.
Not all sockets support this method (e.g., the connectee for an Input is not an Object).
Reimplemented in OpenSim::Socket< T >.
Referenced by OpenSim::Component::getConnectee().
|
inline |
Get connectee path.
This function can only be used if this socket is not a list socket.
Referenced by OpenSim::Input< T >::setAlias().
|
inline |
Get connectee path of a connectee among a list of connectees.
References SimTK::isIndexInRange(), and SimTK_INDEXCHECK_ALWAYS.
|
protected |
|
pure virtual |
Get the type of object this socket connects to.
Implemented in OpenSim::Input< T >, and OpenSim::Socket< T >.
Referenced by OpenSim::ConnecteeNotSpecified::ConnecteeNotSpecified().
|
inline |
Referenced by OpenSim::Socket< T >::connect(), OpenSim::ConnecteeNotSpecified::ConnecteeNotSpecified(), OpenSim::Input< T >::getAlias(), OpenSim::Input< T >::getChannel(), OpenSim::Socket< T >::getConnectee(), OpenSim::Input< T >::getLabel(), OpenSim::Input< T >::getValue(), and OpenSim::Input< T >::setAlias().
|
inline |
The number of slots to fill in order to satisfy this socket.
This is 1 for a non-list socket. This is the number of elements in the connectee path property; to sync this with the number of connectee objects, call finalizeConnection().
Referenced by OpenSim::Input< T >::getAlias(), OpenSim::Input< T >::getChannel(), OpenSim::Input< T >::getLabel(), OpenSim::Input< T >::getValue(), OpenSim::Input< T >::isConnected(), and OpenSim::Input< T >::setAlias().
|
inline |
Get owner component of this socket.
Referenced by OpenSim::Socket< T >::findAndConnect(), and OpenSim::Socket< T >::getConnectee().
|
inlineprotected |
This will be false immediately after copy construction or assignment.
|
pure virtual |
Derived classes must satisfy this Interface.
Is the Socket connected to its connectee(s)? For a list socket, this is only true if this socket is connected to all its connectees.
Implemented in OpenSim::Input< T >, and OpenSim::Socket< T >.
Referenced by OpenSim::Component::getConnectee(), and OpenSim::Component::getInputValue().
|
inline |
Can this Socket have more than one connectee?
Referenced by OpenSim::Input< T >::getAlias(), OpenSim::Input< T >::getChannel(), OpenSim::Input< T >::getLabel(), and OpenSim::Input< T >::getValue().
|
inline |
Set connectee path.
This function can only be used if this socket is not a list socket. If a connectee reference is set (with connect()) the connectee path is ignored; call disconnect() if you want the socket to be connected using the connectee path.
It is preferable to use connect() instead of this function.
|
inline |
Set connectee path of a connectee among a list of connectees.
This function is used if this socket is a list socket. If a connectee reference is set (with connect()) the connectee path is ignored; call disconnect() if you want the socket to be connected using the connectee name.
It is preferable to use connect() instead of this function.
References SimTK::isIndexInRange(), and SimTK_INDEXCHECK_ALWAYS.
|
inlineprotected |
Set an internal pointer to the Component that contains this Socket.
This should only be called by Component. This exists so that after the containing Component is copied, the 'owner' is the new Component. This Socket needs to be able to modify the associated connectee path property in the Component. Thus, we require a writable reference.
|
protected |
Writable access to the connectee path property from the Component in which this Socket resides.
Calling this will mark the Component as not "up to date with properties" (Object::isObjectUpToDateWithProperties()).
Referenced by OpenSim::Input< T >::setAlias().