OMK::Iii::SessionPrm Class Reference
[Interactor]

Define a session of interaction between an interactor and an interactive object. More...

#include <OMKSessionPrm.h>

Collaboration diagram for OMK::Iii::SessionPrm:

Collaboration graph
[legend]
List of all members.

Active outputs.

enum  OutputStates {
  EUnknow,
  EIsNotControlled,
  EWaitingForAnswer,
  EIsUnderControl
}
 States of the output. More...
virtual void addControlledConnector (const Type::ControlTakenOfParameterPrm &prm)
 Updating of the output state.
virtual void removeControlledConnector (const Name &id)
 Updating of the output state.
std::list< NamegetActiveOutputs () const
 To get the active outputs list.
OutputStates outputState (const Name &id) const
 The state for an output.
bool isActiveOutput (const Name &id) const
 The state for an output.

Flow processing.

std::vector< Name_ids
 Outputs ids for the current operation.
virtual void selfGetAccessibleParameters ()
 Formats and sends the event "parameters ?".
virtual void selfControlTakeOverAndGetCurrentValues ()
 Formats and sends the event "control take over".
virtual void selfControlRelease ()
 Formats and sends the event "control release".
virtual void selfControlFreeze ()
 Formats and sends the event "control freeze".
virtual void selfControlUnfreeze ()
 Formats and sends the event "control unfreeze".

Public Member Functions

virtual ~SessionPrm ()
 Destructor.
virtual bool isInitialized () const
 Indicates if the session is initialized.
virtual void init (const InteractorOutputsMap &interactorOutputsMap, const Type::AccessibleParametersListPrm &connectors)
 Initialization method.
const NamegetInteractiveObject () const
 To get the interactive object involved into the session.
Name getOutputId (const Name &connectorId) const
 To get the output id from the connector id.
Message construction.
SessionPrmc (SessionPrm &(*f)(SessionPrm &))
 Message construction for friend functions.
template<class TheFunctor>
SessionPrmc (const TheFunctor &theFunctor)
 Message construction for function.
virtual SessionPrmc (const Name &interactiveObjectId)
 Flow operator to store an id to handle.

Static Public Member Functions

static SessionPrmcreate (InteractorExtension *owner, const Name &interactiveObject)
 Creator method.

Protected Member Functions

 SessionPrm (InteractorExtension *owner, const Name &interactiveObject)
 Constructor.

Protected Attributes

std::map< Name, Link_links
 This map stores the valid links between the connectors and the interactor outputs.
Name _interactiveObject
 The id of the interactive object associated with the session.
InteractorExtension_owner
 The interactor extension, owner of the session.

Friends

Friend function to allows flow processing.
Each one call the associated virtual method of SessionPrm.

So the behavior of each can be modified by creating a new king of session.

SessionPrmgetAccessibleParameters (SessionPrm &s)
 Formats and sends the event "parameters ?" according to SessionPrm.
SessionPrmcontrolTakeOverAndGetCurrentValues (SessionPrm &s)
 Formats and sends the event "control take over" according to SessionPrm.
SessionPrmcontrolRelease (SessionPrm &s)
 Formats and sends the event "control release" according to SessionPrm.
SessionPrmcontrolFreeze (SessionPrm &s)
 Formats and sends the event "control freeze" according to SessionPrm.
SessionPrmcontrolUnfreeze (SessionPrm &s)
 Formats and sends the event "control unfreeze" according to SessionPrm.

Classes

class  Functor
 Message construction function for friend functions. More...
struct  Link
 Internal structure to store the connector id and the associated interactor output. More...

Detailed Description

Define a session of interaction between an interactor and an interactive object.

Date:
2006/06/15
Author:
Benoît Chanclou
This class implements the session behavior. It is used by the interactor to establish the dialog with the interactive object. See startSessionWith, closeSessionWith and getSessionWith.
The mechanism of this class is based on flow syntax. During a session the interactor have to send well formatted events to the interactive object. Each event has its own format, most of the time, it includes ids. The interactor can indicate to the session object with which outputs it wants to control the interactive object, to do this it use the flow operator << followed by the output id, to send the event, it finishes the flow with a friend function of the session class. This one calls the homonymous virtual method of the session object which formats and sends the event.
// Starts session with the interactive object identify by "_interactiveObject"
startSessionWith( _interactiveObject ) ;
// asks for parameters values
(*getSessionWith( _interactiveObject )).c( OMK::Iii::getCurrentValues ) ;
// tries to take control with a set of its outputs 
(*getSessionWith( _interactiveObject )).c( _posOutputId ).c( _rotOutputId ).c( _otherOutputId ).c( OMK::Iii::controlTakeOver ) ;
// stops interacte with "_otherOutputId"
(*getSessionWith( _interactiveObject )).c( _otherOutputId ).c( OMK::Iii::controlRelease ) ;
// stops all interaction
(*getSessionWith( _interactiveObject )).c( OMK::Iii::controlRelease ) ;
// Closes definitively the session
closeSessionWith( _interactiveObject ) ;
This class can be derived to change its behavior, in such case, you should overwrite the virtual methods.
See Example of session.

Definition at line 76 of file OMKSessionPrm.h.


Member Enumeration Documentation

enum OMK::Iii::SessionPrm::OutputStates

States of the output.

Enumerator:
EUnknow  The attribute cannot be controlled.
EIsNotControlled  The attribute is not under control.
EWaitingForAnswer  The session tried to take control of the attribute and is waiting for confirmation.
EIsUnderControl  The attribute is controlled by the object.

Definition at line 142 of file OMKSessionPrm.h.

00142                     {
00143     EUnknow,           
00144     EIsNotControlled,  
00145     EWaitingForAnswer, 
00146 
00147     EIsUnderControl    
00148   } ;


Constructor & Destructor Documentation

SessionPrm::SessionPrm ( InteractorExtension owner,
const Name interactiveObject 
) [protected]

Constructor.

It is protected, to create a session use create static method.

Definition at line 45 of file OMKSessionPrm.cpp.

References _owner, and OMASSERTM.

Referenced by create().

00046 : _interactiveObject( interactiveObject ),
00047   _owner( owner )
00048 {
00049   OMASSERTM( _owner, "The listener must be valid" ); 
00050 }

SessionPrm::~SessionPrm (  )  [virtual]

Destructor.

Definition at line 53 of file OMKSessionPrm.cpp.

00054 {
00055 }


Member Function Documentation

SessionPrm * SessionPrm::create ( InteractorExtension owner,
const Name interactiveObject 
) [static]

Creator method.

Parameters:
[in] listener The associated listener of the interactor
[in] interactiveObject The id of the interactive object which the interactor wants to interacte
Returns:
The new session object
Use this method to create a new session of this kind.

Definition at line 36 of file OMKSessionPrm.cpp.

References OMK::ExtensionT< SimulatedObjectType >::getOwner(), OMASSERTM, and SessionPrm().

Referenced by OMK::Iii::InteractorExtension::createSession().

00037 {
00038   OMASSERTM( owner, "Cannot be null" ) ;
00039   return owner->getOwner()->getController().getPointerToSimulatedObjectNamed( interactiveObject ) ?
00040       new SessionPrm( owner, interactiveObject ) :
00041       0 ; // Not ok because it is not a simulated object
00042 }

virtual bool OMK::Iii::SessionPrm::isInitialized (  )  const [inline, virtual]

Indicates if the session is initialized.

Returns:
true if initialized, else false.
An initialized session is a session for which the interactive object answers with a set of parameters that the interactor can control.

Definition at line 98 of file OMKSessionPrm.h.

00098 { return !_links.empty() ; }

void SessionPrm::init ( const InteractorOutputsMap interactorOutputsMap,
const Type::AccessibleParametersListPrm connectors 
) [virtual]

Initialization method.

This method is call by the processAvailableConnectors of EventInteractiveObjectListener implementation of IEventInteractiveObjectListener interface.

Definition at line 60 of file OMKSessionPrm.cpp.

References _interactiveObject, _links, OMK_DEBUG_III, and OMTRACEID.

Referenced by OMK::Iii::InteractorExtension::processAccessibleParameters().

00061 {
00062   for ( AccessibleParametersListPrm::const_iterator connector = connectors.begin() ; 
00063         connector != connectors.end() ; 
00064         ++connector )
00065   { // Try to connect each id sent by the interactor 
00066     OMTRACEID( OMK_DEBUG_III, ":-| The interactive object \"" << _interactiveObject << "\" can be controlled with connector \"" << connector->_id << "\" of category \"" << connector->_category << "\" the parameter is " << (connector->_accessible ? "accessible" : "unaccessible") ) ;
00067     // Is the id in the connector list
00068     InteractorOutputsMap::const_iterator interactorOutput = interactorOutputsMap.find( InteractorOutputsIndex( connector->_category, connector->_type ) ) ;
00069     if( interactorOutput != interactorOutputsMap.end() )
00070     { // Stores a new link
00071       OMTRACEID( OMK_DEBUG_III, ":-| The session with interactive object \"" << _interactiveObject << "\" can have control from the interactor output \"" << interactorOutput->second->id() << "\"" ) ;
00072       _links.insert( std::pair< Name, SessionPrm::Link >( interactorOutput->second->id(), Link( connector->_id, interactorOutput->second ) ) ) ;
00073     }
00074   }
00075 }

const Name& OMK::Iii::SessionPrm::getInteractiveObject (  )  const [inline]

To get the interactive object involved into the session.

Returns:
The id of the interactive object involved into the session

Definition at line 107 of file OMKSessionPrm.h.

Referenced by OMK::Iii::InteractorExtension::startSessionWith().

00107 { return _interactiveObject ; }

SessionPrm& OMK::Iii::SessionPrm::c ( SessionPrm &(*)(SessionPrm &)  f  )  [inline]

Message construction for friend functions.

Definition at line 111 of file OMKSessionPrm.h.

00112   {
00113     return (*f)( *this ); 
00114   }

template<class TheFunctor>
SessionPrm& OMK::Iii::SessionPrm::c ( const TheFunctor &  theFunctor  )  [inline]

Message construction for function.

Definition at line 127 of file OMKSessionPrm.h.

00128   {
00129     return theFunctor.func( *this ); 
00130   }

virtual SessionPrm& OMK::Iii::SessionPrm::c ( const Name interactiveObjectId  )  [inline, virtual]

Flow operator to store an id to handle.

Definition at line 132 of file OMKSessionPrm.h.

00133   { 
00134     _ids.push_back( interactiveObjectId ) ;
00135     return *this; 
00136   }

void SessionPrm::addControlledConnector ( const Type::ControlTakenOfParameterPrm prm  )  [virtual]

Updating of the output state.

Parameters:
[in] id Upates the state of the output connected to the connector which is named id.
Sets to EIsUnderControl the state of the output connected to the connector which is named id.

Definition at line 78 of file OMKSessionPrm.cpp.

References _links, EIsUnderControl, OMK_DEBUG_III, and OMTRACEID.

00079 {
00080   bool ok = false ;
00081   for ( std::map< Name, SessionPrm::Link >::iterator link = _links.begin() ; link != _links.end() ; ++link )
00082   { // Try to find the connector
00083     if( link->second._connector == prm.first )
00084     {
00085       link->second._state = EIsUnderControl ;
00086       ok = true ;
00087       break ;
00088     }
00089   }
00090   if( !ok )
00091   {
00092     OMTRACEID( OMK_DEBUG_III, ":-( The connector with id \"" << prm.first << "\" is not available, cannot add it !" ) ;
00093   }
00094 }

void SessionPrm::removeControlledConnector ( const Name id  )  [virtual]

Updating of the output state.

Parameters:
[in] id Upates the state of the output connected to the connector which is named id.
Sets to EIsNotControlled the state of the output connected to the connector which is named id.

Definition at line 97 of file OMKSessionPrm.cpp.

References _links, EIsNotControlled, OMK_DEBUG_III, and OMTRACEID.

00098 {
00099   bool ok = false ;
00100   for ( std::map< Name, SessionPrm::Link >::iterator link = _links.begin() ; link != _links.end() ; ++link )
00101   { // Try to find the connector
00102     if( link->second._connector == id )
00103     {
00104       link->second._state = EIsNotControlled ;
00105       ok = true ;
00106       break ;
00107     }
00108   }
00109   if( !ok )
00110   {
00111     OMTRACEID( OMK_DEBUG_III, ":-( The connector with id \"" << id << "\" is not under control, cannot remove it !" ) ;
00112   }
00113 }

std::list< Name > SessionPrm::getActiveOutputs (  )  const

To get the active outputs list.

Returns:
The list of outputs id which actually control a connector of the interactive object.
Only the outputs with the state EIsUnderControl are returned.

Definition at line 116 of file OMKSessionPrm.cpp.

References _links, and EIsUnderControl.

00117 {
00118   std::list< Name > activeOutputs ;
00119   for ( std::map< Name, Link >::const_iterator link = _links.begin() ; link !=  _links.end() ; ++link )
00120   {
00121     if( link->second._state == EIsUnderControl ) activeOutputs.push_back( link->first ) ;
00122   }
00123   return activeOutputs ;
00124 }

SessionPrm::OutputStates SessionPrm::outputState ( const Name id  )  const

The state for an output.

Returns:
the output state according to the control state.

Definition at line 134 of file OMKSessionPrm.cpp.

References _links, and EUnknow.

00135 {
00136   std::map< Name, Link >::const_iterator link = _links.find( id ) ;
00137   return link != _links.end() ? link->second._state : EUnknow ;
00138 }

bool SessionPrm::isActiveOutput ( const Name id  )  const

The state for an output.

Returns:
true if the output controls a connector of the associated object. This means that the output has the state EIsUnderControl.

Definition at line 127 of file OMKSessionPrm.cpp.

References _links, and EIsUnderControl.

00128 {
00129   std::map< Name, Link >::const_iterator link = _links.find( id ) ;
00130   return link != _links.end() && link->second._state == EIsUnderControl ;
00131 }

Name SessionPrm::getOutputId ( const Name connectorId  )  const

To get the output id from the connector id.

Parameters:
[in] connectorId The connector id of the interactive object.
Returns:
The id of the corresponding parameter of the interactor.

Definition at line 141 of file OMKSessionPrm.cpp.

References _links.

Referenced by OMK::Iii::InteractorOutputT< PrmType, ModelType >::processSetValue().

00142 {
00143   Name id ;
00144   for ( std::map< Name, SessionPrm::Link >::const_iterator link = _links.begin() ; link != _links.end() ; ++link )
00145   { // Try to find the id in the link part
00146     if( link->second._connector == connectorId )
00147     {
00148       id = link->first ;
00149       break ;
00150     }
00151   }
00152   return id ;
00153 }

void SessionPrm::selfGetAccessibleParameters (  )  [protected, virtual]

Formats and sends the event "parameters ?".

See protocol and SessionPrm

Definition at line 156 of file OMKSessionPrm.cpp.

References _ids, _interactiveObject, _owner, OMK::EventId::GET_ACCESSIBLE_PARAMETERS, OMK::Iii::InteractorExtension::getAccessLevel(), OMK::Iii::InteractorExtension::getGroup(), OMK::Iii::InteractorExtension::getInteractor(), and OMK::SimulatedObject::sendValuedEvent().

Referenced by OMK::Iii::getAccessibleParameters().

00157 { 
00158   _owner->getInteractor()->sendValuedEvent( _interactiveObject, EventId::GET_ACCESSIBLE_PARAMETERS, OMK::Type::GetAccessibleParametersType( OMK::Type::GetAccessibleParametersPrm( _owner->getGroup(), _owner->getAccessLevel() ) ) ) ;
00159   _ids.clear() ;
00160 }

void SessionPrm::selfControlTakeOverAndGetCurrentValues (  )  [protected, virtual]

Formats and sends the event "control take over".

See protocol and SessionPrm

Definition at line 196 of file OMKSessionPrm.cpp.

References _ids, _interactiveObject, _links, _owner, OMK::EventId::CONTROL_TAKE_OVER_AND_GET_CURRENT_VALUES, EWaitingForAnswer, OMK::Iii::InteractorExtension::getAccessLevel(), OMK::Iii::InteractorExtension::getGroup(), OMK::Iii::InteractorExtension::getInteractor(), OMK_DEBUG_III, OMTRACEID, and OMK::SimulatedObject::sendValuedEvent().

Referenced by OMK::Iii::controlTakeOverAndGetCurrentValues().

00197 { 
00198   TakeOverAndGetCurrentValuesPrm connectorsToControl( _owner->getGroup(), _owner->getAccessLevel() ) ;   
00199   if( _ids.empty() )
00200   {
00201     for ( std::map< Name, SessionPrm::Link >::iterator link = _links.begin() ; link != _links.end() ; ++link )
00202     { // Try to connect each id sent by the interactor 
00203       // Is the id in the connector list
00204       connectorsToControl.addItem( ControlTakeOverPrm( link->second._connector,
00205                                                        link->first
00206                                                        // FIXME: owner access level is not the apropriate value!
00207                                                       ) ) ;
00208       // Set the flag to waiting
00209       link->second._state = EWaitingForAnswer ;
00210     }
00211   }
00212   else
00213   {
00214     for ( std::vector< Name >::const_iterator id = _ids.begin() ; id !=  _ids.end() ; ++id )
00215     {
00216       std::map< Name, SessionPrm::Link >::iterator link = _links.find( *id ) ;
00217       if( link != _links.end() )
00218       {
00219         connectorsToControl.addItem( ControlTakeOverPrm( link->second._connector,
00220                                                          link->first
00221                                                          // FIXME: owner access level is not the apropriate value!
00222                                                           ) ) ;
00223         // Set the flag to waiting
00224         link->second._state = EWaitingForAnswer ;
00225       }
00226       else
00227       {
00228         OMTRACEID( OMK_DEBUG_III, ":-( No link with interactor output \"" << (*id) << "\" available" ) ;
00229       }
00230     }
00231   }
00232   if( !connectorsToControl._items.empty() )
00233   {
00234     _owner->getInteractor()->sendValuedEvent( _interactiveObject, EventId::CONTROL_TAKE_OVER_AND_GET_CURRENT_VALUES, TakeOverAndGetCurrentValuesType( connectorsToControl ) ) ;
00235   }
00236   _ids.clear() ;
00237 }

void SessionPrm::selfControlRelease (  )  [protected, virtual]

Formats and sends the event "control release".

See protocol and SessionPrm

Definition at line 239 of file OMKSessionPrm.cpp.

References _ids, _interactiveObject, _links, _owner, OMK::EventId::CONTROL_RELEASE, EIsNotControlled, OMK::Iii::InteractorExtension::getInteractor(), OMK_DEBUG_III, OMTRACEID, OMK::SimulatedObject::sendEvent(), and OMK::SimulatedObject::sendValuedEvent().

Referenced by OMK::Iii::controlRelease().

00240 { 
00241   ControlReleasePrm connectorsList ;
00242   for ( std::vector< Name >::const_iterator id = _ids.begin() ; id !=  _ids.end() ; ++id )
00243   {
00244     std::map< Name, SessionPrm::Link >::iterator link = _links.find( *id ) ;
00245     if( link != _links.end() )
00246     {
00247       connectorsList.push_back( link->second._connector ) ;
00248       link->second._state = EIsNotControlled ;
00249     }
00250     else
00251     {
00252       OMTRACEID( OMK_DEBUG_III, ":-( No link with interactor output \"" << (*id) << "\" available" ) ;
00253     }
00254   }
00255   if( !connectorsList.empty() )
00256   { // The list is filled => send it
00257     _owner->getInteractor()->sendValuedEvent( _interactiveObject, EventId::CONTROL_RELEASE, ControlReleaseType( connectorsList ) ) ;
00258   }
00259   else if( _ids.empty() )
00260   { // all is selected or none is selected => release all <=> no parameter to send
00261     for ( std::map< Name, SessionPrm::Link >::iterator link = _links.begin() ; link != _links.end() ; ++link )
00262     { 
00263       // Set the flag to not controlled
00264       link->second._state = EIsNotControlled ;
00265     }
00266     _owner->getInteractor()->sendEvent( _interactiveObject, EventId::CONTROL_RELEASE ) ;
00267   }
00268   // else a list of unusable ids => error, no event to send
00269   _ids.clear() ;
00270 }

void SessionPrm::selfControlFreeze (  )  [protected, virtual]

Formats and sends the event "control freeze".

See protocol and SessionPrm

Definition at line 272 of file OMKSessionPrm.cpp.

References _ids, _interactiveObject, and OMERROR.

Referenced by OMK::Iii::controlFreeze().

00273 { 
00274   OMERROR( "Control freeze not implemented for interactive object \"" << _interactiveObject << "\"" << std::endl ) ;
00275   _ids.clear() ;
00276 }

void SessionPrm::selfControlUnfreeze (  )  [protected, virtual]

Formats and sends the event "control unfreeze".

See protocol and SessionPrm

Definition at line 278 of file OMKSessionPrm.cpp.

References _ids, _interactiveObject, and OMERROR.

Referenced by OMK::Iii::controlUnfreeze().

00279 { 
00280   OMERROR( "control unfreeze not implemented  for interactive object \"" << _interactiveObject << "\"" << std::endl ) ;
00281   _ids.clear() ;
00282 }


Friends And Related Function Documentation

SessionPrm& getAccessibleParameters ( SessionPrm s  )  [friend]

Formats and sends the event "parameters ?" according to SessionPrm.

See selfGetParameters and Example of session.
Example of use

Definition at line 272 of file OMKSessionPrm.h.

00273 {
00274   s.selfGetAccessibleParameters() ;
00275   return s ;
00276 }

SessionPrm& controlTakeOverAndGetCurrentValues ( SessionPrm s  )  [friend]

Formats and sends the event "control take over" according to SessionPrm.

See selfControlTakeOver. and Example of session.
Example of use

Definition at line 278 of file OMKSessionPrm.h.

00279 {
00280   s.selfControlTakeOverAndGetCurrentValues() ;
00281   return s ;
00282 }

SessionPrm& controlRelease ( SessionPrm s  )  [friend]

Formats and sends the event "control release" according to SessionPrm.

See selfControlRelease. and Example of session.
Example of use

Definition at line 284 of file OMKSessionPrm.h.

00285 {
00286   s.selfControlRelease() ;
00287   return s ;
00288 }

SessionPrm& controlFreeze ( SessionPrm s  )  [friend]

Formats and sends the event "control freeze" according to SessionPrm.

See selfControlFreeze. and Example of session.
Example of use

Definition at line 290 of file OMKSessionPrm.h.

00291 {
00292   s.selfControlFreeze() ;
00293   return s ;
00294 }

SessionPrm& controlUnfreeze ( SessionPrm s  )  [friend]

Formats and sends the event "control unfreeze" according to SessionPrm.

See selfControlUnfreeze. and Example of session.
Example of use

Definition at line 296 of file OMKSessionPrm.h.

00297 {
00298   s.selfControlUnfreeze() ;
00299   return s ;
00300 }


Member Data Documentation

std::map< Name, Link > OMK::Iii::SessionPrm::_links [protected]

This map stores the valid links between the connectors and the interactor outputs.

It is indexed by the connector ids.

Definition at line 198 of file OMKSessionPrm.h.

Referenced by addControlledConnector(), getActiveOutputs(), getOutputId(), init(), isActiveOutput(), outputState(), removeControlledConnector(), selfControlRelease(), and selfControlTakeOverAndGetCurrentValues().

Name OMK::Iii::SessionPrm::_interactiveObject [protected]

The id of the interactive object associated with the session.

Definition at line 200 of file OMKSessionPrm.h.

Referenced by init(), selfControlFreeze(), selfControlRelease(), selfControlTakeOverAndGetCurrentValues(), selfControlUnfreeze(), and selfGetAccessibleParameters().

InteractorExtension* OMK::Iii::SessionPrm::_owner [protected]

The interactor extension, owner of the session.

Definition at line 202 of file OMKSessionPrm.h.

Referenced by selfControlRelease(), selfControlTakeOverAndGetCurrentValues(), selfGetAccessibleParameters(), and SessionPrm().

std::vector< Name > OMK::Iii::SessionPrm::_ids [protected]

Outputs ids for the current operation.

This is in this vector that the output ids are stored until they were used to send a event. Went the event is sent this vector is cleared.

Definition at line 208 of file OMKSessionPrm.h.

Referenced by selfControlFreeze(), selfControlRelease(), selfControlTakeOverAndGetCurrentValues(), selfControlUnfreeze(), and selfGetAccessibleParameters().


logo OpenMask

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

Generated with doxygen by Dimitri van Heesch ,   1997-2007