Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

PsnMirrorObjectHandle.cxx

Go to the documentation of this file.
00001 /*
00002  * This file is part of openMask © INRIA, CNRS, Universite de Rennes 1 1993-2002, thereinafter the Software
00003  * 
00004  * The Software has been developped within the Siames Project. 
00005  * INRIA, the University of Rennes 1 and CNRS jointly hold intellectual property rights
00006  * 
00007  * The Software has been registered with the Agence pour la Protection des
00008  * Programmes (APP) under registration number IDDN.FR.001.510008.00.S.P.2001.000.41200
00009  *  
00010  * This file may be distributed under the terms of the Q Public License
00011  * version 1.0 as defined by Trolltech AS of Norway and appearing in the file
00012  * LICENSE.QPL included in the packaging of this file.
00013  *
00014  * Licensees holding valid specific licenses issued by INRIA, CNRS or Université de Rennes 1 
00015  * for the software may use this file in accordance with that specific license
00016  *
00017  */
00018 #include <PsnMirrorObjectHandle.h>
00019 #include <PsSimulatedObject.h>
00020 #include <PsPvmController.h>
00021 #include <PsnPvmSvmLink.h>
00022 #include <PsnPvmMessage.h>
00023 #include "PsEvent.h"
00024 #include "PsObjectDescriptor.h"
00025 #include "PsnSvm.h"
00026 //-----------------------------------------------------------------------------
00027 //recevoir la liste des outputs exportables
00028 
00029 PsnMirrorObjectHandle::PsnMirrorObjectHandle (PsSimulatedObject & objetSimul) : 
00030    PsnObjectHandle (objetSimul),
00031    _dateOfLastUse ( objetSimul.getController().getSimulatedDate() ),
00032    _registered ( false )
00033 {
00034    PsName processOfReferenceObject = getSimulatedObject().getObjectDescriptor ().getProcess () ;
00035    
00036    _linkToReferencesProcess = dynamic_cast<PsPvmController &>(getSimulatedObject().getController()).getDistributedVirtualMachine()->getLinkToProcessNamed (processOfReferenceObject) ;
00037 
00038   assert ( _linkToReferencesProcess != NULL ) ;
00039 }
00040 
00041 //-----------------------------------------------------------------------------
00042 
00043 PsnMirrorObjectHandle::~PsnMirrorObjectHandle () {
00044 
00045 }
00046 
00047 void PsnMirrorObjectHandle::attributeRead () 
00048 {
00049    PsnObjectHandle::attributeRead() ;
00050    if ( ! _registered )
00051       {
00052          //cerr<<"PsnMirrorObjectHandle::attributeRead : new registration needed"<<endl;
00053          registerToReferenceObject () ;
00054       }
00055 }
00056 
00057 //-----------------------------------------------------------------------------
00058 // s'abonner Flot de Donnees aupres du referentiel
00059 
00060 void PsnMirrorObjectHandle::registerToReferenceObject () 
00061 {
00062    // should only be called once by the creator of the mirror 
00063    assert ( _registered == false ) ;
00064 #ifdef _DEBUGPVMSYNCHRO
00065    cerr << "PsnMirrorObjectHandle::registerToReferenceObject: mirror registering to referential" << endl ;
00066 #endif
00067    sendRequestToReferenceObject (Registration) ;
00068    _registered = true ;
00069 
00070    // until SGI Perfomer becomes compatible with exception handling, request initial values from the referential immediatly, and wait for answer
00071    PsnPvmUnicastMessage * urgentRequest = new PsnPvmUnicastMessage ( _linkToReferencesProcess->getTID() ) ;
00072 
00073    urgentRequest->insertTimeStamp( getSimulatedObject().getController().getSimulatedDate() ) ;
00074 
00075    getSimulatedObject().getName().pack ( *urgentRequest ) ;
00076 
00077    PsPvmController &  realController = dynamic_cast<PsPvmController & > ( _myObject.getController() ) ;
00078 
00079    realController.getProcessName ().pack ( *urgentRequest ) ;
00080 
00081    urgentRequest->send ( PsnPvmMessage::MirrorNeedsInitialValues ) ;
00082 
00083    realController.waitForAnswerToBlockingRequest(PsnPvmMessage::InitialValuesForMirror) ;
00084 }
00085 
00086 //-----------------------------------------------------------------------------
00087 
00088 void  PsnMirrorObjectHandle::cancelRegistrationToReferenceObject () 
00089 {
00090 #ifdef _DEBUGPVMSYNCHRO
00091    cout << "PsnMirrorObjectHandle::cancelRegistrationToReferenceObject" << endl ;
00092 #endif
00093    sendRequestToReferenceObject (CancelRegistration) ;
00094    _registered = false ;
00095 }
00096 
00097 //-----------------------------------------------------------------------------
00098 
00099 void PsnMirrorObjectHandle::insertInStream (ostream & out) const {
00100    out << "PsnMirrorObjectHandle::insertInStream nothing to insert" << endl ;
00101 }
00102 
00103 //-----------------------------------------------------------------------------
00104 void PsnMirrorObjectHandle::unpack (PsIncomingSynchronisationMessage & in) 
00105 {
00106    PsnRequestType typeMess ;
00107    int messageType ;
00108 
00109    //make sure the mirror is still needed
00110    if ( getAttributeRead() )
00111       {
00112          _dateOfLastUse = _myObject.getController().getSimulatedDate() ;
00113       }
00114    else
00115       {
00116          if ( _myObject.getController().getSimulatedDate() > _dateOfLastUse + 2 * _myObject.getController().getCyclePeriod() ) 
00117             { 
00118                cancelRegistrationToReferenceObject () ;
00119             }
00120       }
00121 
00122    in >> messageType ;
00123    typeMess = static_cast <PsnRequestType> (messageType) ;
00124 
00125    switch ( typeMess )
00126       {
00127       case SynchronisationMessage:
00128          {
00129             _myObject.unpack ( in ) ;
00130          }
00131          break;
00132       case InitialValuesMessage:
00133          {
00134             _myObject.unpackAllValues ( in ) ;
00135          }
00136          break;
00137       default:
00138          cerr<<"PsnMirrorObjectHandle::unpack: WARNING: uninterpreted message"<<endl;
00139          break;
00140       }
00141 }
00142 
00143 
00144 
00145 void PsnMirrorObjectHandle::extract (istream & in) 
00146 {
00147    assert (false) ; //use of extract deprecated
00148 }
00149 
00150 //-----------------------------------------------------------------------------
00151 void PsnMirrorObjectHandle::receiveEvent (const PsEvent & event) 
00152 {
00153 #ifdef _DEBUGPVMMESS
00154    cerr<<"PsnMirrorObjectHandle::receiveEvent (const PsEvent & event) "<<endl;
00155 #endif
00156    _linkToReferencesProcess->getOutgoingBuffer () << getSimulatedObject().getObjectDescriptor ().getName ()
00157                                                   << EventReceived
00158                                                   << event ;
00159 }
00160 
00161 
00162 
00163 void PsnMirrorObjectHandle::receiveEvent (PsEvent * event) 
00164 {
00165 #ifdef _DEBUGPVMMESS
00166    cerr<<"PsnMirrorObjectHandle::receiveEvent (PsEvent * event) "<<endl;
00167 #endif
00168 
00169    _linkToReferencesProcess->getOutgoingBuffer () << getSimulatedObject().getObjectDescriptor ().getName () 
00170                                                   << EventReceived
00171                                                   << *event ;
00172 
00173    delete event ;
00174 }
00175 
00176 
00177 //-----------------------------------------------------------------------------
00178 
00179 bool PsnMirrorObjectHandle::receiveRegistrationForSignal ( const PsEventIdentifier & sigId,
00180                                                            const PsName & registrant, 
00181                                                            const PsEventIdentifier & eventId )
00182 {
00183 
00184    _linkToReferencesProcess->getOutgoingBuffer ()<< getSimulatedObject().getObjectDescriptor().getName () 
00185                                                  << PsString ("EV") 
00186                                                  << (int) RegisterForSignal 
00187                                                  << sigId 
00188                                                  << registrant 
00189                                                  << eventId ;
00190    return true;
00191 }
00192    
00193 bool PsnMirrorObjectHandle::cancelRegistrationForSignal( const PsEventIdentifier & sigId , 
00194                                                          const PsName & registrant ) 
00195 {
00196    _linkToReferencesProcess->getOutgoingBuffer () << getSimulatedObject().getObjectDescriptor().getName () << " "
00197                                                   << PsString ("EV") 
00198                                                   << (int) CancelRegistrationForSignal  
00199                                                   << sigId 
00200                                                   << registrant ;
00201    return true  ;
00202 }
00203 
00204 void PsnMirrorObjectHandle::sendEventsForSignal( PsEvent & event , const PsEventIdentifier & sigId ) 
00205 {
00206    assert ( false ) ;
00207 }
00208 
00209 void PsnMirrorObjectHandle::sendRequestToReferenceObject (PsnRequestType typeMess) 
00210 {
00211    //cerr<<"PsnMirrorObjectHandle::sendRequestToReferenceObject("<<typeMess<<")"<<endl;
00212    PsnPvmOutgoingMessage * sendBuffer = & _linkToReferencesProcess->getOutgoingBuffer () ;
00213 
00214    // as no garanty can be made on the validity of the buffer, timestamp it
00215    if ( typeMess == CancelRegistration )
00216       {
00217          sendBuffer->insertTimeStamp ( _myObject.getController().getSimulatedDate() + _myObject.getController().getPeriod()*1000 ) ;
00218       }
00219    // send the name of the object
00220    *sendBuffer << _myObject.getName ()  ;
00221    
00222    // send the request
00223    *sendBuffer << (int)typeMess ;
00224    
00225 #ifdef _DEBGUPVMMESS
00226    cerr<<"PsnMirrorObjectHandle::sendRequestToReferenceObject adding "<<_myObject.getController ().getObjectDescriptor().getProcess ()<<" to the synchronisation message for object "<<_myObject.getName()<<endl;
00227 #endif
00228    // send the requesting process
00229    *sendBuffer << _myObject.getController ().getObjectDescriptor().getProcess () ;
00230 }
00231 
00232 
00233 
00234 
00235 
00236 
00237 
00238 
00239 
00240 
00241 

logo OpenMask

Documentation generated on Mon Nov 25 15:25:00 2002

Generated with doxygen 1.2.12 by Dimitri van Heesch ,   1997-2001