OMK::PvmMirrorObjectHandle Class Reference

defines an object handle for mirors (ghosts) of reference objects only for pvm More...

#include <OMKPvmMirrorObjectHandle.h>

Inheritance diagram for OMK::PvmMirrorObjectHandle:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

 PvmMirrorObjectHandle (SimulatedObject &objetSimul)
 constructor
virtual ~PvmMirrorObjectHandle ()
 destructor
virtual void linkToNewReferential (Name newProcessName)
 CHADI.
virtual void setMorphosisPhaseTrue ()
virtual void registerToReferenceObject (bool needValues)
 Register the mirror to the reference object for regular updates of outputs.
virtual void cancelRegistrationToReferenceObject ()
 cancel registration of the mirror object to the reference object
virtual void insertInStream (std::ostream &=std::cout) const
 should be obsoleted
virtual void extract (std::istream &=std::cin)
 should be obsoleted
virtual void unpack (IncomingSynchronisationMessage &in)
 unpack update information packed in the incoming message by the reference object
virtual void receiveEvent (const Event &event)
 implement receive event so that the event is transfered to the reference object
virtual void receiveEvent (Event *event)
 implement receive event so that the event is transfered to the reference object
virtual void sendEventsForSignal (Event &event, const EventIdentifier &sigId)
 send events for a signal emitted by the reference object.
virtual bool receiveRegistrationForSignal (const EventIdentifier &sigId, const Name &registrant, const EventIdentifier &eventId)
 receive the registration for signal sigId by registrant, and forward it to the reference object.
virtual bool cancelRegistrationForSignal (const EventIdentifier &sigId, const Name &registrant)
 cancel the registration made by registrant for sigId

Protected Member Functions

virtual void attributeRead ()
 called when an attribute is read
virtual void sendRequestToReferenceObject (RequestType typeMess)
 send a request or an event to the reference object

Detailed Description

defines an object handle for mirors (ghosts) of reference objects only for pvm

Author:
Siames
Version:
1.1

Definition at line 39 of file OMKPvmMirrorObjectHandle.h.


Constructor & Destructor Documentation

PvmMirrorObjectHandle::PvmMirrorObjectHandle ( SimulatedObject objetSimul  ) 

constructor

Definition at line 37 of file OMKPvmMirrorObjectHandle.cxx.

References OMK::MirrorObjectHandle::_linkToReferencesProcess, OMK::SimulatedObject::getController(), OMK::SimulatedObject::getObjectDescriptor(), OMK::ObjectDescriptor::getProcess(), and OMK::ObjectHandle::getSimulatedObject().

00037                                                                           : 
00038    MirrorObjectHandle (objetSimul)
00039 {
00040   Name processOfReferenceObject = 
00041     getSimulatedObject().getObjectDescriptor ().getProcess () ;
00042   
00043   _linkToReferencesProcess = 
00044     dynamic_cast<PvmController &>(getSimulatedObject().getController()).
00045     getDistributedVirtualMachine()->
00046     getLinkToProcessNamed (processOfReferenceObject) ;
00047 
00048   assert ( _linkToReferencesProcess != NULL ) ;
00049 }

PvmMirrorObjectHandle::~PvmMirrorObjectHandle (  )  [virtual]

destructor

Definition at line 53 of file OMKPvmMirrorObjectHandle.cxx.

00053                                                {
00054 
00055 }


Member Function Documentation

void PvmMirrorObjectHandle::linkToNewReferential ( Name  newProcessName  )  [virtual]

CHADI.

Implements OMK::MirrorObjectHandle.

Definition at line 268 of file OMKPvmMirrorObjectHandle.cxx.

References OMK::MirrorObjectHandle::_linkToReferencesProcess, OMK::SimulatedObject::getController(), OMK::ObjectHandle::getSimulatedObject(), and registerToReferenceObject().

