OMK::ObjectDescriptor Class Reference

object of this class are used to store the description of simulated object, with data meaningfull for object outside the kernel. More...

#include <OMKObjectDescriptor.h>

Inheritance diagram for OMK::ObjectDescriptor:

Inheritance graph
[legend]
Collaboration diagram for OMK::ObjectDescriptor:

Collaboration graph
[legend]
List of all members.

member functions using the object descriptor as a node of the simulation tree

typedef std::list< ObjectDescriptor * > SonsContainerType
 The type of the container memorizing the sons of the described object in the simulation tree.
virtual const ObjectDescriptorgetFathersObjectDescriptor () const
 get the object descriptor of the father
virtual ObjectDescriptorgetFathersObjectDescriptor ()
 get the object descriptor of the father
virtual SonsContainerTypegetSons ()
 get a container with all the sons of this object in the simulation tree
virtual const std::list< ObjectDescriptor * > * getSons () const
 get a container with all the sons of this object in the simulation tree the resulting list should be deleted
virtual std::list< const ObjectDescriptor * > * getDescendants () const
 get a container with all the descendants of this object in the simualtion tree the result should be deleted after usage if the object has no descendants, an empty list is returned
virtual std::list< const ObjectDescriptor * > * getDescendants (std::list< const ObjectDescriptor * > *resultList) const
 get a container with all the descendants of this object in the simualtion tree
virtual std::list< ObjectDescriptor * > * getDescendants ()
 get a container with all the descendants of this object in the simualtion tree the result should be deleted after usage if the object has no descendants, an empty list is returned
virtual std::list< ObjectDescriptor * > * getDescendants (std::list< ObjectDescriptor * > *resultList)
 get a container with all the descendants of this object in the simualtion tree
virtual void addSon (ObjectDescriptor *newSon)
 add a son in the simulation tree to the described object If called after initialisation of the controller, isn't taken into account by the controller
virtual void removeSon (ObjectDescriptor *oldSon)
 remove a son in the simulation tree If called after initialisation of the controller, isn't taken into account by the controller
template<typename type>
std::list< const ObjectDescriptor * > * listSonsOfType () const
 listSonsOfType.
template<typename type>
std::list< const ObjectDescriptor * > * listSonsOfType (std::list< const ObjectDescriptor * > *resultList) const
 list the sons of a certain Type.
template<typename type>
std::list< const ObjectDescriptor * > * listDescendantsOfType () const
 listDescendantsOfType.
template<typename type>
std::list< const ObjectDescriptor * > * listDescendantsOfType (std::list< const ObjectDescriptor * > *resultList) const
 listDescendantsOfType.
virtual const ObjectDescriptorfindDescendantNamed (const Name &name) const
 find a descendant of this node
virtual ObjectDescriptorfindDescendantNamed (const Name &name)
 find a descendant of this node
static void interpretConfigurationParameterAsListOfSons (SonsContainerType &listOfSons, MultipleConfigurationParameter *sonsDescription)
 helper function, to help interpret a object described as a configuration parameter
static ObjectDescriptorinterpretConfigurationParameterAsObjectDescription (std::string objectName, MultipleConfigurationParameter *)
 helper function, to create a object described as a configuration parameter

Public Types

enum  Distribution {
  DEFAULT_OBJECT = 0,
  LOCAL_OBJECT,
  DUPLICATED_OBJECT
}

Public Member Functions

 ObjectDescriptor ()
 default constructor needed for an object descriptor to be included in a valued event for distributed creation
 ObjectDescriptor (const ObjectDescriptor &)
 copy constructor
 ObjectDescriptor (const Name &objectName, const Name &classId, MultipleConfigurationParameter *schedulingParameters, ConfigurationParameterDescriptor *configurationParameters, ConfigurationParameterDescriptor *extensionParameters=0)
 Constructor responsability of the destruction of schedulingParameters and configurationParameters is transfered to the object.
 ObjectDescriptor (const Name &objectName, const Name &classId, const Frequency &frequency, ConfigurationParameterDescriptor *configurationParameters, ConfigurationParameterDescriptor *extensionParameters=0, Distribution distribution=DEFAULT_OBJECT)
 Constructor, used as a shortcut for constructing correct scheduling parameters responsability of the destruction of configurationParameters is transfered to the object.
 ObjectDescriptor (const Name &objectName, const Name &classId, const Name &processId, const Frequency &frequency, ConfigurationParameterDescriptor *configurationParameters, ConfigurationParameterDescriptor *extensionParameters=0, Distribution distribution=DEFAULT_OBJECT)
 Constructor, used as a shortcut for constructing correct scheduling parameters responsability of the destruction of configurationParameters is transfered to the object.
virtual ~ObjectDescriptor ()
 Destructor.
virtual const NamegetName () const
 get the name of the described object
virtual const NamegetClass () const
 get the class name of the described object
virtual const NamegetProcess () const
 get the process wich this object is affected to
virtual const FrequencygetFrequency () const
 get the frequency of the described object
virtual const FrequencygetOriginalFrequency () const
 get the original frequency of the described object
virtual Distribution getDistribution () const
 get the object type (default, local or duplicated)
virtual const ConfigurationParameterDescriptorgetConfigurationParameters () const
 get the configuration parameters of the controled object
virtual ConfigurationParameterDescriptorgetConfigurationParameters (bool create=false)
 get the configuration parameters of the controled object
virtual const ConfigurationParameterDescriptorgetExtensionsParameters () const
 get the extensions parameters of the controled object
virtual ConfigurationParameterDescriptorgetExtensionsParameters (bool create=false)
 get the extensions parameters of the controled object
virtual const MultipleConfigurationParametergetOriginalSchedulingParameters () const
 get the configuration parameters of the controled object
virtual const MultipleConfigurationParametergetSchedulingParameters () const
 get the configuration parameters of the controled object
virtual void setProcess (const Name &newProcessName)
 change the process of the described object
virtual void setFrequency (const Frequency &newFrequency)
 change the frequency of the described object
virtual void setDistribution (Distribution newDistribution)
 change the distribution of the described object
virtual void deleteCachedData ()
 in the event this object description contains cached data, delete it
virtual void unpack (IncomingSynchronisationMessage &in)
 unpack from a synchronisation message
virtual void pack (OutgoingSynchronisationMessage &out) const
 pack in a synchronisation message
virtual void extract (std::istream &in)
 extract from a stream
virtual void insertInStream (std::ostream &out) const
 insert in a stream
virtual MultipleConfigurationParametergetSchedulingParameters ()
 get the configuration parameters of the controled object (non const version)

Protected Member Functions

virtual SimulatedObjectcreateDescribedObject () const
 create the described object if _pointerToSimulatedObject is nil, create the described object.
virtual void setFathersDescription (ObjectDescriptor *newFather)
void interpretSchedulingParameters (MultipleConfigurationParameter *schedulingParameters)
 interpret a ConfigurationParameterDescriptor as the initial scheduling parameters non virtual because called by the constructor
virtual void printToStream (std::ostream &out, int currentOffset) const
 pretty insert in a stream

Protected Attributes

SimulatedObject_pointerToSimulatedObject
 if a simulated object corresponding to this descriptor has been created, a pointer to this object is memorised here.
bool _destroySimulatedObject
 a pointer indicating if _pointerToSimulatedObject is deletable by this object
Name _objectName
 decribed object's name
Name _classId
 decribed object's class
ConfigurationParameterDescriptor_configurationParameters
 described object's configuration parameters (isn't const to enable extraction
ConfigurationParameterDescriptor_extensionsParameters
 described object's extension parameters (isn't const to enable extraction
MultipleConfigurationParameter_originalSchedulingParameters
 described object's scheduling parameters
MultipleConfigurationParameter_schedulingParameters
 described object's scheduling parameters
ObjectDescriptor_fathersDescription
 a pointer to the objects father in the simulation tree
SonsContainerType _sonsContainer
 a container with all of the sons of an object.
bool _creatingObject
 the boolean used to avoid recursive creation : should be accessed only protected
pthread_t _creatingThread
 the thread id of the creating lock

Private Attributes

Name _processId
 decribed object's current process (stored to avoid reinterpreting the scheduling parameters)
Frequency _frequency
 decribed object's current frequency (stored to avoid reinterpreting the scheduling parameters)
Distribution _distribution
 decribed object's current distribution (stored to avoid reinterpreting the scheduling parameters)
Frequency _originalFrequency
 decribed object's current frequency (stored to avoid reinterpreting the scheduling parameters)

Friends

class Controller
 make the controller a friend so that only controllers can ask for the creation of the described simulation object and change the father of an object
class ObjectHandle
 make the object handle a friend so that only controllers can change the boolean indicating delete responsability
class SimulatedObject
 make the simulated object friend so it can change the _pointerToSimulatedObject as early as possible

Detailed Description

