00001 /* 00002 * This file is part of openMask © INRIA, CNRS, Universite de Rennes 1 1993-2002, thereinafter the Software 00003 * 00004 * The Software has been developped within the Siames Project. 00005 * INRIA, the University of Rennes 1 and CNRS jointly hold intellectual property rights 00006 * 00007 * The Software has been registered with the Agence pour la Protection des 00008 * Programmes (APP) under registration number IDDN.FR.001.510008.00.S.P.2001.000.41200 00009 * 00010 * This file may be distributed under the terms of the Q Public License 00011 * version 1.0 as defined by Trolltech AS of Norway and appearing in the file 00012 * LICENSE.QPL included in the packaging of this file. 00013 * 00014 * Licensees holding valid specific licenses issued by INRIA, CNRS or Université de Rennes 1 00015 * for the software may use this file in accordance with that specific license 00016 * 00017 */ 00018 #ifndef OMKSimulatedObjectHEADER 00019 #define OMKSimulatedObjectHEADER 00020 #include "OMKTracer.h" 00021 #include "OMKSimpleTypeT.h" 00022 //include ancestor classes 00023 #include "OMKFlowable.h" 00024 00025 //include member class 00026 #include "OMKNameToPointerMap.h" 00027 00028 //include definition of OMK::Type::PolatorNT::defaultPrecisionLevel 00029 #include "OMKPolatorNT.h" 00030 #include "OBTPrototypeFactory.h" 00031 00032 #include <iostream> 00033 #include <list> 00034 00035 00036 namespace OMK 00037 { 00038 template <typename Type> class Output ; 00039 template <typename Type> class InputAlias ; 00040 template <typename Type> class OutputAlias ; 00041 template <typename Type> class Input ; 00042 template <typename Type> class AbstractInput ; 00043 template <typename Type> class SensitiveInput ; 00044 template <typename Type> class SensitiveNotifyingInput ; 00045 template <typename Type> class ControlParameter ; 00046 template <typename Type> class SensitiveInputAlias ; 00047 template <typename Type> class SensitiveNotifyingInputAlias ; 00048 template <typename Type> class ValuedEvent ; 00049 class ObjectDescriptor ; 00050 class ConfigurationParameterDescriptor ; 00051 class Controller ; 00052 class InputNT ; 00053 class OutputNT ; 00054 class Event ; 00055 class ObjectHandle ; 00056 class Name ; 00057 class EventListener ; 00058 class EventIdentifier ; 00072 class OMK_API SimulatedObject : public Flowable 00073 { 00074 00075 public: 00078 00079 SimulatedObject ( Controller & ctrl, const ObjectDescriptor & objectDescription ); 00080 00082 virtual ~SimulatedObject() ; 00084 00088 00094 template< typename Type > 00095 std::list< const ObjectDescriptor * > * listSonsOfType ( ) ; 00096 00097 00102 template< typename Type > 00103 std::list< const ObjectDescriptor * > * listBrothersOfType ( ) ; 00104 00105 00109 template< typename Type > 00110 std::list< const ObjectDescriptor * > * listDescendantsOfType ( ) ; 00111 00112 00117 virtual bool isAncestor ( const Name & name ); 00118 00122 virtual SimulatedObject * getFather () const ; 00123 00126 virtual const ObjectDescriptor & getFathersDescriptor () const ; 00127 00128 00130 00131 00135 00137 virtual const Name & getName () const; 00138 00140 virtual Controller & getController () const; 00141 00143 ObjectHandle * getObjectHandle () const ; 00144 00146 void setObjectHandle ( ObjectHandle * objectHandle) ; 00147 00150 const ObjectDescriptor & getObjectDescriptor () const ; 00151 00152 00154 virtual const NameToPointerMap < InputNT > & getInputTable () const ; 00155 00156 00158 virtual const NameToPointerMap < OutputNT > & getOutputTable () const ; 00159 00160 00162 virtual const NameToPointerMap < OutputNT > & getControlParameterTable () const ; 00163 00164 00166 virtual const std::list < EventListener * > & getEventListeners () const ; 00167 00168 00173 virtual InputNT * getPointerToInputNamed ( const Name & inputName ) const; 00174 00175 00180 virtual OutputNT * getPointerToOutputNamed ( const Name & outputName) const; 00181 00182 00187 virtual OutputNT * getPointerToControlParameterNamed ( const Name & parameterName ) const ; 00188 00189 00191 virtual const ConfigurationParameterDescriptor * getConfigurationParameters () const ; 00193 00194 00195 00198 00199 00200 00201 // added by Jean-Marie Houssay 2005-03-29 00207 virtual void postConstruction() ; 00208 00212 virtual void init() ; 00213 00215 virtual void emigrate() ; 00216 virtual void immigrate(Event * event) ; 00221 virtual void compute (); 00222 00223 00227 virtual void finish (); 00228 00229 00233 virtual void extract (std::istream & in = std::cin) ; 00234 00235 00239 virtual void insertInStream (std::ostream & out = std::cout) const; 00240 00241 00243 virtual void unpack (IncomingSynchronisationMessage &) ; 00244 00246 virtual void unpackAllValues (IncomingSynchronisationMessage &) ; 00247 00249 virtual void pack (OutgoingSynchronisationMessage &) const ; 00250 00252 virtual void packAllValues (OutgoingSynchronisationMessage &) const ; 00253 00254 00255 00259 virtual void prepareEventProcessing ( std::list <Event *> & ) ; 00260 00261 00265 virtual bool processEvent (Event *) ; 00266 00267 00270 virtual void eventsProcessed ( std::list <Event *> & ) ; 00271 00272 00278 virtual bool processEventsASAP () const ; 00279 00280 00287 virtual void addEventListener( EventListener & ) ; 00288 00293 void registerEventListenerForEvent( EventListener & eventListener, 00294 const EventIdentifier & eventId ) ; 00295 00302 void unregisterEventListener( EventListener & eventListener ) ; 00303 00305 00306 00307 00314 void fireSignal(const EventIdentifier & sig); 00315 00316 00321 template <typename UserType> 00322 void fireValuedSignal( const EventIdentifier & sig, const UserType & value ); 00323 00324 00330 virtual bool registerForSignalBy ( const EventIdentifier & sig , 00331 const Name & producer ); 00332 00333 00340 virtual bool registerForSignalBy ( const EventIdentifier & sig , 00341 const Name & producer, 00342 const EventIdentifier & eventId ); 00343 00344 00350 virtual bool registerForSignalBy ( const EventIdentifier & sig , 00351 SimulatedObject * producer ); 00352 00353 00359 virtual bool registerForSignalBy ( const EventIdentifier & sig , 00360 SimulatedObject & producer ); 00361 00362 00369 virtual bool registerForSignalBy ( const EventIdentifier & sig , 00370 SimulatedObject * producer, 00371 const EventIdentifier & eventId ); 00372 00373 00374 00381 virtual bool registerForSignalBy ( const EventIdentifier & sig , 00382 SimulatedObject & producer, 00383 const EventIdentifier & eventId ); 00384 00385 00386 00391 virtual bool registerForSignal ( const EventIdentifier & sig ); 00392 00398 virtual bool registerForSignal ( const EventIdentifier & sig , 00399 const EventIdentifier & eventId ); 00400 00406 virtual bool cancelRegistrationForSignalBy ( const EventIdentifier & sig , const Name & producer ); 00407 00408 00414 virtual bool cancelRegistrationForSignalBy ( const EventIdentifier & sig , SimulatedObject * producer ); 00415 00416 00417 00423 virtual bool cancelRegistrationForSignalBy ( const EventIdentifier & sig , SimulatedObject & producer ); 00424 00425 00426 00431 virtual bool cancelRegistrationForSignal ( const EventIdentifier & sig ); 00433 00443 template <typename Type> Input<Type> & addInput( const Name & inputName, 00444 bool makeConnectable = false, 00445 int precisionLevel = OMK::Type::PolatorNT::defaultPrecisionLevel ) ; 00446 00447 00454 template <typename Type> SensitiveInput<Type> & addSensitiveInput (const Name & inputName, 00455 bool makeConnectable = false, 00456 int precisionLevel = OMK::Type::PolatorNT::defaultPrecisionLevel ) ; 00457 00458 00465 template <typename Type> SensitiveNotifyingInput<Type> & addSensitiveNotifyingInput( const Name & inputName, 00466 bool makeConnectable = false, 00467 int precisionLevel = OMK::Type::PolatorNT::defaultPrecisionLevel ) ; 00468 00469 00474 void deleteInput( const Name & inputName) ; 00475 00476 00481 template <typename Type> Output<Type> & addOutput( const Name & outputName, 00482 OMK::Type::PolatorNT * polator = 0 ) ; 00483 00484 00489 template <typename Type> ControlParameter<Type> & addControlParameter( const Name & controlParameterName, 00490 OMK::Type::PolatorNT * polator = 0 ) ; 00491 00492 00501 template <typename Type> 00502 InputAlias<Type> & addInputAlias (const Name & aliasName, 00503 const Name & aliasedObjectName, 00504 const Name & aliasedInputName, 00505 int precisionLevel = OMK::Type::PolatorNT::defaultPrecisionLevel ) ; 00506 00507 00516 template <typename Type> 00517 SensitiveInputAlias<Type> & addSensitiveInputAlias( const Name & aliasName, 00518 const Name & aliasedObjectName, 00519 const Name & aliasedInputName, 00520 int precisionLevel = OMK::Type::PolatorNT::defaultPrecisionLevel ) ; 00521 00522 00531 template <typename Type> SensitiveNotifyingInputAlias<Type> & 00532 addSensitiveNotifyingInputAlias( const Name & aliasName, 00533 const Name & aliasedObjectName, 00534 const Name & aliasedInputName, 00535 int precisionLevel = OMK::Type::PolatorNT::defaultPrecisionLevel ) ; 00536 00537 00544 template <typename Type> OutputAlias<Type> & addOutputAlias( const Name & aliasName, 00545 const Name & aliasedObjectName, 00546 const Name & aliasedOutputName, 00547 OMK::Type::PolatorNT * interp = 0 ) ; 00548 00550 00551 00555 00559 virtual const Date & getSimulatedDate () const ; 00560 00565 float getPeriod( ) const ; 00566 00568 00572 00577 void sendEvent (const Name & receiver , const EventIdentifier & eventId) ; 00578 00579 00584 void sendEvent ( SimulatedObject * receiver , const EventIdentifier & eventId) ; 00585 00586 00591 void sendEvent ( SimulatedObject & receiver , const EventIdentifier & eventId) ; 00592 00593 00599 template <typename UserType> 00600 void sendValuedEvent (const Name & receiver , const EventIdentifier & eventId, const UserType & userInfo) ; 00601 00602 00608 template <typename UserType> 00609 void sendValuedEvent ( SimulatedObject * receiver , const EventIdentifier & eventId , const UserType & userInfo) ; 00610 00611 00617 template <typename UserType> 00618 void sendValuedEvent ( SimulatedObject & receiver , const EventIdentifier & eventId , const UserType & userInfo) ; 00619 00620 00625 void sendEvent ( const Event & event ) ; 00626 00627 00632 void sendEvent ( Event * event ) ; 00633 00635 00636 protected: 00637 00639 Controller & _controller; 00640 00642 const ObjectDescriptor & _objectDescriptor ; 00643 00644 friend class InputNT ; 00646 NameToPointerMap<InputNT> _inputTable ; 00647 00649 NameToPointerMap<OutputNT> _outputTable ; 00650 00652 NameToPointerMap<OutputNT> _controlParameterTable ; 00653 00655 std::list <EventListener *> _listOfEventListeners ; 00656 00658 ObjectHandle * _objectHandle ; 00659 00660 }; // SimulatedObject 00661 00662 00663 00664 00674 #define DECLARE_OBJECT_FACTORY( ObjectClass ) \ 00675 public: \ 00676 \ 00677 friend class OMK::SimulatedObjectCreatorT< ObjectClass > ; \ 00678 \ 00679 static OMK::Name OMK_CLASS_ID ; \ 00680 \ 00681 static const bool REGISTERED_IN_OBJECT_FACTORY ; \ 00682 protected: \ 00683 \ 00685 ObjectClass( OMK::Controller& ctrl, const OMK::ObjectDescriptor& objectDescriptor ) ; \ 00686 public: \ 00687 virtual ~ObjectClass() 00688 00696 #define REGISTER_OBJECT_FACTORY( ObjectClass, Id )\ 00697 /* Factory */ \ 00698 OMK::Name ObjectClass::OMK_CLASS_ID( Id ) ; \ 00699 const bool ObjectClass::REGISTERED_IN_OBJECT_FACTORY( OMK::SimulatedObjectFactory::getInstance().registerCreator< OMK::SimulatedObjectCreatorT< ObjectClass > >( Id ) ) 00700 00701 } // namespace OMK 00702 00703 //------------------------------------------------------------------------- 00704 #include "OMKObjectDescriptor.h" 00705 00706 namespace OMK 00707 { 00708 //----------------------------------------------------------------------------- 00715 class SimulatedObjectCreator 00716 { 00717 public: 00718 virtual ~SimulatedObjectCreator(){} 00719 virtual SimulatedObject* operator()( Controller & ctrl, const ObjectDescriptor & objectDescription ) const 00720 { 00721 OMERROR( "Creator is not registered for \"" << objectDescription.getName() << "\" class \"" << objectDescription.getClass() << "\"" ) ; 00722 throw Exception( "Creator is not registered" ) ; 00723 return 0 ; 00724 } 00725 } ; 00726 00727 //----------------------------------------------------------------------------- 00736 template <class T> 00737 class SimulatedObjectCreatorT : public SimulatedObjectCreator 00738 { 00739 public: 00740 00741 typedef T object_to_create ; 00742 virtual ~SimulatedObjectCreatorT(){} 00743 SimulatedObject* operator()( Controller & ctrl, const ObjectDescriptor & objectDescription ) const 00744 { 00745 SimulatedObject* object = new T( ctrl, objectDescription ) ; 00746 if( object ) object->postConstruction() ; 00747 return object ; 00748 } 00749 } ; 00750 00751 //----------------------------------------------------------------------------- 00773 typedef OBT::Singleton< OBT::PrototypeFactory< OMK::Name, SimulatedObjectCreator > > SimulatedObjectFactory ; 00774 00775 } // namespace OMK 00776 00777 template class OMK_API OBT::PrototypeFactory< OMK::Name, OMK::SimulatedObjectCreator > ; 00778 template class OMK_API OBT::Singleton< OBT::PrototypeFactory< OMK::Name, OMK::SimulatedObjectCreator > > ; 00779 00780 #endif
Documentation generated on Mon Jun 9 11:45:57 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |