OMK::Iii::SimpleConnectorT< Type > Class Template Reference
[Interactive object]

The implementation class for simple connectors. More...

#include <OMKConnectors.h>

Inheritance diagram for OMK::Iii::SimpleConnectorT< Type >:

Inheritance graph
[legend]
Collaboration diagram for OMK::Iii::SimpleConnectorT< Type >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

Redefined interface.
virtual bool isConnected (const Name &interactor) const
 Returns if the interactor is connected or not.
virtual bool preConnect (const Name &interactor, const OMK::Type::AccessGroupLevel &freeze, OMK::Type::AccessLevel tool)
 Connection method.
virtual bool connect (const Name &interactor, const Name &outputName)
virtual void disconnect (const Name &interactor)
 Disconnection method.
virtual void disconnect ()
 Disconnection method.
virtual void updateParameter () const
 Update method.
virtual void sendValue (const Name &receiver) const
 Sending the current value.

Protected Attributes

InputNT_input
 The pointer on the input to get the value from the interactor.
IAttributeBaseT< Type > * _attribute
 The attribute interface.
IConvertorT< Type, Type > * _convertor
 The optionnal convertor from input to the attribute.

Private Member Functions

 DECLARE_TEMPLATE_CONNECTOR_FACTORY (SimpleConnectorT, Type)

Detailed Description

template<typename Type>
class OMK::Iii::SimpleConnectorT< Type >

The implementation class for simple connectors.

Date:
2006-10-12
Author:
Beno� Chanclou
This connector allows the connection of only one interactor at the same time. It is a part of the interaction protocol.

This connector is a template class, the parameter is:

To use it see Create connectors.

Definition at line 101 of file OMKConnectors.h.


Member Function Documentation

template<typename Type>
OMK::Iii::SimpleConnectorT< Type >::DECLARE_TEMPLATE_CONNECTOR_FACTORY ( SimpleConnectorT< Type >  ,
Type   
) [private]

template<typename T>
bool OMK::Iii::SimpleConnectorT< T >::isConnected ( const Name interactor  )  const [virtual]

Returns if the interactor is connected or not.

See IConnector::isConnected.

Implements OMK::Iii::IConnector.

Definition at line 67 of file OMKConnectors.inl.

References OMK::Iii::SimpleConnectorT< Type >::_input, OMK::InputNT::getConnectedOutput(), OMK::SimulatedObject::getName(), and OMK::KernelAttribute::getOwner().

Referenced by OMK::Iii::SimpleConnectorT< Type >::disconnect().

00068 {
00069   return _input 
00070       && _input->getConnectedOutput() 
00071       && _input->getConnectedOutput()->getOwner().getName() == interactor ;
00072 }

template<typename Type>
virtual bool OMK::Iii::SimpleConnectorT< Type >::preConnect ( const Name interactor,
const OMK::Type::AccessGroupLevel freeze,
OMK::Type::AccessLevel  tool 
) [virtual]

Connection method.

This method creates an input in its associated interactive object and connects it to the output of the interactor.
The name of the created input is the concatenation of the iterator name and its output.
See IConnector::connect.

Implements OMK::Iii::IConnector.

Reimplemented in OMK::Iii::AssociatedConnectorT< Type >.

template<typename T>
bool OMK::Iii::SimpleConnectorT< T >::connect ( const Name interactor,
const Name outputName 
) [virtual]

Implements OMK::Iii::IConnector.

Definition at line 95 of file OMKConnectors.inl.

References OMK::Iii::SimpleConnectorT< Type >::_attribute, OMK::Iii::IConnector::_id, OMK::Iii::SimpleConnectorT< Type >::_input, OMK::Iii::IConnector::_owner, OMK::Iii::IConnector::_toolsOnStandby, OMK::InputNT::connect(), OMK::IAttribute::createInput(), OMK::debugMsg(), OMK::Name::getString(), OMASSERT, OMK_DEBUG_III, and OMTRACEID.

00096 {
00097   bool ok = false ;
00098   Name inputName ;
00099   if( std::find( _toolsOnStandby.begin(), _toolsOnStandby.end(), interactor ) != _toolsOnStandby.end() )
00100   {
00101     // preconditions
00102     OMASSERT( !_input && "The connector must be disconnected" ) ;
00103     // creates the name's input
00104     inputName = interactor.getString() + outputName.getString() ;
00105     // creates the input in the interactive object
00106     _input = _attribute->createInput( inputName ) ;
00107     // connects it to the interactor output
00108     ok = _input && _input->connect( interactor, outputName ) ; 
00109   }
00110   if( ok )
00111   { // The interactor is no more waiting list
00112     _toolsOnStandby.clear() ;
00113   }
00114   else
00115   { // Unsuccessful connection => delete the input
00116     OMTRACEID( OMK_DEBUG_III, ":-( Error in SimpleConnectorT< \"" << _id 
00117         << "\" >:: connect for the " << OMK::debugMsg( _owner ) << std::endl
00118         << ">>> The interactor \"" << interactor << "\" cannot be connected !" ) ;
00119     _owner->deleteInput( inputName ) ;
00120     _input = 0 ;
00121   }
00122   return ok ;
00123 }

template<typename T>
void OMK::Iii::SimpleConnectorT< T >::disconnect ( const Name interactor  )  [virtual]

Disconnection method.

Disconnects the input and destroys it. An assertion is made with the interactor name.
See IConnector::disconnect( const Name& interactor ).

Implements OMK::Iii::IConnector.

Definition at line 126 of file OMKConnectors.inl.

References OMK::Iii::IConnector::_id, OMK::Iii::IConnector::_owner, OMK::debugMsg(), OMK::Name::getString(), OMK::Iii::SimpleConnectorT< Type >::isConnected(), OMK_DEBUG_III, and OMTRACEID.

00127 {
00128   if( isConnected( interactor ) )
00129   {
00130     SimpleConnectorT< T >::disconnect() ;
00131   }
00132   else
00133   {
00134     OMTRACEID( OMK_DEBUG_III, ":-( Error in SimpleConnectorT< \"" << _id.getString() 
00135         << "\" >:: disconnect for the " << OMK::debugMsg( _owner ) << std::endl
00136         << ">>> The interactor \"" << interactor.getString() << "\" is not one of those which are connected !" ) ;
00137   }
00138 }

template<typename T>
void OMK::Iii::SimpleConnectorT< T >::disconnect (  )  [virtual]

Disconnection method.

Disconnects the input and destroys it.
See IConnector::disconnect().

Implements OMK::Iii::IConnector.

Definition at line 141 of file OMKConnectors.inl.

References OMK::Iii::IConnector::_accessRule, OMK::Iii::SimpleConnectorT< Type >::_input, OMK::Iii::IConnector::_owner, OMK::Iii::IConnector::_toolsInUse, OMK::Iii::IConnector::_toolsOnStandby, OMK::SimulatedObject::deleteInput(), OMK::InputNT::disconnect(), OMK::KernelAttribute::getName(), OMK::Iii::IAccessRule::resetCurrentLevel(), and OMK::Iii::IConnector::SendControlEnded().

00142 {
00143   // Must send a event to inform the old interactor it was disconnected
00144   if( !_toolsInUse.empty() )
00145   {
00146     SendControlEnded( *_toolsInUse.begin() ) ;
00147   }
00148   if( _input )
00149   {
00150     _input->disconnect() ; 
00151     _owner->deleteInput( _input->getName() ) ;
00152     _input = 0 ;
00153   }
00154   _toolsOnStandby.clear() ; // discard the possible waiting tool
00155   _toolsInUse.clear() ;
00156   _accessRule->resetCurrentLevel() ; // unfreeze if necessary
00157 }

template<typename T>
void OMK::Iii::SimpleConnectorT< T >::updateParameter (  )  const [virtual]

Update method.

The method gets the value read from the associated input and gives it to the owner which updates its parameter.
See IConnector::updateParameter.

Implements OMK::Iii::IConnector.

Definition at line 160 of file OMKConnectors.inl.

References OMK::Iii::SimpleConnectorT< Type >::_attribute, OMK::Iii::SimpleConnectorT< Type >::_convertor, OMK::Iii::SimpleConnectorT< Type >::_input, OMK::IAccessorT< T >::get(), OMK::IAttributeBaseT< PrmType >::getValueFromInput(), and OMK::IAccessorT< T >::set().

00161 { // if it is connected, it updates the parameter
00162   if( _input ) 
00163   {
00164     // Update the parameter
00165     if( _convertor )
00166     { // Through the convertor
00167       T valueOut = _attribute->get() ;
00168       T valueIn ;
00169       _attribute->getValueFromInput( valueIn, _input ) ;
00170       _convertor->convert( valueOut, valueIn ) ;
00171       _attribute->set( valueOut ) ; 
00172     }
00173     else
00174     { // directly
00175       _attribute->getValueFromInput( _input ) ; 
00176     }
00177   }
00178 }

template<typename T>
void OMK::Iii::SimpleConnectorT< T >::sendValue ( const Name receiver  )  const [virtual]

Sending the current value.

Call by EventInteractorListener::processGetParameters to send the current value of the parameter. See the protocol

Implements OMK::Iii::IConnector.

Definition at line 181 of file OMKConnectors.inl.

References OMK::Iii::SimpleConnectorT< Type >::_attribute, OMK::Iii::IConnector::_id, OMK::EventId::CURRENT_VALUE, and OMK::IAttribute::sendIdAndValue().

00182 {
00183   _attribute->sendIdAndValue( receiver, EventId::CURRENT_VALUE, _id ) ;
00184 }


Member Data Documentation

template<typename Type>
InputNT* OMK::Iii::SimpleConnectorT< Type >::_input [protected]

The pointer on the input to get the value from the interactor.

Definition at line 141 of file OMKConnectors.h.

Referenced by OMK::Iii::SimpleConnectorT< Type >::connect(), OMK::Iii::SimpleConnectorT< Type >::disconnect(), OMK::Iii::SimpleConnectorT< Type >::isConnected(), and OMK::Iii::SimpleConnectorT< Type >::updateParameter().

template<typename Type>
IAttributeBaseT< Type >* OMK::Iii::SimpleConnectorT< Type >::_attribute [protected]

The attribute interface.

Definition at line 143 of file OMKConnectors.h.

Referenced by OMK::Iii::SimpleConnectorT< Type >::connect(), OMK::Iii::SimpleConnectorT< Type >::sendValue(), and OMK::Iii::SimpleConnectorT< Type >::updateParameter().

template<typename Type>
IConvertorT< Type, Type >* OMK::Iii::SimpleConnectorT< Type >::_convertor [protected]

The optionnal convertor from input to the attribute.

Definition at line 145 of file OMKConnectors.h.

Referenced by OMK::Iii::SimpleConnectorT< Type >::updateParameter().


logo OpenMask

Documentation generated on Mon Jun 9 11:46:04 2008

Generated with doxygen by Dimitri van Heesch ,   1997-2007