00269 {
00270 //          struct timeval local_start_timer,local_end_timer ;
00271 //          double time_in_ms;
00272 
00273 //       gettimeofday (&local_start_timer, NULL) ;
00274 
00275   _linkToReferencesProcess = dynamic_cast<PvmController &>(getSimulatedObject().getController()).getDistributedVirtualMachine()->getLinkToProcessNamed (newProcessName) ;
00276 
00277 //       gettimeofday (&local_end_timer, NULL) ;
00278 //       time_in_ms = (local_end_timer.tv_sec - local_start_timer.tv_sec) * 1000.0 +
00279 //       (local_end_timer.tv_usec - local_start_timer.tv_usec) / 1000.0 ;
00280 //       std::cout << "partial duration 6 = " << time_in_ms << std::endl ;
00281 //       gettimeofday (&local_start_timer, NULL) ;
00282 
00283   assert ( _linkToReferencesProcess != NULL ) ;
00284 // TDTD pour shunter PVM en cas de migration
00285   registerToReferenceObject (false) ;
00286 
00287 //       gettimeofday (&local_end_timer, NULL) ;
00288 //       time_in_ms = (local_end_timer.tv_sec - local_start_timer.tv_sec) * 1000.0 +
00289 //       (local_end_timer.tv_usec - local_start_timer.tv_usec) / 1000.0 ;
00290 //       std::cout << "partial duration 7 = " << time_in_ms << std::endl ;
00291 }

void PvmMirrorObjectHandle::setMorphosisPhaseTrue (  )  [virtual]

Implements OMK::MirrorObjectHandle.

Definition at line 293 of file OMKPvmMirrorObjectHandle.cxx.

References OMK::ObjectHandle::_migrationCase, and OMK::MirrorObjectHandle::morphosisPhase.

00294 {
00295   morphosisPhase = true ;
00296   _migrationCase = true ;
00297 }

void PvmMirrorObjectHandle::registerToReferenceObject ( bool  needValues  )  [virtual]

Register the mirror to the reference object for regular updates of outputs.

Implements OMK::MirrorObjectHandle.

Definition at line 76 of file OMKPvmMirrorObjectHandle.cxx.

References OMK::MirrorObjectHandle::_linkToReferencesProcess, OMK::ObjectHandle::_myObject, OMK::MirrorObjectHandle::_registered, OMK::SimulatedObject::getController(), OMK::SimulatedObject::getName(), OMK::PvmController::getProcessName(), OMK::ObjectHandle::getSimulatedObject(), OMK::SvmLink::getTID(), OMK::PvmMessage::InitialValuesForMirror, OMK::PvmOutgoingMessage::insertTimeStamp(), OMK::PvmMessage::MirrorNeedsInitialValues, OMK::Name::pack(), OMK::Registration, OMK::PvmUnicastMessage::send(), sendRequestToReferenceObject(), and OMK::PvmController::waitForAnswerToBlockingRequest().

Referenced by attributeRead(), and linkToNewReferential().

00077 {
00078    // should only be called once by the creator of the mirror 
00079    assert ( _registered == false ) ;
00080 #ifdef _DEBUGPVMSYNCHRO
00081    cerr << "PvmMirrorObjectHandle::registerToReferenceObject: mirror registering to referential" << endl ;
00082 #endif
00083    sendRequestToReferenceObject (Registration) ;
00084    _registered = true ;
00085 
00086    // until SGI Perfomer becomes compatible with exception handling, request initial values from the referential immediatly, and wait for answer
00087    PvmUnicastMessage * urgentRequest = new PvmUnicastMessage ( _linkToReferencesProcess->getTID() ) ;
00088 
00089    urgentRequest->insertTimeStamp( getSimulatedObject().getController().getSimulatedDate() ) ;
00090 
00091    getSimulatedObject().getName().pack ( *urgentRequest ) ;
00092 
00093    PvmController &  realController = dynamic_cast<PvmController & > ( _myObject.getController() ) ;
00094 
00095    realController.getProcessName ().pack ( *urgentRequest ) ;
00096 
00097    urgentRequest->send ( PvmMessage::MirrorNeedsInitialValues ) ;
00098 
00099 //          struct timeval local_start_timer,local_end_timer ;
00100 //          double time_in_ms;
00101 //       gettimeofday (&local_start_timer, NULL) ;
00102 
00103       if (needValues) {
00104          realController.waitForAnswerToBlockingRequest(PvmMessage::InitialValuesForMirror) ;
00105       }
00106 //       gettimeofday (&local_end_timer, NULL) ;
00107 //       time_in_ms = (local_end_timer.tv_sec - local_start_timer.tv_sec) * 1000.0 +
00108 //       (local_end_timer.tv_usec - local_start_timer.tv_usec) / 1000.0 ;
00109 //       std::cout << "partial duration 8 = " << time_in_ms << std::endl ;
00110 
00111 }

