00001 00002 /************************************************************************/ 00003 /* This file is part of openMask(c) INRIA, CNRS, Universite de Rennes 1 */ 00004 /* 1993-2002, thereinafter the Software */ 00005 /* */ 00006 /* The Software has been developped within the Siames Project. */ 00007 /* INRIA, the University of Rennes 1 and CNRS jointly hold intellectual */ 00008 /* property rights */ 00009 /* */ 00010 /* The Software has been registered with the Agence pour la Protection */ 00011 /* des Programmes (APP) under registration number */ 00012 /* IDDN.FR.001.510008.00.S.P.2001.000.41200 */ 00013 /* */ 00014 /* This file may be distributed under the terms of the Q Public License */ 00015 /* version 1.0 as defined by Trolltech AS of Norway and appearing in */ 00016 /* the file LICENSE.QPL included in the packaging of this file. */ 00017 /* */ 00018 /* Licensees holding valid specific licenses issued by INRIA, CNRS or */ 00019 /* Universite Rennes 1 for the software may use this file in */ 00020 /* acordance with that specific license */ 00021 /************************************************************************/ 00022 00023 #include "OMKSessionPrm.h" 00024 #include "OMKAccessLevelList.inl" 00025 #include "OMKInteractorExtension.h" 00026 #include "OMKInteractorOutput.h" 00027 #include "OMKExtensibleSimulatedObject.h" 00028 #include "OMKIAttribute.h" 00029 #include "OMKIAttribute.h" 00030 00031 using namespace OMK ; 00032 using namespace OMK::Iii ; 00033 using namespace OMK::Type ; 00034 00035 //----------------------------------------------------------------- 00036 SessionPrm* SessionPrm::create( InteractorExtension* owner, const Name& interactiveObject ) 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 } 00043 00044 //----------------------------------------------------------------- 00045 SessionPrm::SessionPrm( InteractorExtension* owner, const Name& interactiveObject ) 00046 : _interactiveObject( interactiveObject ), 00047 _owner( owner ) 00048 { 00049 OMASSERTM( _owner, "The listener must be valid" ); 00050 } 00051 00052 //----------------------------------------------------------------- 00053 SessionPrm::~SessionPrm() 00054 { 00055 } 00056 00057 //----------------------------------------------------------------- 00058 // connectors.getId : the connector id 00059 // connectors.getSecondId : the category 00060 void SessionPrm::init( const InteractorOutputsMap& interactorOutputsMap, const AccessibleParametersListPrm& connectors ) 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 } 00076 00077 //----------------------------------------------------------------- 00078 void SessionPrm::addControlledConnector( const ControlTakenOfParameterPrm& prm ) 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 } 00095 00096 //----------------------------------------------------------------- 00097 void SessionPrm::removeControlledConnector( const Name& id ) 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 } 00114 00115 //----------------------------------------------------------------- 00116 std::list< Name > SessionPrm::getActiveOutputs() const 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 } 00125 00126 //----------------------------------------------------------------- 00127 bool SessionPrm::isActiveOutput( const Name& id ) const 00128 { 00129 std::map< Name, Link >::const_iterator link = _links.find( id ) ; 00130 return link != _links.end() && link->second._state == EIsUnderControl ; 00131 } 00132 00133 //----------------------------------------------------------------- 00134 SessionPrm::OutputStates SessionPrm::outputState( const Name& id ) const 00135 { 00136 std::map< Name, Link >::const_iterator link = _links.find( id ) ; 00137 return link != _links.end() ? link->second._state : EUnknow ; 00138 } 00139 00140 //----------------------------------------------------------------- 00141 Name SessionPrm::getOutputId( const Name& connectorId ) const 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 } 00154 00155 //----------------------------------------------------------------- 00156 void SessionPrm::selfGetAccessibleParameters() 00157 { 00158 _owner->getInteractor()->sendValuedEvent( _interactiveObject, EventId::GET_ACCESSIBLE_PARAMETERS, OMK::Type::GetAccessibleParametersType( OMK::Type::GetAccessibleParametersPrm( _owner->getGroup(), _owner->getAccessLevel() ) ) ) ; 00159 _ids.clear() ; 00160 } 00161 //----------------------------------------------------------------- 00162 /*void SessionPrm::selfGetCurrentValues() 00163 { 00164 AccessCurrentValuePrm connectorsToGet( _owner->getAccessLevel() ) ; 00165 if( _ids.empty() ) 00166 { 00167 for ( std::map< Name, SessionPrm::Link >::const_iterator link = _links.begin() ; link != _links.end() ; ++link ) 00168 { // Try to connect each id sent by the interactor 00169 // Is the id in the connector list 00170 connectorsToGet.addItem( TwoIdsPrm( link->second._connector, link->first ) ) ; 00171 } 00172 } 00173 else 00174 { 00175 for ( std::vector< Name >::const_iterator id = _ids.begin() ; id != _ids.end() ; ++id ) 00176 { 00177 std::map< Name, SessionPrm::Link >::const_iterator link = _links.find( *id ) ; 00178 if( link != _links.end() ) 00179 { 00180 connectorsToGet.addItem( TwoIdsPrm( link->second._connector, link->first ) ) ; 00181 } 00182 else 00183 { 00184 OMTRACEID( OMK_DEBUG_III, ":-( The id \"" << (*id) << "\" is not available" ) ; 00185 } 00186 } 00187 } 00188 if( !connectorsToGet.getItems().empty() ) 00189 { 00190 _owner->getInteractor()->sendValuedEvent( _interactiveObject, EventId::GET_CURRENT_VALUE, AccessCurrentValueType( connectorsToGet ) ) ; 00191 } 00192 00193 _ids.clear() ; 00194 }*/ 00195 //----------------------------------------------------------------- 00196 void SessionPrm::selfControlTakeOverAndGetCurrentValues() 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 } 00238 //----------------------------------------------------------------- 00239 void SessionPrm::selfControlRelease() 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 } 00271 //----------------------------------------------------------------- 00272 void SessionPrm::selfControlFreeze() 00273 { 00274 OMERROR( "Control freeze not implemented for interactive object \"" << _interactiveObject << "\"" << std::endl ) ; 00275 _ids.clear() ; 00276 } 00277 //----------------------------------------------------------------- 00278 void SessionPrm::selfControlUnfreeze() 00279 { 00280 OMERROR( "control unfreeze not implemented for interactive object \"" << _interactiveObject << "\"" << std::endl ) ; 00281 _ids.clear() ; 00282 }
Documentation generated on Mon Jun 9 11:45:57 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |