OMKObjectDescriptor.h

Go to the documentation of this file.
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 OMKObjectDescriptorHEADER
00019 #define OMKObjectDescriptorHEADER
00020 
00021 #include "OMKFlowable.h"
00022 #include "OMKName.h"
00023 #include "OMKTracer.h"
00024 #ifdef _OMK_MUTEX_
00025 #  include "OMKCondition.h"
00026 #  include "OMKMutexLock.h"
00027 #endif
00028 #ifndef _MSC_VER
00029    #include "pthread.h"
00030 #endif
00031 #include <list>
00032 
00033 namespace OMK
00034 {
00035   class Controller ;
00036   class ConfigurationParameterDescriptor ;
00037   class MultipleConfigurationParameter ;
00038   class SimulatedObject ;
00039   class ObjectHandle ;
00040 
00069 class OMK_API ObjectDescriptor : public Flowable
00070 {
00071 public:   
00075    explicit ObjectDescriptor() ;
00076 
00077    enum Distribution
00078    {
00079      DEFAULT_OBJECT = 0,
00080      LOCAL_OBJECT,
00081      DUPLICATED_OBJECT
00082    } ;
00083 
00085    ObjectDescriptor( const ObjectDescriptor & ) ;
00086 
00090    ObjectDescriptor( const Name & objectName,
00091                      const Name & classId,
00092                      MultipleConfigurationParameter * schedulingParameters,
00093                      ConfigurationParameterDescriptor * configurationParameters,
00094                      ConfigurationParameterDescriptor * extensionParameters = 0 ) ;
00095 
00099    ObjectDescriptor( const Name & objectName,
00100                      const Name & classId,
00101                      const Frequency & frequency,
00102                      ConfigurationParameterDescriptor * configurationParameters,
00103                      ConfigurationParameterDescriptor * extensionParameters = 0,
00104                      Distribution distribution = DEFAULT_OBJECT ) ;
00105 
00109    ObjectDescriptor( const Name & objectName,
00110                      const Name & classId,
00111                      const Name & processId,
00112                      const Frequency & frequency,
00113                      ConfigurationParameterDescriptor * configurationParameters,
00114                      ConfigurationParameterDescriptor * extensionParameters = 0,
00115                      Distribution distribution = DEFAULT_OBJECT ) ;
00116 
00120    virtual ~ObjectDescriptor(); 
00121 
00124    virtual const Name & getName() const
00125    {
00126      return _objectName ;
00127    }
00128 
00131    virtual const Name & getClass() const
00132    {
00133      return _classId ;
00134    }
00135 
00138    virtual const Name & getProcess() const
00139    {
00140      return _processId ;
00141    }
00142 
00145    virtual const Frequency & getFrequency() const
00146    {
00147      return _frequency ;
00148    }
00149 
00152    virtual const Frequency & getOriginalFrequency() const
00153    {
00154      return _originalFrequency ;
00155    }
00156 
00159    virtual Distribution getDistribution() const
00160    {
00161      return _distribution ;
00162    }
00163 
00166    virtual const ConfigurationParameterDescriptor * getConfigurationParameters() const
00167    {
00168      return _configurationParameters ;
00169    }
00170 
00173    virtual ConfigurationParameterDescriptor * getConfigurationParameters( bool create = false ) ;
00174 
00177    virtual const ConfigurationParameterDescriptor * getExtensionsParameters() const
00178    {
00179      return _extensionsParameters ;
00180    }
00181 
00184    virtual ConfigurationParameterDescriptor * getExtensionsParameters( bool create = false ) ;
00185 
00188    virtual const MultipleConfigurationParameter * getOriginalSchedulingParameters() const
00189    {
00190      return _originalSchedulingParameters ;
00191    }
00192 
00195    virtual const MultipleConfigurationParameter * getSchedulingParameters() const
00196    {
00197      return _schedulingParameters ;
00198    }
00199 
00201    virtual void setProcess( const Name & newProcessName ) ; 
00202 
00203 
00205    virtual void setFrequency( const Frequency & newFrequency ) ; 
00206 
00208    virtual void setDistribution( Distribution newDistribution ) ; 
00209 
00212    virtual void deleteCachedData() ;
00213 
00215    virtual void unpack( IncomingSynchronisationMessage & in ) ;
00216    
00218    virtual void pack( OutgoingSynchronisationMessage & out ) const ;
00219    
00221    virtual void extract( std::istream & in ) ;
00222 
00224    virtual void insertInStream( std::ostream & out ) const ;
00225 
00228 
00229 
00232    virtual const ObjectDescriptor * getFathersObjectDescriptor() const
00233    {
00234      return _fathersDescription ;
00235    }
00236 
00239    virtual ObjectDescriptor * getFathersObjectDescriptor()
00240    {
00241      return _fathersDescription ;
00242    }
00243 
00245    typedef std::list< ObjectDescriptor * > SonsContainerType ;
00246 
00247 
00249    virtual SonsContainerType & getSons()
00250    {
00251      return _sonsContainer ;
00252    }
00253 
00257    virtual const std::list< ObjectDescriptor * > * getSons() const
00258    {
00259      return & _sonsContainer ;
00260    }
00261 
00266    virtual std::list< const ObjectDescriptor * > * getDescendants() const ;
00267 
00268 
00274    virtual std::list< const ObjectDescriptor * > * getDescendants( std::list< const ObjectDescriptor * > * resultList ) const ;
00275 
00276 
00281    virtual std::list< ObjectDescriptor * > * getDescendants() ;
00282 
00283 
00289    virtual std::list< ObjectDescriptor * > * getDescendants( std::list< ObjectDescriptor * > * resultList ) ;
00290 
00291 
00298    virtual void addSon( ObjectDescriptor * newSon ) ;
00299 
00300 
00304    virtual void removeSon( ObjectDescriptor * oldSon ) ;
00305 
00306 
00311    template< typename type >
00312    std::list<const ObjectDescriptor *> * listSonsOfType() const ;
00313 
00314 
00319    template< typename type > 
00320    std::list<const ObjectDescriptor *> * listSonsOfType( std::list< const ObjectDescriptor * > * resultList ) const ;
00321 
00322 
00326    template< typename type > 
00327    std::list<const ObjectDescriptor *> * listDescendantsOfType() const ;
00328    
00329 
00335    template< typename type > 
00336    std::list<const ObjectDescriptor *> * listDescendantsOfType( std::list< const ObjectDescriptor * > * resultList ) const ;
00337 
00338 
00342    virtual const ObjectDescriptor * findDescendantNamed( const Name & name ) const ;
00343 
00344 
00348    virtual ObjectDescriptor * findDescendantNamed( const Name & name ) ;
00349 
00350 
00353    static void interpretConfigurationParameterAsListOfSons( SonsContainerType & listOfSons,
00354                                                             MultipleConfigurationParameter * sonsDescription ) ;
00355 
00358    static ObjectDescriptor * 
00359    interpretConfigurationParameterAsObjectDescription( std::string objectName,
00360                                                         MultipleConfigurationParameter * ) ;
00362 protected:
00366   friend class Controller ;
00367 
00368 
00371   friend class ObjectHandle ;
00372 
00374    friend class SimulatedObject ;
00375 
00386    virtual SimulatedObject * createDescribedObject() const ;   
00387 
00388 
00389    virtual void setFathersDescription( ObjectDescriptor * newFather ) ;
00390 
00394    mutable SimulatedObject * _pointerToSimulatedObject ;
00395 
00396 
00399    mutable bool _destroySimulatedObject ;
00400 
00401 
00405    void interpretSchedulingParameters( MultipleConfigurationParameter * schedulingParameters ) ;
00406 
00407 public:
00410    virtual MultipleConfigurationParameter * getSchedulingParameters()
00411    {
00412      return _schedulingParameters ;
00413    }
00414 
00415 protected:
00417    Name _objectName ;         
00418    
00420    Name _classId ; 
00421    
00423    ConfigurationParameterDescriptor * _configurationParameters ;
00424 
00426    ConfigurationParameterDescriptor * _extensionsParameters ;
00427 
00429    MultipleConfigurationParameter * _originalSchedulingParameters ;
00430 
00432    MultipleConfigurationParameter * _schedulingParameters ;
00433 
00435    ObjectDescriptor * _fathersDescription ;
00436 
00437 
00441    SonsContainerType _sonsContainer ;
00442 
00444    virtual void printToStream( std::ostream & out, int currentOffset ) const ;
00445 
00446 
00447 #ifdef _OMK_MUTEX_
00448 
00449    mutable OMKMutexLock _dataLock ;
00450 
00452    mutable OMKCondition _createdCondition ;
00453 #endif
00454 
00456    mutable bool _creatingObject ;
00457 
00458 #ifndef _MSC_VER
00459 
00460    mutable pthread_t _creatingThread ;
00461 #endif
00462 
00463 private:
00465    Name _processId ;   
00466    
00468    Frequency _frequency ;     
00469 
00471    Distribution _distribution ;     
00472 
00474    Frequency _originalFrequency ;     
00475 
00476 };
00477 
00478 
00479 //------------------------------------------------------------------------------
00480 //------------------------------------------------------------------------------
00481 
00482 
00483 template< typename Type >
00484 std::list< const ObjectDescriptor * > *
00485 ObjectDescriptor::listSonsOfType() const
00486 {
00487   return listSonsOfType< Type >( new std::list< const ObjectDescriptor * >() );
00488 }
00489 //------------------------------------------------------------------------------
00490 template< typename Type > 
00491 std::list< const ObjectDescriptor * > *
00492 ObjectDescriptor::listSonsOfType(
00493   std::list< const ObjectDescriptor * > * resultList ) const
00494 {
00495   for( SonsContainerType::const_iterator i = _sonsContainer.begin() ;
00496        i != _sonsContainer.end() ;
00497        ++i )
00498   {
00499     if( dynamic_cast< Type * >( ( *i )->createDescribedObject() ) != 0 )
00500     {
00501       resultList->push_back( *i ) ;
00502     }
00503   }
00504   return resultList ;
00505 }
00506 //------------------------------------------------------------------------------
00507 template< typename Type > 
00508 std::list< const ObjectDescriptor * > *
00509 ObjectDescriptor::listDescendantsOfType() const
00510 {
00511   return listDescendantsOfType< Type >(
00512     new std::list< const ObjectDescriptor * >() );
00513 }
00514 //------------------------------------------------------------------------------
00515 template< typename Type > 
00516 std::list< const ObjectDescriptor * > *
00517 ObjectDescriptor::listDescendantsOfType(
00518   std::list< const ObjectDescriptor * > * resultList ) const
00519 {
00520   OMASSERTM( createDescribedObject(), "Unable to create descriptor" ) ;
00521 
00522   // test the current node
00523   if( dynamic_cast< Type * >( createDescribedObject() ) != 0 )
00524   {
00525     resultList->push_back( this ) ;
00526   }
00527   //recurse through the sons
00528   for( SonsContainerType::const_iterator i = _sonsContainer.begin() ;
00529        i != _sonsContainer.end() ;
00530        ++i )
00531   {
00532     OMASSERTM( ( *i )->getFathersObjectDescriptor() == this,
00533                "The father is not the good one" ) ;
00534     ( *i )->template listDescendantsOfType< Type >( resultList ) ;
00535   }
00536   return resultList ;
00537 }
00538 //------------------------------------------------------------------------------
00539 
00540 }// namespace OMK
00541 
00542 //typedef OMK::ObjectDescriptor ObjectDescriptor ;
00543 
00544 #endif // OMKObjectDescriptorHEADER

logo OpenMask

Documentation generated on Mon Jun 9 11:45:57 2008

Generated with doxygen by Dimitri van Heesch ,   1997-2007