void PvmMirrorObjectHandle::cancelRegistrationToReferenceObject (  )  [virtual]

cancel registration of the mirror object to the reference object

Implements OMK::MirrorObjectHandle.

Definition at line 115 of file OMKPvmMirrorObjectHandle.cxx.

References OMK::MirrorObjectHandle::_registered, OMK::CancelRegistration, and sendRequestToReferenceObject().

Referenced by unpack().

00116 {
00117 #ifdef _DEBUGPVMSYNCHRO
00118    cout << "PvmMirrorObjectHandle::cancelRegistrationToReferenceObject" << endl ;
00119 #endif
00120    sendRequestToReferenceObject (CancelRegistration) ;
00121    _registered = false ;
00122 }

void PvmMirrorObjectHandle::insertInStream ( std::ostream &  = std::cout  )  const [virtual]

should be obsoleted

Implements OMK::MirrorObjectHandle.

Definition at line 126 of file OMKPvmMirrorObjectHandle.cxx.

00126                                                                {
00127    out << "PvmMirrorObjectHandle::insertInStream nothing to insert" << endl ;
00128 }

void PvmMirrorObjectHandle::extract ( std::istream &  = std::cin  )  [virtual]

should be obsoleted

Reimplemented from OMK::MirrorObjectHandle.

Definition at line 173 of file OMKPvmMirrorObjectHandle.cxx.

00174 {
00175    assert (false) ; //use of extract deprecated
00176 }

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

unpack update information packed in the incoming message by the reference object

Implements OMK::MirrorObjectHandle.

Definition at line 131 of file OMKPvmMirrorObjectHandle.cxx.

References OMK::MirrorObjectHandle::_dateOfLastUse, OMK::ObjectHandle::_myObject, cancelRegistrationToReferenceObject(), OMK::ObjectHandle::getAttributeRead(), OMK::SimulatedObject::getController(), OMK::Controller::getCyclePeriod(), OMK::SimulatedObject::getName(), OMK::Controller::getSimulatedDate(), OMK::InitialValuesMessage, OMK::SimulatedObject::unpack(), and OMK::SimulatedObject::unpackAllValues().

00132 {
00133    RequestType typeMess ;
00134    int messageType ;
00135 
00136    //make sure the mirror is still needed
00137    if ( getAttributeRead() )
00138       {
00139          _dateOfLastUse = _myObject.getController().getSimulatedDate() ;
00140       }
00141    else
00142       {
00143          if ( _myObject.getController().getSimulatedDate() > _dateOfLastUse + 2 * _myObject.getController().getCyclePeriod() ) 
00144             { 
00145                cancelRegistrationToReferenceObject () ;
00146             }
00147       }
00148 
00149    in >> messageType ;
00150    typeMess = static_cast <RequestType> (messageType) ;
00151 
00152    switch ( typeMess )
00153       {
00154       case SynchronisationMessage:
00155          {
00156             _myObject.unpack ( in ) ;
00157          }
00158          break;
00159       case InitialValuesMessage:
00160          {
00161             _myObject.unpackAllValues ( in ) ;
00162          }
00163          break;
00164       default:
00165          cerr<<"PvmMirrorObjectHandle::unpack: " << _myObject.getName ()
00166              << " WARNING: uninterpreted message of type "<< typeMess << endl;
00167          break;
00168       }
00169 }

void PvmMirrorObjectHandle::receiveEvent ( const Event event  )  [virtual]

implement receive event so that the event is transfered to the reference object

Implements OMK::MirrorObjectHandle.

Definition at line 179 of file OMKPvmMirrorObjectHandle.cxx.

References OMK::MirrorObjectHandle::_linkToReferencesProcess, OMK::EventReceived, OMK::ObjectDescriptor::getName(), OMK::SimulatedObject::getObjectDescriptor(), OMK::SvmLink::getOutgoingBuffer(), and OMK::ObjectHandle::getSimulatedObject().

00180 {
00181 #ifdef _DEBUGPVMMESS
00182    cerr<<"PvmMirrorObjectHandle::receiveEvent (const Event & event) "<<endl;
00183 #endif
00184    _linkToReferencesProcess->getOutgoingBuffer () << getSimulatedObject().getObjectDescriptor ().getName ()
00185                                                   << EventReceived
00186                                                   << event ;
00187 }

void PvmMirrorObjectHandle::receiveEvent ( Event event  )  [virtual]

implement receive event so that the event is transfered to the reference object

Implements OMK::MirrorObjectHandle.

Definition at line 191 of file OMKPvmMirrorObjectHandle.cxx.

References OMK::MirrorObjectHandle::_linkToReferencesProcess, OMK::EventReceived, OMK::ObjectDescriptor::getName(), OMK::SimulatedObject::getObjectDescriptor(), OMK::SvmLink::getOutgoingBuffer(), and OMK::ObjectHandle::getSimulatedObject().

00192 {
00193 #ifdef _DEBUGPVMMESS
00194    cerr<<"PvmMirrorObjectHandle::receiveEvent (Event * event) "<<endl;
00195 #endif
00196 
00197    _linkToReferencesProcess->getOutgoingBuffer () << getSimulatedObject().getObjectDescriptor ().getName () 
00198                                                   << EventReceived
00199                                                   << *event ;
00200 
00201    delete event ;
00202 }

void PvmMirrorObjectHandle::sendEventsForSignal ( Event event,
const EventIdentifier sigId 
) [virtual]

send events for a signal emitted by the reference object.

shouldn't be called, because registration for signals are forwarded to the reference object wich fires them and sends the corresponding event to a miror of the registrant. This algorithm could be re-written to send the signam to the miror which would then fire the signals locally.

Implements OMK::MirrorObjectHandle.

Definition at line 232 of file OMKPvmMirrorObjectHandle.cxx.

00233 {
00234    assert ( false ) ;
00235 }

bool PvmMirrorObjectHandle::receiveRegistrationForSignal ( const EventIdentifier sigId,
const Name registrant,
const EventIdentifier eventId 
) [virtual]

receive the registration for signal sigId by registrant, and forward it to the reference object.

Parameters:
eventId the eventId of the event sent to registrant when sigId is fired
Returns:
registration was successful

Implements OMK::MirrorObjectHandle.

Definition at line 207 of file OMKPvmMirrorObjectHandle.cxx.

References OMK::MirrorObjectHandle::_linkToReferencesProcess, OMK::ObjectDescriptor::getName(), OMK::SimulatedObject::getObjectDescriptor(), OMK::SvmLink::getOutgoingBuffer(), OMK::ObjectHandle::getSimulatedObject(), OMTRACEID, and OMK::RegisterForSignal.

00210 {
00211   OMTRACEID("DEBUGPVM", "Register : " << sigId << " " << " Name : "<< registrant <<" Ev : "<<  eventId );
00212 
00213    _linkToReferencesProcess->getOutgoingBuffer ()<< getSimulatedObject().getObjectDescriptor().getName () 
00214                                                  << (int) RegisterForSignal 
00215                                                  << sigId 
00216                                                  << registrant 
00217                                                  << eventId ;
00218    return true;
00219 }

bool PvmMirrorObjectHandle::cancelRegistrationForSignal ( const EventIdentifier sigId,
const Name registrant 
) [virtual]

