OMKPvmDuplicatedObjectHandle.cxx

Go to the documentation of this file.
00001 #include "OMKPvmDuplicatedObjectHandle.h"
00002 
00003 #include "OMKController.h"
00004 #include "OMKProcess.h"
00005 #include "OMKSimulatedObject.h"
00006 #include "OMKSvmLink.h"
00007 
00008 #ifdef _DEBUGPVMMESS
00009 #include <iostream>
00010 #endif
00011 using namespace OMK ;
00012 
00013 PvmDuplicatedObjectHandle::PvmDuplicatedObjectHandle ( SimulatedObject & obj, Controller & ctrl ) :
00014    DuplicatedObjectHandle ( obj, ctrl )
00015 {
00016 }
00017 
00018 PvmDuplicatedObjectHandle::~PvmDuplicatedObjectHandle ()
00019 {
00020 }
00021 
00022 void PvmDuplicatedObjectHandle::broadcastEvent ( const Event & event )
00023 {
00024   //send the event to all copies of oneself
00025   for (std::list<const Process *>::const_iterator i = _processesOfDuplicates.begin() ;
00026        i != _processesOfDuplicates.end () ;
00027        ++i) 
00028     {
00029       if (getSimulatedObject().getController().getObjectDescriptor().getProcess() != (*i)->getProcessName() )
00030         {
00031 #ifdef _DEBUGPVMMESS
00032           std::cerr<<"PvmDuplicatedObjectHandle::broadcastEvent"<<std::endl;
00033 #endif
00034           if ( ! (*i)->getSvmLink ()->getOutgoingBuffer().isTimeStamped() )
00035             {
00036               (*i)->getSvmLink ()->getOutgoingBuffer().
00037                 insertTimeStamp ( getSimulatedObject().getController().getSimulatedDate() ) ;
00038              }
00039           (*i)->getSvmLink ()->getOutgoingBuffer()<< getSimulatedObject().getName ()
00040                                                   << EventReceived
00041                                                   << event  ;
00042         }
00043      }
00044   //receive the event oneself
00045   ReferenceObjectHandle::receiveEvent ( event.clone() ) ;
00046 }
00047 
00048 
00049 
00050 void PvmDuplicatedObjectHandle::unpack (IncomingSynchronisationMessage & in) 
00051 {
00052    RequestType typeMess ;
00053    int messageType ;
00054 
00055    in >> messageType ;
00056    typeMess = static_cast <RequestType> (messageType) ;
00057 
00058    if ( typeMess == EventReceived )
00059       {
00060          Event * event ;
00061          Name classToCreate ;
00062          EventIdentifier eventId;
00063          Date eventDate;
00064          Name sender, receiver ;
00065          in >> classToCreate >> eventId>> eventDate>>sender>>receiver ;
00066          event = EventCreator::createEvent (classToCreate, eventId, eventDate, sender, receiver ) ;
00067          event->unpack ( in ) ;
00068          ReferenceObjectHandle::receiveEvent ( event ) ;
00069       }
00070 }
00071 
00072 
00073 
00074 void PvmDuplicatedObjectHandle::addProcessOfDuplicate ( const Process * process ) 
00075 {
00076    _processesOfDuplicates.push_back( process ) ;
00077 }

logo OpenMask

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

Generated with doxygen by Dimitri van Heesch ,   1997-2007