object of this class are used to store the description of simulated object, with data meaningfull for object outside the kernel.

Objects of this class store real data, and not references or pointers to data. Therefore, whatever the means of creation of any simulated object, the permanent location for its general data is in objects of this class. An object handle is responsible for the creation of the corresponding simulated object and of its destruction if its destruction wasn't handled over to the object's handle.

Author:
Siames
Version:
1.0
2007/03/05 Benoît Chanclou added the Type to add a new property in the simulated object instead of the ugly subclassing in OMKLocalObject and OMKDuplicatedObject, these classes were deleted. Add the Distribution field in the Sheduling parameter to allow the object to be Local or Duplicated. By default if this parameter is not defined, the distibution is the usual one. Example
visuOgre
{
...
        Class OgreVis
        Scheduling
        {
                Frequency 25
                Distribution Local
        }
        UserParams
        {
...

Definition at line 69 of file OMKObjectDescriptor.h.


Member Typedef Documentation

typedef std::list< ObjectDescriptor * > OMK::ObjectDescriptor::SonsContainerType

The type of the container memorizing the sons of the described object in the simulation tree.

Definition at line 245 of file OMKObjectDescriptor.h.


Member Enumeration Documentation

enum OMK::ObjectDescriptor::Distribution

Enumerator:
DEFAULT_OBJECT 
LOCAL_OBJECT 
DUPLICATED_OBJECT 

Definition at line 77 of file OMKObjectDescriptor.h.

00078    {
00079      DEFAULT_OBJECT = 0,
00080      LOCAL_OBJECT,
00081      DUPLICATED_OBJECT
00082    } ;


Constructor & Destructor Documentation

ObjectDescriptor::ObjectDescriptor (  )  [explicit]

default constructor needed for an object descriptor to be included in a valued event for distributed creation

Definition at line 33 of file OMKObjectDescriptor.cpp.

References OMASSERT.

Referenced by interpretConfigurationParameterAsObjectDescription(), and ObjectDescriptor().

00034   : _pointerToSimulatedObject( 0 ),
00035     _destroySimulatedObject( false ),
00036     _configurationParameters( 0 ),
00037     _extensionsParameters( 0 ),
00038     _originalSchedulingParameters( 0 ),
00039     _schedulingParameters( 0 ),
00040     _fathersDescription( 0 ),
00041     _creatingObject( false ),
00042 #ifndef _MSC_VER
00043     _creatingThread( 0 ),
00044 #endif
00045     _frequency( 0 ),
00046     _distribution( DEFAULT_OBJECT ),
00047     _originalFrequency( 0 )
00048 {
00049   // otherwise, the initial value of _creatingThread is inappropriate
00050 #if !defined _MSC_VER && defined _OMK_MUTEX_
00051   OMASSERT( pthread_self() != 0 ) ;
00052 #endif
00053 }

ObjectDescriptor::ObjectDescriptor ( const ObjectDescriptor  ) 

copy constructor

Definition at line 55 of file OMKObjectDescriptor.cpp.

References _configurationParameters, _destroySimulatedObject, _extensionsParameters, _originalSchedulingParameters, _pointerToSimulatedObject, _schedulingParameters, _sonsContainer, addSon(), OMK::MultipleConfigurationParameter::clone(), OMK::ConfigurationParameterDescriptor::clone(), ObjectDescriptor(), and OMASSERT.

00056   : _pointerToSimulatedObject( 0 ),
00057     _destroySimulatedObject( false ),
00058     _objectName( orig._objectName ),
00059     _classId( orig._classId ),
00060     _configurationParameters( 0 ),
00061     _extensionsParameters( 0 ),
00062     _originalSchedulingParameters( 0 ),
00063     _schedulingParameters( 0 ),
00064     _fathersDescription( 0 ),
00065     _creatingObject( false ),
00066     _processId( orig._processId ),
00067     _frequency( orig._frequency ),
00068     _distribution( orig._distribution ),
00069     _originalFrequency( orig._originalFrequency )
00070 {
00071   _configurationParameters =
00072     orig._configurationParameters != 0 ?
00073     orig._configurationParameters->clone() : 0 ;
00074 
00075   _extensionsParameters =
00076     orig._extensionsParameters != 0 ?
00077     orig._extensionsParameters->clone() : 0 ;
00078 
00079   _originalSchedulingParameters =
00080     orig._originalSchedulingParameters != 0 ?
00081     static_cast< MultipleConfigurationParameter *>(
00082       orig._originalSchedulingParameters->clone() ) : 0 ;
00083 
00084   _schedulingParameters =
00085     orig._schedulingParameters != 0 ?
00086     static_cast< MultipleConfigurationParameter *>(
00087       orig._schedulingParameters->clone() ) : 0 ;
00088 
00089   // Only one descriptor by object. Assume descriptor is copied only before
00090   // the described object is created
00091   OMASSERT( orig._pointerToSimulatedObject == 0 ) ;
00092   OMASSERT( orig._destroySimulatedObject == false ) ;
00093 
00094   // copy the sons
00095   for( SonsContainerType::const_iterator i = orig._sonsContainer.begin() ;
00096        i != orig. _sonsContainer.end() ;
00097        ++i )
00098   {
00099     addSon( new ObjectDescriptor( *( *i ) ) ) ;
00100   }
00101 }

ObjectDescriptor::ObjectDescriptor ( const Name objectName,
const Name classId,
MultipleConfigurationParameter schedulingParameters,
ConfigurationParameterDescriptor configurationParameters,
ConfigurationParameterDescriptor extensionParameters = 0 
)

Constructor responsability of the destruction of schedulingParameters and configurationParameters is transfered to the object.

Definition at line 183 of file OMKObjectDescriptor.cpp.

References interpretSchedulingParameters(), and OMASSERT.

00189   : _pointerToSimulatedObject( 0 ),
00190     _destroySimulatedObject( false ),
00191     _objectName( objectName ),
00192     _classId( classId ),
00193     _configurationParameters( configurationParameters ),
00194     _extensionsParameters( extensionsParameters ),
00195     _originalSchedulingParameters( 0 ),
00196     _schedulingParameters( schedulingParameters ),
00197     _fathersDescription( 0 ),
00198     _creatingObject( false )
00199 #if !defined _MSC_VER && defined _OMK_MUTEX_
00200     ,_creatingThread( 0 )
00201 #endif
00202 {
00203 #if !defined _MSC_VER && defined _OMK_MUTEX_
00204   OMASSERT( pthread_self() != 0 ) ;
00205 #endif
00206 
00207   interpretSchedulingParameters( schedulingParameters ) ;
00208 }

ObjectDescriptor::ObjectDescriptor ( const Name objectName,
const Name classId,
const Frequency frequency,
ConfigurationParameterDescriptor configurationParameters,
ConfigurationParameterDescriptor extensionParameters = 0,
Distribution  distribution = DEFAULT_OBJECT 
)

Constructor, used as a shortcut for constructing correct scheduling parameters responsability of the destruction of configurationParameters is transfered to the object.

Definition at line 145 of file OMKObjectDescriptor.cpp.

References _originalSchedulingParameters, _schedulingParameters, OMK::MultipleConfigurationParameter::appendSubDescriptorNamed(), OMK::MultipleConfigurationParameter::clone(), and OMASSERT.

00152   : _pointerToSimulatedObject( 0 ),
00153     _destroySimulatedObject( false ),
00154     _objectName( objectName ),
00155     _classId( classId ),
00156     _configurationParameters( configurationParameters ),
00157     _extensionsParameters( extensionsParameters ),
00158     _originalSchedulingParameters( 0 ),
00159     _schedulingParameters( 0 ),
00160     _fathersDescription( 0 ),
00161     _creatingObject( false ),
00162 #ifndef _MSC_VER
00163     _creatingThread( 0 ),
00164 #endif
00165     _frequency( frequency ),
00166     _distribution( distribution ),
00167     _originalFrequency( frequency )
00168 {
00169 #if !defined _MSC_VER && defined _OMK_MUTEX_
00170   OMASSERT( pthread_self() != 0 ) ;
00171 #endif
00172 
00173   _schedulingParameters = new MultipleConfigurationParameter() ;
00174   std::ostringstream freq ;
00175   freq << frequency ;
00176   _schedulingParameters->appendSubDescriptorNamed(
00177     "Frequency", 
00178     new UniqueConfigurationParameter( freq.str() ) ) ;
00179   _originalSchedulingParameters = static_cast< MultipleConfigurationParameter *>(
00180     _schedulingParameters->clone() ) ;
00181 }

ObjectDescriptor::ObjectDescriptor ( const Name objectName,
const Name classId,
const Name processId,
const Frequency frequency,
ConfigurationParameterDescriptor configurationParameters,
ConfigurationParameterDescriptor extensionParameters = 0,
Distribution  distribution = DEFAULT_OBJECT 
)

Constructor, used as a shortcut for constructing correct scheduling parameters responsability of the destruction of configurationParameters is transfered to the object.

Definition at line 103 of file OMKObjectDescriptor.cpp.

References _originalSchedulingParameters, _schedulingParameters, OMK::MultipleConfigurationParameter::appendSubDescriptorNamed(), OMK::MultipleConfigurationParameter::clone(), OMK::Name::getString(), and OMASSERT.

00111   : _pointerToSimulatedObject( 0 ),
00112     _destroySimulatedObject( false ),
00113     _objectName( objectName ),
00114     _classId( classId ),
00115     _configurationParameters( configurationParameters ),
00116     _extensionsParameters( extensionsParameters ),
00117     _originalSchedulingParameters( 0 ),
00118     _schedulingParameters( 0 ),
00119     _fathersDescription( 0 ),
00120     _creatingObject( false ),
00121 #ifndef _MSC_VER
00122     _creatingThread( 0 ),
00123 #endif
00124     _processId( processId ),
00125     _frequency( frequency ),
00126     _distribution( distribution ),
00127     _originalFrequency( frequency )
00128 {
00129 #if !defined _MSC_VER && defined _OMK_MUTEX_
00130   OMASSERT( pthread_self() != 0 ) ;
00131 #endif
00132   _schedulingParameters = new MultipleConfigurationParameter() ;
00133   std::ostringstream freq ;
00134   freq << frequency ;
00135   _schedulingParameters->appendSubDescriptorNamed(
00136     "Frequency",
00137     new UniqueConfigurationParameter( freq.str() ) ) ;
00138   _schedulingParameters->appendSubDescriptorNamed(
00139     "Process",
00140     new UniqueConfigurationParameter( processId.getString() ) ) ;
00141   _originalSchedulingParameters = static_cast< MultipleConfigurationParameter *>(
00142     _schedulingParameters->clone() ) ;
00143 }

ObjectDescriptor::~ObjectDescriptor (  )  [virtual]

Destructor.

Definition at line 210 of file OMKObjectDescriptor.cpp.

References _configurationParameters, _destroySimulatedObject, _extensionsParameters, _fathersDescription, _originalSchedulingParameters, _pointerToSimulatedObject, _schedulingParameters, _sonsContainer, getName(), OMERROR, OMK_DEBUG_OMK_OBJ, OMTRACEID, and removeSon().

00211 {
00212   if( _destroySimulatedObject )
00213   {
00214     if( _pointerToSimulatedObject == 0 )
00215     {
00216       OMERROR( "ObjectDescriptor::~ObjectDescriptor() destroying "
00217                << getName() << " in incooherant state" << std::endl ) ;
00218     }
00219     delete _pointerToSimulatedObject ;
00220   }
00221 
00222   if( _fathersDescription != 0 )
00223   {
00224     _fathersDescription->removeSon( this ) ;
00225   }
00226 
00227   delete _originalSchedulingParameters ;
00228   delete _schedulingParameters ;
00229   delete _configurationParameters ;
00230   delete _extensionsParameters ;
00231 
00232   if( !_sonsContainer.empty() )
00233   {
00234     OMTRACEID( OMK_DEBUG_OMK_OBJ, "ObjectDescriptor with "
00235                << _sonsContainer.size()
00236                << " remaining sons deleted. Sons not deleted" << std::endl ) ;
00237   }
00238 }


Member Function Documentation

virtual const Name& OMK::ObjectDescriptor::getName (  )  const [inline, virtual]

get the name of the described object

Definition at line 124 of file OMKObjectDescriptor.h.

Referenced by addSon(), OMK::PvmMirrorObjectHandle::cancelRegistrationForSignal(), createDescribedObject(), OMK::DistributedController::createDuplicatedObject(), OMK::DistributedController::createLocalObject(), OMK::DistributedController::createMirrorObject(), OMK::Controller::createReferenceObject(), OMK::Controller::deleteObject(), OMK::Controller::deleteObjectHandle(), findDescendantNamed(), OMK::SimulatedObject::getFather(), OMK::SimulatedObject::getName(), OMK::SimulatedObject::isAncestor(), OMK::operator<=(), printToStream(), OMK::Controller::processDeleteEventOf(), OMK::Controller::processEvent(), OMK::DistributedController::processNewObjectDeclaration(), OMK::PvmMirrorObjectHandle::receiveEvent(), OMK::PvmMirrorObjectHandle::receiveRegistrationForSignal(), OMK::Controller::sendInitialEventsTo(), setFathersDescription(), and ~ObjectDescriptor().

00125    {
00126      return _objectName ;
00127    }

virtual const Name& OMK::ObjectDescriptor::getClass (  )  const [inline, virtual]

get the class name of the described object

Definition at line 131 of file OMKObjectDescriptor.h.

Referenced by createDescribedObject(), OMK::debugMsg(), OMK::Vis::VisObjectExtension::loadAnimatorParameters(), and printToStream().

00132    {
00133      return _classId ;
00134    }

virtual const Name& OMK::ObjectDescriptor::getProcess (  )  const [inline, virtual]

get the process wich this object is affected to

Definition at line 138 of file OMKObjectDescriptor.h.

Referenced by OMK::DistributedController::createLocalObject(), OMK::DistributedController::createObject(), OMK::DistributedController::getPointerToSimulatedObjectNamed(), OMK::DistributedController::processEvent(), OMK::DistributedController::processNewObjectDeclaration(), OMK::PvmMirrorObjectHandle::PvmMirrorObjectHandle(), and OMK::PvmMirrorObjectHandle::sendRequestToReferenceObject().

00139    {
00140      return _processId ;
00141    }

virtual const Frequency& OMK::ObjectDescriptor::getFrequency (  )  const [inline, virtual]

get the frequency of the described object

Definition at line 145 of file OMKObjectDescriptor.h.

Referenced by OMK::Controller::computeScheduling(), OMK::SimulatedObject::getPeriod(), OMK::DistributedController::getPointerToSimulatedObjectNamed(), OMK::Clock::init(), OMK::Controller::processNewObjectDeclaration(), and OMK::Controller::sendInitialEventsTo().

00146    {
00147      return _frequency ;
00148    }

virtual const Frequency& OMK::ObjectDescriptor::getOriginalFrequency (  )  const [inline, virtual]

get the original frequency of the described object

Definition at line 152 of file OMKObjectDescriptor.h.

Referenced by OMK::Controller::computeScheduling().

00153    {
00154      return _originalFrequency ;
00155    }

virtual Distribution OMK::ObjectDescriptor::getDistribution (  )  const [inline, virtual]

get the object type (default, local or duplicated)

Definition at line 159 of file OMKObjectDescriptor.h.

Referenced by OMK::Controller::getPointerToDuplicatedObjectNamed(), and OMK::DistributedController::getPointerToSimulatedObjectNamed().

00160    {
00161      return _distribution ;
00162    }

virtual const ConfigurationParameterDescriptor* OMK::ObjectDescriptor::getConfigurationParameters (  )  const [inline, virtual]

get the configuration parameters of the controled object

Definition at line 166 of file OMKObjectDescriptor.h.

Referenced by OMK::SimulatedObject::getConfigurationParameters(), and printToStream().

00167    {
00168      return _configurationParameters ;
00169    }

ConfigurationParameterDescriptor * ObjectDescriptor::getConfigurationParameters ( bool  create = false  )  [virtual]

get the configuration parameters of the controled object

Definition at line 241 of file OMKObjectDescriptor.cpp.

References _configurationParameters.

00243 {
00244   if( create && !_configurationParameters )
00245   {
00246     _configurationParameters = new MultipleConfigurationParameter() ;
00247   }
00248   return _configurationParameters ;
00249 }

virtual const ConfigurationParameterDescriptor* OMK::ObjectDescriptor::getExtensionsParameters (  )  const [inline, virtual]

get the extensions parameters of the controled object

Definition at line 177 of file OMKObjectDescriptor.h.

Referenced by OMK::ExtensibleSimulatedObject::init(), and printToStream().

00178    {
00179      return _extensionsParameters ;
00180    }

ConfigurationParameterDescriptor * ObjectDescriptor::getExtensionsParameters ( bool  create = false  )  [virtual]

get the extensions parameters of the controled object

Definition at line 251 of file OMKObjectDescriptor.cpp.

References _extensionsParameters.

00253 {
00254   if( create && !_extensionsParameters )
00255   {
00256     _extensionsParameters = new MultipleConfigurationParameter() ;
00257   }
00258   return _extensionsParameters ;
00259 }

virtual const MultipleConfigurationParameter* OMK::ObjectDescriptor::getOriginalSchedulingParameters (  )  const [inline, virtual]

get the configuration parameters of the controled object

Definition at line 188 of file OMKObjectDescriptor.h.

00189    {
00190      return _originalSchedulingParameters ;
00191    }

virtual const MultipleConfigurationParameter* OMK::ObjectDescriptor::getSchedulingParameters (  )  const [inline, virtual]

get the configuration parameters of the controled object

Definition at line 195 of file OMKObjectDescriptor.h.

Referenced by OMK::Controller::getSchedulingParametersOfObject(), and printToStream().

00196    {
00197      return _schedulingParameters ;
00198    }

void ObjectDescriptor::setProcess ( const Name newProcessName  )  [virtual]

change the process of the described object

Definition at line 394 of file OMKObjectDescriptor.cpp.

References _processId, _schedulingParameters, OMK::MultipleConfigurationParameter::appendSubDescriptorNamed(), OMK::UniqueConfigurationParameter::changeConfigurationParameter(), OMK::Name::getCString(), and OMK::MultipleConfigurationParameter::getSubDescriptorByName().

Referenced by OMK::DistributedController::processEvent(), and OMK::Controller::setProcessOfDescriptor().

00395 {
00396   _processId = newProcessName ;
00397   UniqueConfigurationParameter * description =
00398     dynamic_cast< UniqueConfigurationParameter * >(
00399       _schedulingParameters->getSubDescriptorByName( "Process" ) );
00400   if( description != 0 )
00401   {
00402     description->changeConfigurationParameter( newProcessName.getCString() ) ;
00403   }
00404   else
00405   {
00406     _schedulingParameters->appendSubDescriptorNamed(
00407       "Process", 
00408       new UniqueConfigurationParameter( newProcessName.getCString() ) ) ;
00409   }
00410 }

void ObjectDescriptor::setFrequency ( const Frequency newFrequency  )  [virtual]

change the frequency of the described object

Definition at line 412 of file OMKObjectDescriptor.cpp.

References _frequency, _schedulingParameters, OMK::MultipleConfigurationParameter::appendSubDescriptorNamed(), OMK::UniqueConfigurationParameter::changeConfigurationParameter(), and OMK::MultipleConfigurationParameter::getSubDescriptorByName().

Referenced by OMK::Controller::computeScheduling(), and OMK::Controller::reactToControlledObjectsSystemEvents().

00413 {
00414   _frequency = newFrequency ;
00415    
00416   UniqueConfigurationParameter *description =
00417     dynamic_cast< UniqueConfigurationParameter * >(
00418       _schedulingParameters->getSubDescriptorByName( "Frequency" ) );
00419   if( description != 0 )
00420   {
00421     std::ostringstream freq ;
00422     freq << newFrequency ;
00423     description->changeConfigurationParameter( freq.str() ) ;
00424   }
00425   else
00426   {
00427     std::ostringstream freq ;
00428     freq << newFrequency ;
00429     _schedulingParameters->appendSubDescriptorNamed(
00430       "Frequency",
00431       new UniqueConfigurationParameter( freq.str() ) ) ;
00432   }
00433 }

void ObjectDescriptor::setDistribution ( Distribution  newDistribution  )  [virtual]

change the distribution of the described object

Definition at line 435 of file OMKObjectDescriptor.cpp.

References _distribution, _schedulingParameters, OMK::MultipleConfigurationParameter::appendSubDescriptorNamed(), OMK::UniqueConfigurationParameter::changeConfigurationParameter(), DUPLICATED_OBJECT, OMK::MultipleConfigurationParameter::getSubDescriptorByName(), and LOCAL_OBJECT.

00436 {
00437   _distribution = newDistribution ;
00438    UniqueConfigurationParameter *description =
00439      dynamic_cast< UniqueConfigurationParameter * >(
00440        _schedulingParameters->getSubDescriptorByName( "Distribution" ) ) ;
00441    if( description != 0 )
00442    {
00443      description->changeConfigurationParameter(
00444        ( newDistribution == DUPLICATED_OBJECT ) ? "Duplicated" :
00445        ( ( newDistribution == LOCAL_OBJECT ) ? "Local" : "Default" ) ) ;
00446    }
00447    else
00448    {
00449      _schedulingParameters->appendSubDescriptorNamed(
00450        "Distribution", 
00451        new UniqueConfigurationParameter(
00452          ( newDistribution == DUPLICATED_OBJECT ) ? "Duplicated" :
00453          ( ( newDistribution == LOCAL_OBJECT ) ? "Local" : "Default" ) ) ) ;
00454    }
00455 }

void ObjectDescriptor::deleteCachedData (  )  [virtual]

in the event this object description contains cached data, delete it

Definition at line 724 of file OMKObjectDescriptor.cpp.

References _destroySimulatedObject, _pointerToSimulatedObject, and OMASSERT.

00725 {
00726   if( _destroySimulatedObject )
00727   {
00728     OMASSERT( _pointerToSimulatedObject != 0 ) ;
00729     delete _pointerToSimulatedObject ;
00730     _pointerToSimulatedObject = 0 ;
00731   }
00732   _destroySimulatedObject = false ;
00733 }

void ObjectDescriptor::unpack ( IncomingSynchronisationMessage in  )  [virtual]

unpack from a synchronisation message

Reimplemented from OMK::Flowable.

Definition at line 261 of file OMKObjectDescriptor.cpp.

References extract().

00262 {
00263   std::string messageBuffer ;
00264   in >> messageBuffer ;
00265   std::istringstream message( messageBuffer );
00266   extract(message ) ;
00267 }

void ObjectDescriptor::pack ( OutgoingSynchronisationMessage out  )  const [virtual]

pack in a synchronisation message

Reimplemented from OMK::Flowable.

Definition at line 269 of file OMKObjectDescriptor.cpp.

References printToStream().

00270 {
00271   // packed in a quite inefficient way (unsing the string representation of the
00272   // object descriptor), 
00273   // but much simpler to decode : therefore, use extract
00274   std::ostringstream char_out ;
00275   printToStream( char_out, 0 ) ;
00276   out << char_out.str() ;
00277 }

void ObjectDescriptor::extract ( std::istream &  in  )  [virtual]

extract from a stream

Implements OMK::Flowable.

Definition at line 279 of file OMKObjectDescriptor.cpp.

References _classId, _configurationParameters, _extensionsParameters, _objectName, _sonsContainer, OMK::ConfigurationParameterDescriptor::getAssociatedString(), OMK::MultipleConfigurationParameter::getSubDescriptorByName(), interpretConfigurationParameterAsListOfSons(), and interpretSchedulingParameters().

Referenced by unpack().

00280 {
00281   _sonsContainer.clear() ;
00282    
00283   KernelIstreamLexer< std::istream > inputStream( in ) ;
00284   DLGLexer scan( & inputStream ) ;
00285   ANTLRTokenBuffer pipe( & scan ) ;
00286   ANTLRTokenPtr aToken = new ANTLRToken() ;
00287   scan.setToken( mytoken( aToken ) ) ;
00288   genericKernelParser extractor( &pipe ) ;
00289   extractor.init() ;
00290 
00291   std::string stringName;
00292   extractor.key( stringName ) ;
00293   _objectName = stringName ;
00294 
00295   ConfigurationParameterDescriptor *genericSubDescription =
00296     extractor.anonymousValue() ;
00297   MultipleConfigurationParameter * generalDescription =
00298     dynamic_cast< MultipleConfigurationParameter * >( genericSubDescription );
00299   if( generalDescription == 0 )
00300   {
00301     throw UserException( "Unable to extract a name for an ObjectDescriptor from a stream" ) ;
00302   }
00303 
00304   genericSubDescription = generalDescription->getSubDescriptorByName( "Class" ) ;
00305   if( genericSubDescription == 0 ) 
00306   {
00307     throw UserException( "Unable to extract a class for an ObjectDescriptor from a stream") ;
00308   }
00309   _classId = genericSubDescription->getAssociatedString() ;
00310 
00311   delete _configurationParameters ;
00312   _configurationParameters =
00313     generalDescription->getSubDescriptorByName( "UserParams" ) ;
00314 
00315   delete _extensionsParameters ;
00316   _extensionsParameters =
00317     generalDescription->getSubDescriptorByName( "Extensions" ) ;
00318 
00319   genericSubDescription =
00320     generalDescription->getSubDescriptorByName( "Scheduling" ) ;
00321   if( genericSubDescription !=0 )
00322   {
00323     interpretSchedulingParameters(
00324       dynamic_cast< MultipleConfigurationParameter * >( genericSubDescription ) ) ;
00325   }
00326   else
00327   {
00328     interpretSchedulingParameters( 0 ) ;
00329   }
00330 
00331   genericSubDescription = generalDescription->getSubDescriptorByName( "Sons" ) ;
00332   generalDescription =
00333     dynamic_cast< MultipleConfigurationParameter * >( genericSubDescription ) ;
00334   if( generalDescription != 0 )
00335   {
00336     interpretConfigurationParameterAsListOfSons( _sonsContainer, generalDescription ) ;
00337   }
00338 }

void ObjectDescriptor::insertInStream ( std::ostream &  out  )  const [virtual]

insert in a stream

Implements OMK::Flowable.

Definition at line 389 of file OMKObjectDescriptor.cpp.

References printToStream().

00390 {
00391   printToStream( out, 0 ) ;
00392 } 

virtual const ObjectDescriptor* OMK::ObjectDescriptor::getFathersObjectDescriptor (  )  const [inline, virtual]

get the object descriptor of the father

Definition at line 232 of file OMKObjectDescriptor.h.

Referenced by createDescribedObject(), OMK::Controller::deleteObject(), OMK::SimulatedObject::getFather(), OMK::SimulatedObject::getFathersDescriptor(), OMK::SimulatedObject::isAncestor(), and OMK::Controller::listBrothersOfType().

00233    {
00234      return _fathersDescription ;
00235    }

virtual ObjectDescriptor* OMK::ObjectDescriptor::getFathersObjectDescriptor (  )  [inline, virtual]

get the object descriptor of the father

Definition at line 239 of file OMKObjectDescriptor.h.

00240    {
00241      return _fathersDescription ;
00242    }

virtual SonsContainerType& OMK::ObjectDescriptor::getSons (  )  [inline, virtual]

get a container with all the sons of this object in the simulation tree

Definition at line 249 of file OMKObjectDescriptor.h.

Referenced by OMK::DistributedController::createControlledObjects(), OMK::Controller::createControlledObjects(), OMK::Controller::destroyObject(), and OMK::Controller::finish().

00250    {
00251      return _sonsContainer ;
00252    }

virtual const std::list< ObjectDescriptor * >* OMK::ObjectDescriptor::getSons (  )  const [inline, virtual]

get a container with all the sons of this object in the simulation tree the resulting list should be deleted

Definition at line 257 of file OMKObjectDescriptor.h.

00258    {
00259      return & _sonsContainer ;
00260    }

std::list< const ObjectDescriptor * > * ObjectDescriptor::getDescendants (  )  const [virtual]

get a container with all the descendants of this object in the simualtion tree the result should be deleted after usage if the object has no descendants, an empty list is returned

Definition at line 760 of file OMKObjectDescriptor.cpp.

Referenced by OMK::Controller::computeScheduling(), getDescendants(), and OMK::PvmController::PvmController().

00761 {
00762   std::list< const ObjectDescriptor * > *result =
00763     new std::list< const ObjectDescriptor * >() ;
00764   return getDescendants( result ) ;
00765 }

std::list< const ObjectDescriptor * > * ObjectDescriptor::getDescendants ( std::list< const ObjectDescriptor * > *  resultList  )  const [virtual]

get a container with all the descendants of this object in the simualtion tree

Parameters:
resultList : the list in wich the descendants should be inserted. The list is unchanged if no descendants are found the result should be deleted after usage if the object has no descendants, an empty list is returned

Definition at line 767 of file OMKObjectDescriptor.cpp.

References _sonsContainer.

00769 {
00770   for( SonsContainerType::const_iterator i = _sonsContainer.begin() ;
00771        i != _sonsContainer.end() ;
00772        ++i )
00773   {
00774     resultList->push_back( *i ) ;
00775     ( *i )->getDescendants( resultList ) ;
00776   }
00777   return resultList ;
00778 }

std::list< ObjectDescriptor * > * ObjectDescriptor::getDescendants (  )  [virtual]

get a container with all the descendants of this object in the simualtion tree the result should be deleted after usage if the object has no descendants, an empty list is returned

Definition at line 780 of file OMKObjectDescriptor.cpp.

References getDescendants().

00781 {
00782   std::list< ObjectDescriptor * > *result = new std::list< ObjectDescriptor * >() ;
00783   return getDescendants( result ) ;
00784 }

std::list< ObjectDescriptor * > * ObjectDescriptor::getDescendants ( std::list< ObjectDescriptor * > *  resultList  )  [virtual]

get a container with all the descendants of this object in the simualtion tree

Parameters:
resultList : the list in wich the descendants should be inserted. The list is unchanged if no descendants are found the result should be deleted after usage if the object has no descendants, an empty list is returned

Definition at line 786 of file OMKObjectDescriptor.cpp.

References _sonsContainer.

00788 {
00789   for( SonsContainerType::const_iterator i = _sonsContainer.begin() ;
00790        i != _sonsContainer.end() ;
00791        ++i )
00792   {
00793     resultList->push_back( *i ) ;
00794     ( *i )->getDescendants( resultList ) ;
00795   }
00796   return resultList ;
00797 }

void ObjectDescriptor::addSon ( ObjectDescriptor newSon  )  [virtual]

add a son in the simulation tree to the described object If called after initialisation of the controller, isn't taken into account by the controller

Parameters:
newSon the added son. Responsability of the destruction of that descriptor is passed to this object descriptor. Nevertheless, all sons should be removed before this object descriptor is deleted (to ensure the controllers data structures reflect addition and removal of sons ). Moreover, if addition fails, the newSon is destroyed

Definition at line 735 of file OMKObjectDescriptor.cpp.

References _fathersDescription, _sonsContainer, findDescendantNamed(), getName(), OMASSERT, OMK_DEBUG_OMK_OBJ, and OMTRACEID.

Referenced by ObjectDescriptor(), and setFathersDescription().

00736 {
00737    OMASSERT( newSon != 0 ) ;
00738    const ObjectDescriptor *duplicate = findDescendantNamed( newSon->getName() ) ;
00739    if( duplicate == 0 )
00740    {
00741      _sonsContainer.push_back( newSon ) ;
00742      newSon->_fathersDescription = this ;
00743    }
00744    else
00745    {
00746      OMTRACEID( OMK_DEBUG_OMK_OBJ,
00747                 "ObjectDescriptor::addSon named \"" << newSon->getName()
00748                 << "\" failed because descendant with the same name allready exists for object named \""
00749                 << getName() << "\"" ) ;
00750      // as respnsability is transfered and the son is not added, delete it
00751      delete newSon ;
00752    }
00753 }

void ObjectDescriptor::removeSon ( ObjectDescriptor oldSon  )  [virtual]

remove a son in the simulation tree If called after initialisation of the controller, isn't taken into account by the controller

Parameters:
oldSon the son to remove. The removed son is not deleted

Definition at line 755 of file OMKObjectDescriptor.cpp.

References _sonsContainer.

Referenced by OMK::Controller::deleteObject(), setFathersDescription(), and ~ObjectDescriptor().

00756 {
00757   _sonsContainer.remove( oldSon ) ;
00758 }

template<typename Type>
std::list< const ObjectDescriptor * > * OMK::ObjectDescriptor::listSonsOfType (  )  const

listSonsOfType.

Returns:
the list of sons of the current node that are of the type of the template parameter delete the resulting list after usage

Definition at line 486 of file OMKObjectDescriptor.h.

00486 {
00487   return listSonsOfType< Type >( new std::list< const ObjectDescriptor * >() );
00488 }
00489 //------------------------------------------------------------------------------

template<typename Type>
std::list< const ObjectDescriptor * > * OMK::ObjectDescriptor::listSonsOfType ( std::list< const ObjectDescriptor * > *  resultList  )  const

list the sons of a certain Type.

Parameters:
resultList a list to be used to store the result
Returns:
the list of sons of the current node that are of the type of the template parameter

Definition at line 493 of file OMKObjectDescriptor.h.

References _sonsContainer.

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 //------------------------------------------------------------------------------

template<typename Type>
std::list< const ObjectDescriptor * > * OMK::ObjectDescriptor::listDescendantsOfType (  )  const

listDescendantsOfType.

Returns:
the list of descendants of the current node that are of the type of the template parameter

Definition at line 510 of file OMKObjectDescriptor.h.

00510 {
00511   return listDescendantsOfType< Type >(
00512     new std::list< const ObjectDescriptor * >() );
00513 }
00514 //------------------------------------------------------------------------------

template<typename Type>
std::list< const ObjectDescriptor * > * OMK::ObjectDescriptor::listDescendantsOfType ( std::list< const ObjectDescriptor * > *  resultList  )  const

listDescendantsOfType.

Parameters:
resultList a list to be used to store the result
Returns:
the list of descendants of the current node that are of the type of the template parameter delete the resulting list after usage

Definition at line 518 of file OMKObjectDescriptor.h.

References _sonsContainer, createDescribedObject(), and OMASSERTM.

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 //------------------------------------------------------------------------------

const ObjectDescriptor * ObjectDescriptor::findDescendantNamed ( const Name name  )  const [virtual]

find a descendant of this node

Parameters:
name the named of the searched descriptor

Definition at line 800 of file OMKObjectDescriptor.cpp.

References _sonsContainer, findDescendantNamed(), and getName().

Referenced by addSon(), OMK::Controller::changeObjectsFather(), OMK::Controller::destroyObject(), findDescendantNamed(), OMK::DistributedController::getObjectDescriptorOfObject(), OMK::Controller::getObjectDescriptorOfObject(), OMK::DistributedController::getPointerToSimulatedObjectNamed(), OMK::Controller::listBrothersOfType(), OMK::Controller::listDescendantsOfType(), OMK::DistributedController::processEvent(), OMK::Controller::processEvent(), OMK::Controller::reactToControlledObjectsSystemEvents(), and setFathersDescription().

00801 {
00802   const ObjectDescriptor *resul( 0 ) ;  
00803   if( name == getName() )
00804   {
00805     resul = this ;
00806   }
00807   else
00808   {
00809     SonsContainerType::const_iterator i = _sonsContainer.begin() ;
00810     while( ( resul == 0 ) && ( i != _sonsContainer.end() ) )
00811     {
00812       resul = ( *i )->findDescendantNamed( name ) ;
00813       ++i ;
00814     }
00815   }
00816   return resul ;
00817 }

ObjectDescriptor * ObjectDescriptor::findDescendantNamed ( const Name name  )  [virtual]

find a descendant of this node

Parameters:
name the named of the searched descriptor

Definition at line 820 of file OMKObjectDescriptor.cpp.

References _sonsContainer, findDescendantNamed(), and getName().

00821 {
00822   ObjectDescriptor *resul( 0 ) ;
00823   if( name == getName() )
00824   {
00825     resul = this ;
00826   }
00827   else
00828   {
00829     SonsContainerType::iterator i = _sonsContainer.begin() ;
00830     while( ( resul == 0 ) && ( i != _sonsContainer.end() ) )
00831     {
00832       resul = ( *i )->findDescendantNamed( name ) ;
00833       ++i ;
00834     }
00835   }
00836   return resul ;
00837 }

void ObjectDescriptor::interpretConfigurationParameterAsListOfSons ( SonsContainerType listOfSons,
MultipleConfigurationParameter sonsDescription 
) [static]

helper function, to help interpret a object described as a configuration parameter

Definition at line 839 of file OMKObjectDescriptor.cpp.

References OMK::MultipleConfigurationParameter::getNameOfSubDescriptor(), OMK::MultipleConfigurationParameter::getNumberOfSubItems(), OMK::MultipleConfigurationParameter::getSubDescriptorByPosition(), and interpretConfigurationParameterAsObjectDescription().

Referenced by extract(), and interpretConfigurationParameterAsObjectDescription().

00842 {
00843   if( sonsDescription != 0 )
00844   {
00845     int nbSons = sonsDescription->getNumberOfSubItems() ;
00846     std::string sonName ;
00847     for( int i = 0 ; i < nbSons ; ++i )
00848     {
00849       ConfigurationParameterDescriptor * aGenericSonsDescription ;
00850       aGenericSonsDescription = sonsDescription->getSubDescriptorByPosition( i ) ;
00851       sonName = sonsDescription->getNameOfSubDescriptor( i ) ;
00852       MultipleConfigurationParameter * aSonsDescription ;
00853       aSonsDescription = dynamic_cast< MultipleConfigurationParameter * >(
00854         aGenericSonsDescription ) ;
00855       if( aSonsDescription != 0 )
00856       {
00857         ObjectDescriptor * descriptionOfSon =
00858           interpretConfigurationParameterAsObjectDescription(
00859             sonName, aSonsDescription ) ;
00860         listOfSons.push_back( descriptionOfSon );
00861       }
00862     }
00863   }
00864 }

ObjectDescriptor * ObjectDescriptor::interpretConfigurationParameterAsObjectDescription ( std::string  objectName,
MultipleConfigurationParameter  
) [static]

helper function, to create a object described as a configuration parameter

Definition at line 866 of file OMKObjectDescriptor.cpp.

References OMK::ConfigurationParameterDescriptor::getAssociatedString(), OMK::MultipleConfigurationParameter::getSubDescriptorByName(), interpretConfigurationParameterAsListOfSons(), ObjectDescriptor(), and OMASSERT.

Referenced by interpretConfigurationParameterAsListOfSons().

00869 {
00870   OMASSERT( generalDescription != 0 ) ;
00871 
00872   ConfigurationParameterDescriptor *genericSubDescription =
00873     generalDescription->getSubDescriptorByName( "Class" ) ;
00874 
00875   if( genericSubDescription == 0 ) 
00876   {
00877     throw UserException( "Unable to extract a class for an ObjectDescriptor from a stream" ) ;
00878   }
00879 
00880   std::string classId = genericSubDescription->getAssociatedString() ;
00881 
00882   ConfigurationParameterDescriptor *configurationParameters =
00883     generalDescription->getSubDescriptorByName( "UserParams" ) ;
00884 
00885 
00886   ConfigurationParameterDescriptor *extensionsParameters =
00887     generalDescription->getSubDescriptorByName( "Extensions" ) ;
00888 
00889 
00890   MultipleConfigurationParameter *schedulingParameters =
00891     dynamic_cast< MultipleConfigurationParameter * >(
00892       generalDescription->getSubDescriptorByName( "Scheduling" ) ) ;
00893 
00894   ObjectDescriptor *result = new ObjectDescriptor( Name( objectName ),
00895                                                    Name( classId ),
00896                                                    schedulingParameters,
00897                                                    configurationParameters,
00898                                                    extensionsParameters ) ;
00899 
00900   genericSubDescription = generalDescription->getSubDescriptorByName( "Sons" ) ;
00901   generalDescription =
00902     dynamic_cast< MultipleConfigurationParameter * >( genericSubDescription ) ;
00903   if( generalDescription != 0 )
00904   {
00905     interpretConfigurationParameterAsListOfSons(
00906       result->_sonsContainer, generalDescription ) ;
00907     //for all the sons, connect to their father, only known here
00908     for( SonsContainerType::const_iterator i = result->_sonsContainer.begin() ;
00909          i != result->_sonsContainer.end() ;
00910          ++i )
00911     {
00912       ( *i )->_fathersDescription = result ;
00913     }
00914   }
00915   return result ;
00916 }

SimulatedObject * ObjectDescriptor::createDescribedObject (  )  const [protected, virtual]

create the described object if _pointerToSimulatedObject is nil, create the described object.

Otherwise, returns a pointer to the previously created object responsability of the destruction of the object is kept by this objectDescriptor until _destroySimulatedObject is reset to false In particular, this member function is used for searches in the simulation tree in distributed contexts. the created object isn't handled to the controler for scheduling or other purposes, and isn't encapsulated in an object handle. only the constructor of the created object has been called

Definition at line 543 of file OMKObjectDescriptor.cpp.

References _creatingObject, _creatingThread, _destroySimulatedObject, _fathersDescription, _pointerToSimulatedObject, createDescribedObject(), getClass(), OMK::SimulatedObject::getController(), getFathersObjectDescriptor(), getName(), OMK_DEBUG_OMK_OBJ, and OMTRACEID.

Referenced by createDescribedObject(), OMK::Controller::createDescribedObject(), and listDescendantsOfType().

00544 {
00545 #if !defined _MSC_VER && defined _OMK_MUTEX_
00546   //here, use mutual exclusion, to avoid
00547   // 1 - recursive creation loops
00548   // 2 - simultaneous creations
00549   // 3 - recursive creation loops during simultaneous creations!
00550   //therefore, only allow one thread to do creation at a time (share the
00551   // creatingThread exclusion lock, and test to see if we're in a recursive loop)
00552 
00553   _dataLock.protect() ;
00554 
00555   SimulatedObject *result( _pointerToSimulatedObject ) ;
00556 
00557   if( _pointerToSimulatedObject == 0 )
00558   {
00559     if( _creatingObject && ( _creatingThread == pthread_self() ) )
00560     {
00561       // recursive creation loop : return null is the best that can be done
00562       _dataLock.unprotect() ;
00563     }
00564     else
00565     {
00566       // the object needs creating : here the question is whether an other
00567       // thread is creating it or not
00568       if( _creatingObject )
00569       {
00570         //other thread is creating the object : wait for it to finish creation
00571         _createdCondition.waitForChange( _dataLock ) ;
00572       }
00573       else 
00574       {
00575         //no thread is creating the object, 
00576         //therefore this thread takes responsability for creation
00577         _creatingObject = true ;
00578         _creatingThread = pthread_self() ;
00579         _dataLock.unprotect() ;
00580 
00581         //here, we can garantie that we are the only creating thread,
00582         //and that 
00583         // 1 - any recursive creation loop is a non-blocking creation
00584         // 2 - other threads creating the object are waiting on the condition
00585 
00586         //attempt object creation
00587         SimulatedObject *father( 0 ) ;
00588         const ObjectDescriptor *fathersDescription( _fathersDescription ) ;
00589 
00590         // as creation can happen during a paralel simulation,
00591         // it can happen at a time where getCurrentActiveObject returns the
00592         // object whose request triggered instance creation.
00593         // Therefore, the current active object is temporarly set to null,
00594         // so as to mimic creation phase.
00595         // If it is set to the controller, changing a controlparameter
00596         // triggers the sending of a valueEvent by the controller, which
00597         // might not have it's objectHandle initialized in order to avoid
00598         // being scheduled by itself
00599         CurrentActiveObject context( 0 ) ;
00600          
00601         while( fathersDescription != 0 )
00602         {
00603           father = fathersDescription->createDescribedObject() ;
00604           if( father != 0 )
00605           {
00606             OMTRACEID( OMK_DEBUG_OMK_OBJ,
00607                        "Creating object of type \"" << getClass() << "\"" ) ;
00608             SimulatedObject *result(
00609               SimulatedObjectFactory::getInstance().create( getClass() )(
00610                 father->getController() , *this ) ) ;
00611             OMTRACEID( OMK_DEBUG_OMK_OBJ,
00612                        "Creating object of type \"" << getClass() << "\" done" ) ;
00613 
00614             //result = father -> createInstanceOfEncapsulatedClass( *this );
00615             _dataLock.protect() ;
00616             _pointerToSimulatedObject = result ;
00617             _dataLock.unprotect() ;
00618             if( _pointerToSimulatedObject != 0 )
00619             {
00620               _destroySimulatedObject = true ;
00621               fathersDescription = 0 ;
00622             }
00623             else 
00624             {
00625               fathersDescription = fathersDescription->getFathersObjectDescriptor() ;
00626             }
00627           }
00628           else 
00629           {
00630             fathersDescription = 0 ;
00631           }
00632         }
00633       }
00634       if( _pointerToSimulatedObject == 0 )
00635       {
00636         OMTRACEID( OMK_DEBUG_OMK_OBJ,
00637                    "ObjectDescriptor::createDescribedObject: unable to create \""
00638                    << getName() << "\" of class " << getClass() ) ;
00639       }
00640       _dataLock.protect() ;
00641       _creatingObject = false ;
00642       _creatingThread = 0 ;
00643       _dataLock.unprotect() ;
00644       //wathever the result, unblock other waiting threads
00645       _createdCondition.signalChange() ;
00646     }
00647   }
00648   else
00649   {
00650     _dataLock.unprotect() ;
00651   }
00652   return result ;
00653 
00654 #else // _MSC_VER || ! _OMK_MUTEX_
00655   SimulatedObject *result( _pointerToSimulatedObject ) ;
00656   if( _pointerToSimulatedObject == 0 )
00657   {
00658     //no thread is creating the object, 
00659     _creatingObject = true ;
00660          
00661     //here, we can garantie that we are the only creating thread,
00662     //and that 
00663     // 1 - any recursive creation loop is a non-blocking creation
00664     // 2 - other threads creating the object are waiting on the condition
00665 
00666     //attempt object creation
00667     SimulatedObject *father( 0 ) ;
00668     const ObjectDescriptor *fathersDescription( _fathersDescription ) ;
00669          
00670     // as creation can happen during a paralel simulation, (not here : no multi
00671     // threading in MSC version) it can happen at a time where
00672     // getCurrentActiveObject returns the object whose request triggered
00673     // instance creation.
00674     // Therefore, the current active object is temporarly set to null, so as to
00675     // mimic creation phase. If it is set to the controller, changing a
00676     // controlparameter triggers the sending of a valueEvent by the controller,
00677     // which might not have it's objectHandle initialized in order to avoid
00678     // being scheduled by itself
00679     
00680     while( fathersDescription != 0 )
00681     {
00682       father = fathersDescription->createDescribedObject() ;
00683       if( father != 0 )
00684       {
00685         OMTRACEID( OMK_DEBUG_OMK_OBJ, "Creating object of type \""
00686                    << getClass() << "\"" ) ;
00687         result = OMK::SimulatedObjectFactory::getInstance().create(
00688           getClass() )( father->getController() , *this ) ;
00689         OMTRACEID( OMK_DEBUG_OMK_OBJ,
00690                    "Creating object of type \"" << getClass()
00691                    << "\" done " << result ) ;
00692         //result = father -> createInstanceOfEncapsulatedClass (*this);
00693         _pointerToSimulatedObject = result ;
00694         if( _pointerToSimulatedObject != 0 )
00695         {
00696           _destroySimulatedObject = true ;
00697           fathersDescription = 0 ;
00698         }
00699         else 
00700         {
00701           fathersDescription = fathersDescription->getFathersObjectDescriptor() ;
00702         }
00703       }
00704       else 
00705       {
00706         fathersDescription = 0 ;
00707       }
00708     }
00709   }
00710 
00711   if( _pointerToSimulatedObject == 0 )
00712   {
00713     OMTRACEID( OMK_DEBUG_OMK_OBJ,
00714                "ObjectDescriptor::createDescribedObject: unable to create \""
00715                << getName() << "\" of class " << getClass() ) ;
00716   }
00717   _creatingObject = false ;
00718 
00719   return result ;
00720 
00721 #endif // _MSC_VER
00722 }

void ObjectDescriptor::setFathersDescription ( ObjectDescriptor newFather  )  [protected, virtual]

Definition at line 520 of file OMKObjectDescriptor.cpp.

References _fathersDescription, addSon(), findDescendantNamed(), getName(), OMASSERT, OMK_DEBUG_OMK_OBJ, OMTRACEID, and removeSon().

Referenced by OMK::Controller::changeObjectsFather().

00521 {
00522   OMASSERT( newFather != 0 ) ;
00523   if( _fathersDescription != 0 )
00524   {
00525     _fathersDescription->removeSon( this ) ;
00526   }
00527 
00528   if( newFather->findDescendantNamed( getName() ) != 0 )
00529   {
00530     //cannot add the object : do nothing
00531     OMTRACEID( OMK_DEBUG_OMK_OBJ,
00532                "ObjectDescriptor::setFathersDescription of object named \""
00533                << getName()
00534                << "\" failed because descendant with the same name allready exists for object named \""
00535                << newFather->getName() << "\"" );
00536   }
00537   else 
00538   {
00539     newFather->addSon( this ) ;
00540   }
00541 }

void ObjectDescriptor::interpretSchedulingParameters ( MultipleConfigurationParameter schedulingParameters  )  [protected]

interpret a ConfigurationParameterDescriptor as the initial scheduling parameters non virtual because called by the constructor

Definition at line 457 of file OMKObjectDescriptor.cpp.

References _distribution, _frequency, _objectName, _originalFrequency, _originalSchedulingParameters, _processId, _schedulingParameters, OMK::MultipleConfigurationParameter::appendSubDescriptorNamed(), OMK::MultipleConfigurationParameter::clone(), DEFAULT_OBJECT, DUPLICATED_OBJECT, OMK::ConfigurationParameterDescriptor::getAssociatedString(), OMK::MultipleConfigurationParameter::getSubDescriptorByName(), LOCAL_OBJECT, OMK_DEBUG_PVM, and OMTRACEID.

Referenced by extract(), and ObjectDescriptor().

00459 {
00460   if( _schedulingParameters != schedulingParameters )
00461   {
00462     delete _schedulingParameters ;
00463   }
00464 
00465   _schedulingParameters = schedulingParameters ;    
00466   if( _schedulingParameters == 0 )
00467   {
00468     _schedulingParameters = new MultipleConfigurationParameter() ;
00469   } 
00470 
00471   const ConfigurationParameterDescriptor *description =
00472     _schedulingParameters->getSubDescriptorByName( "Frequency" ) ;
00473   if( description != 0 )
00474   {
00475     std::istringstream strValue( description->getAssociatedString() ) ;
00476     strValue >> _frequency ;
00477   }
00478   else
00479   {
00480     _frequency = 0 ;
00481     _schedulingParameters->appendSubDescriptorNamed(
00482       "Frequency",
00483       new UniqueConfigurationParameter( "0" ) ) ;
00484   }
00485 
00486   delete _originalSchedulingParameters ;
00487 
00488   _originalSchedulingParameters =
00489     static_cast< MultipleConfigurationParameter *>(
00490       _schedulingParameters->clone() ) ;
00491 
00492   _originalFrequency = _frequency ;
00493 
00494   description = _schedulingParameters->getSubDescriptorByName( "Process" ) ; 
00495   if( description != 0 )
00496   {
00497     _processId = description->getAssociatedString() ;
00498   }
00499   else
00500   {
00501     OMTRACEID( OMK_DEBUG_PVM, "No Process parameter for OSO" << _objectName );
00502   }
00503 
00504   _distribution = DEFAULT_OBJECT ;
00505   description = _schedulingParameters->getSubDescriptorByName( "Distribution" ) ;
00506   if( description != 0 )
00507   {
00508     std::string value( description->getAssociatedString() ) ;
00509     if( value == "Local" )
00510     {
00511       _distribution = LOCAL_OBJECT ;
00512     }
00513     else if( value == "Duplicated" )
00514     {
00515       _distribution = DUPLICATED_OBJECT ;
00516     }
00517   }
00518 }

virtual MultipleConfigurationParameter* OMK::ObjectDescriptor::getSchedulingParameters (  )  [inline, virtual]

get the configuration parameters of the controled object (non const version)

Definition at line 410 of file OMKObjectDescriptor.h.

00411    {
00412      return _schedulingParameters ;
00413    }

void ObjectDescriptor::printToStream ( std::ostream &  out,
int  currentOffset 
) const [protected, virtual]

pretty insert in a stream

Definition at line 340 of file OMKObjectDescriptor.cpp.

References _sonsContainer, getClass(), getConfigurationParameters(), getExtensionsParameters(), getName(), getSchedulingParameters(), OMK::printTabToStream(), OMK::ConfigurationParameterDescriptor::printToStream(), and OMK::MultipleConfigurationParameter::printToStream().

Referenced by insertInStream(), and pack().

00341 {
00342   //suppose any needed offset has allready been printed
00343   out << getName() << std::endl ;
00344   printTabToStream( out,offset + 2 ) ;
00345   out << "{" << std::endl ;
00346   printTabToStream( out, offset + 4 ) ;
00347   out << "Class " << getClass() << std::endl ;
00348   if( getSchedulingParameters() != 0 )
00349   {
00350     printTabToStream( out, offset + 4 ) ;
00351     out << "Scheduling " ;
00352     getSchedulingParameters()->printToStream( out, offset + 6 ) ;
00353     out << std::endl ;
00354   }
00355   if( getConfigurationParameters() != 0 )
00356   {
00357     printTabToStream( out, offset + 4 ) ;
00358     out << "UserParams " ;
00359     getConfigurationParameters()->printToStream( out, offset + 6 ) ;
00360     out << std::endl ;
00361   }
00362   if( getExtensionsParameters() != 0 )
00363   {
00364     printTabToStream( out, offset + 4 ) ;
00365     out << "Extensions " ;
00366     getExtensionsParameters()->printToStream( out, offset + 6 ) ;
00367     out << std::endl ;
00368   }
00369   if( _sonsContainer.size() != 0 )
00370   {
00371     printTabToStream( out, offset + 4 ) ;
00372     out << "Sons" << std::endl ;
00373     printTabToStream( out, offset + 6 ) ;
00374     out << "{" << std::endl ;
00375     for( SonsContainerType::const_iterator i = _sonsContainer.begin() ;
00376          i != _sonsContainer.end() ;
00377          ++i )
00378     {
00379       printTabToStream( out, offset + 8 ) ;
00380       ( *i )->printToStream( out, offset + 8 ) ;
00381     }
00382     printTabToStream( out, offset + 6 ) ;
00383     out << "}" << std::endl ; 
00384   }
00385   printTabToStream( out, offset + 2 ) ;
00386   out << "}" << std::endl ;
00387 }


Friends And Related Function Documentation

friend class Controller [friend]

make the controller a friend so that only controllers can ask for the creation of the described simulation object and change the father of an object

Definition at line 366 of file OMKObjectDescriptor.h.

friend class ObjectHandle [friend]

make the object handle a friend so that only controllers can change the boolean indicating delete responsability

Definition at line 371 of file OMKObjectDescriptor.h.

friend class SimulatedObject [friend]

make the simulated object friend so it can change the _pointerToSimulatedObject as early as possible

Definition at line 374 of file OMKObjectDescriptor.h.


Member Data Documentation

SimulatedObject* OMK::ObjectDescriptor::_pointerToSimulatedObject [mutable, protected]

if a simulated object corresponding to this descriptor has been created, a pointer to this object is memorised here.

destruction of this object is the responsability of the descriptor only if _destroySimulatedObject is true

Definition at line 394 of file OMKObjectDescriptor.h.

Referenced by OMK::Controller::Controller(), createDescribedObject(), deleteCachedData(), OMK::Controller::deleteObjectHandle(), ObjectDescriptor(), OMK::SimulatedObject::SimulatedObject(), ~ObjectDescriptor(), and OMK::SimulatedObject::~SimulatedObject().

bool OMK::ObjectDescriptor::_destroySimulatedObject [mutable, protected]

a pointer indicating if _pointerToSimulatedObject is deletable by this object

Definition at line 399 of file OMKObjectDescriptor.h.

Referenced by OMK::Controller::Controller(), createDescribedObject(), deleteCachedData(), ObjectDescriptor(), OMK::ObjectHandle::ObjectHandle(), and ~ObjectDescriptor().

Name OMK::ObjectDescriptor::_objectName [protected]

decribed object's name

Definition at line 417 of file OMKObjectDescriptor.h.

Referenced by extract(), and interpretSchedulingParameters().

Name OMK::ObjectDescriptor::_classId [protected]

decribed object's class

Definition at line 420 of file OMKObjectDescriptor.h.

Referenced by extract().

ConfigurationParameterDescriptor* OMK::ObjectDescriptor::_configurationParameters [protected]

described object's configuration parameters (isn't const to enable extraction

Definition at line 423 of file OMKObjectDescriptor.h.

Referenced by extract(), getConfigurationParameters(), ObjectDescriptor(), and ~ObjectDescriptor().

ConfigurationParameterDescriptor* OMK::ObjectDescriptor::_extensionsParameters [protected]

described object's extension parameters (isn't const to enable extraction

Definition at line 426 of file OMKObjectDescriptor.h.

Referenced by extract(), getExtensionsParameters(), ObjectDescriptor(), and ~ObjectDescriptor().

MultipleConfigurationParameter* OMK::ObjectDescriptor::_originalSchedulingParameters [protected]

described object's scheduling parameters

Definition at line 429 of file OMKObjectDescriptor.h.

Referenced by interpretSchedulingParameters(), ObjectDescriptor(), and ~ObjectDescriptor().

MultipleConfigurationParameter* OMK::ObjectDescriptor::_schedulingParameters [protected]

described object's scheduling parameters

Definition at line 432 of file OMKObjectDescriptor.h.

Referenced by interpretSchedulingParameters(), ObjectDescriptor(), setDistribution(), setFrequency(), setProcess(), and ~ObjectDescriptor().

ObjectDescriptor* OMK::ObjectDescriptor::_fathersDescription [protected]

a pointer to the objects father in the simulation tree

Definition at line 435 of file OMKObjectDescriptor.h.

Referenced by addSon(), createDescribedObject(), setFathersDescription(), and ~ObjectDescriptor().

SonsContainerType OMK::ObjectDescriptor::_sonsContainer [protected]

a container with all of the sons of an object.

Order of sons in the container should be conseidered meaningless

Definition at line 442 of file OMKObjectDescriptor.h.

Referenced by addSon(), extract(), findDescendantNamed(), getDescendants(), listDescendantsOfType(), listSonsOfType(), ObjectDescriptor(), printToStream(), removeSon(), and ~ObjectDescriptor().

bool OMK::ObjectDescriptor::_creatingObject [mutable, protected]

the boolean used to avoid recursive creation : should be accessed only protected

Definition at line 457 of file OMKObjectDescriptor.h.

Referenced by createDescribedObject().

pthread_t OMK::ObjectDescriptor::_creatingThread [mutable, protected]

the thread id of the creating lock

Definition at line 461 of file OMKObjectDescriptor.h.

Referenced by createDescribedObject().

Name OMK::ObjectDescriptor::_processId [private]

decribed object's current process (stored to avoid reinterpreting the scheduling parameters)

Definition at line 466 of file OMKObjectDescriptor.h.

Referenced by interpretSchedulingParameters(), and setProcess().

Frequency OMK::ObjectDescriptor::_frequency [private]

decribed object's current frequency (stored to avoid reinterpreting the scheduling parameters)

Definition at line 469 of file OMKObjectDescriptor.h.

Referenced by interpretSchedulingParameters(), and setFrequency().

Distribution OMK::ObjectDescriptor::_distribution [private]

decribed object's current distribution (stored to avoid reinterpreting the scheduling parameters)

Definition at line 472 of file OMKObjectDescriptor.h.

Referenced by interpretSchedulingParameters(), and setDistribution().

Frequency OMK::ObjectDescriptor::_originalFrequency [private]

decribed object's current frequency (stored to avoid reinterpreting the scheduling parameters)

Definition at line 475 of file OMKObjectDescriptor.h.

Referenced by interpretSchedulingParameters().


logo OpenMask

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

Generated with doxygen by Dimitri van Heesch ,   1997-2007