cancel the registration made by registrant for sigId

Returns:
cancellation was successful

Implements OMK::MirrorObjectHandle.

Definition at line 221 of file OMKPvmMirrorObjectHandle.cxx.

References OMK::MirrorObjectHandle::_linkToReferencesProcess, OMK::CancelRegistrationForSignal, OMK::ObjectDescriptor::getName(), OMK::SimulatedObject::getObjectDescriptor(), OMK::SvmLink::getOutgoingBuffer(), OMK::ObjectHandle::getSimulatedObject(), and OMTRACEID.

00223 {
00224   OMTRACEID("DEBUGPVM", "UN!!!Register : " << sigId << " Reg : "<< registrant );
00225   _linkToReferencesProcess->getOutgoingBuffer() << getSimulatedObject().getObjectDescriptor().getName ()
00226                                                 << (int) CancelRegistrationForSignal  
00227                                                 << sigId 
00228                                                 << registrant ;
00229   return true  ;
00230 }

void PvmMirrorObjectHandle::attributeRead (  )  [protected, virtual]

called when an attribute is read

CHADI

CHADI

Implements OMK::MirrorObjectHandle.

Definition at line 57 of file OMKPvmMirrorObjectHandle.cxx.

References OMK::MirrorObjectHandle::_registered, OMK::ObjectHandle::attributeRead(), OMK::MirrorObjectHandle::morphosisPhase, and registerToReferenceObject().

00058 {
00059    ObjectHandle::attributeRead() ;
00060    if ( ! _registered )
00061       {
00062         //cerr<<"MirrorObjectHandle::attributeRead : new registration needed"<<endl;
00064         if ( !morphosisPhase )
00065           {
00066             registerToReferenceObject (true) ;
00067           }
00069         //registerToReferenceObject () ;
00070       }
00071 }

void PvmMirrorObjectHandle::sendRequestToReferenceObject ( RequestType  typeMess  )  [protected, virtual]

send a request or an event to the reference object

Implements OMK::MirrorObjectHandle.

Definition at line 237 of file OMKPvmMirrorObjectHandle.cxx.

References OMK::MirrorObjectHandle::_linkToReferencesProcess, OMK::ObjectHandle::_myObject, OMK::CancelRegistration, OMK::SimulatedObject::getController(), OMK::SimulatedObject::getName(), OMK::SimulatedObject::getObjectDescriptor(), OMK::SvmLink::getOutgoingBuffer(), OMK::SimulatedObject::getPeriod(), OMK::ObjectDescriptor::getProcess(), OMK::Controller::getSimulatedDate(), and OMK::PvmOutgoingMessage::insertTimeStamp().

Referenced by cancelRegistrationToReferenceObject(), and registerToReferenceObject().

00238 {
00239    PvmOutgoingMessage * sendBuffer = & _linkToReferencesProcess->getOutgoingBuffer () ;
00240 
00241    // as no garanty can be made on the validity of the buffer, timestamp it
00242    if ( typeMess == CancelRegistration )
00243       {
00244          sendBuffer->insertTimeStamp ( OMK::Date(_myObject.getController().getSimulatedDate() + _myObject.getController().getPeriod()*1000) ) ;
00245       }
00246    // send the name of the object
00247    *sendBuffer << _myObject.getName ()  ;
00248    
00249    // send the request
00250    *sendBuffer << (int)typeMess ;
00251    
00252 #ifdef _DEBGUPVMMESS
00253    std::cerr<<"PvmMirrorObjectHandle::sendRequestToReferenceObject adding "
00254             <<_myObject.getController ().getObjectDescriptor().getProcess ()
00255             <<" to the synchronisation message for object "
00256             <<_myObject.getName()
00257             <<std::endl;
00258 #endif
00259    // send the requesting process
00260    *sendBuffer << _myObject.getController ().getObjectDescriptor().getProcess () ;
00261 }


logo OpenMask

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

Generated with doxygen by Dimitri van Heesch ,   1997-2007