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

PsnPvmReferenceObjectHandle.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 <PsnPvmReferenceObjectHandle.h>
00019 #include <PsSimulatedObject.h>
00020 #include <PsnPvmMessage.h>
00021 #include <PsObjectDescriptor.h>
00022 #include <PsnSvmLink.h>
00023 #include <PsnProcess.h>
00024 #include <PsController.h>
00025 #ifdef _PVM
00026 #include <PsPvmController.h>
00027 #endif
00028 #include "PsnSvm.h"
00029 #include <typeinfo>
00030 #include "PsEventListener.h"
00031 #include "PsIncomingSynchronisationMessage.h"
00032 //-----------------------------------------------------------------------------
00033 
00034 PsnPvmReferenceObjectHandle::PsnPvmReferenceObjectHandle (PsSimulatedObject & object, 
00035                                                           PsController & controller)
00036    : PsnReferenceObjectHandle ( object, controller)
00037 {
00038 }
00039 
00040 PsnPvmReferenceObjectHandle::PsnPvmReferenceObjectHandle (PsSimulatedObject & object, 
00041                                                           PsController & controller, 
00042                                                           PsnSignalDispatcher * signalDispatcher)
00043    : PsnReferenceObjectHandle ( object, controller, signalDispatcher)
00044 {
00045 }
00046 
00047 //-----------------------------------------------------------------------------
00048 
00049 PsnPvmReferenceObjectHandle::~PsnPvmReferenceObjectHandle () 
00050 {
00051 }
00052 
00053 
00054 //-----------------------------------------------------------------------------
00055 
00056 void PsnPvmReferenceObjectHandle::emettreValAttributs (PsnPvmOutgoingMessage *messFD,
00057                                                        PsnPvmOutgoingMessage *messEV) 
00058 {
00059 
00060 }
00061 
00062 
00063 void PsnPvmReferenceObjectHandle::insertInStream (ostream & out) const 
00064 {
00065    PsController::error ("On utilise l'insert du referentiel") ;
00066 }
00067 
00068 //-----------------------------------------------------------------------------
00069 void PsnPvmReferenceObjectHandle::unpack (PsIncomingSynchronisationMessage & in) 
00070 {
00071 #if defined (_DEBUGPVMMESS)
00072    cerr << "PsnPvmReferenceObjectHandle::unpack"<<endl;
00073 #endif
00074    // Frequency max des refs du pss distant
00075    PsFrequency freqPssDist ;
00076    // Frequency de ce pss
00077    PsFrequency freqLocale ;
00078    // Frequency de communication
00079    PsFrequency  freqComm ;
00080 
00081    PsnRequestType typeMess ;
00082    int messageType ;
00083 
00084    in >> messageType ;
00085    typeMess = static_cast <PsnRequestType> (messageType) ;
00086 
00087 #if defined (_DEBUGPVMMESS)
00088    cerr << "PsnPvmReferenceObjectHandle::unpack: received a message of type " <<typeMess<<" "<<Registration
00089         <<" at date "<<getSimulatedObject().getSimulatedDate()
00090         <<endl;
00091 #endif
00092  
00093    if (typeMess == Registration) 
00094       {
00095          // name of the process sending the message
00096          PsName processName ;
00097          
00098          processName.unpack ( in ) ;
00099 #ifdef _DEBUGPVMMESS
00100          cout << "PsnPvmReferenceObjectHandle::unpack " << processName << " registering a mirror "<< endl ;
00101 #endif
00102          PsnSvmLink * canal = dynamic_cast<PsPvmController &>(_controller).getDistributedVirtualMachine()->getLinkToProcessNamed (processName) ;
00103 
00104          PsnProcess * processDescriptor = dynamic_cast<PsPvmController &>(_controller).getDistributedVirtualMachine()->getProcessDescriptorNamed (processName) ;
00105          
00106          //the registering process needs a complete version of the outputs of the object in the next synchronisation message
00107          _needAllOutputValues.insert ( make_pair(processName, canal) ) ;
00108 
00109 //       // On recupere la frequency max des refs du pss distant
00110 //       freqPssDist = processDescriptor->getMaxFrequencyOfHostedObjects () ;
00111 //       // On recupere la frequency locale
00112 //       freqLocale = _myObject. getObjectDescriptor ().getFrequency () ;
00113 //       // On calcule la frequency de communication
00114 //  #ifdef _DEBUGPVMMESS
00115 //       cout << "freqLocale : " << freqLocale << endl ;
00116 //       cout << "freqPssDist : " << freqPssDist << endl ;
00117 //  #endif
00118 //       if (freqLocale > freqPssDist) 
00119 //          {
00120 //             freqComm = plusPetitSSMultSup(freqLocale,
00121 //                                            freqPssDist) ;
00122 //  #ifdef _DEBUGPVMMESS
00123 //             cout << "freqComm : " << freqComm << endl ;
00124 //  #endif
00125 //          } 
00126 //       else 
00127 //          {
00128 //             freqComm = freqLocale ;
00129 //  #ifdef _DEBUGPVMMESS
00130 //             cout << "freqComm  : " << freqComm << endl ;
00131 //  #endif
00132 //          }
00133 //       // On la stocke
00134 //       _processFrequencies.insert (ProcessFrequenciesType::value_type(processName, freqComm)) ;
00135       } 
00136    else if (typeMess == CancelRegistration) 
00137       {
00138          // name of the process sending the message
00139          PsName processName ;
00140          processName.unpack ( in ) ;
00141 
00142          _needUpdateOutputValues.erase (processName) ; 
00143          //_processFrequencies.erase ( processName ) ;
00144          _needAllOutputValues.erase ( processName ) ;
00145       } 
00146    else if (typeMess == EventReceived) 
00147       {
00148 #if ( defined (_DEBUGPVMMESS) || defined (_DEBUGPVMEVENTS ) )
00149          cerr << "PsnPvmReferenceObjectHandle::unpack: received an event relayed from an mirror" << endl ;
00150 #endif
00151          PsEvent * event ;
00152          PsName classToCreate ;
00153          PsEventIdentifier eventId;
00154          PsDate eventDate;
00155          PsName sender, receiver ;
00156          in >> classToCreate >> eventId>> eventDate>>sender>>receiver ;
00157          event = PsEventCreator::createEvent (classToCreate, eventId, eventDate, sender, receiver ) ;
00158          event->unpack ( in ) ;
00159          PsnReferenceObjectHandle::receiveEvent ( event ) ;
00160       } 
00161    else if (typeMess == RegisterForSignal) 
00162       {
00163 #ifdef _DEBUGPVMMESS
00164          cout << "PsnPvmReferenceObjectHandle::unpack: RegisterForSignal" << endl ;
00165 #endif
00166       PsName sigId ;
00167       PsName registrant ;
00168       PsName eventId ;
00169       in >> sigId >> registrant >> eventId ;
00170       receiveRegistrationForSignal (sigId, registrant, eventId );
00171    } 
00172    else if (typeMess == CancelRegistrationForSignal) 
00173       {
00174 #ifdef _DEBUGPVMMESS
00175          cout << "PsnPvmReferenceObjectHandle::unpack: CancelRegistrationForSignal" << endl ;
00176 #endif
00177          PsName sigId ;
00178          PsName registrant ;
00179          in >> sigId >> registrant ;
00180          cancelRegistrationForSignal (sigId, registrant) ;
00181       }
00182    else 
00183       {
00184          cerr<<"PsnPvmReferenceObjectHandle::unpack : unknown request"<<endl; ;
00185       }
00186 
00187 #if defined (_DEBUGPVMMESS)
00188    cerr << "PsnPvmReferenceObjectHandle::unpack finished" <<endl;
00189 #endif
00190 }
00191    
00192 
00193 
00194 void PsnPvmReferenceObjectHandle::extract (istream & in) {
00195 #if defined (_DEBUGPVMMESS)
00196    cerr << "PsnPvmReferenceObjectHandle::extract:"<<endl;
00197 #endif
00198    // Type de message
00199    PsString typeMess ;
00200    // Nom du processus ou se trouve le miroir (cas de l'EV)
00201    PsName processName ;
00202    
00203    in >> typeMess ;
00204    cerr << "PsnPvmReferenceObjectHandle::extract: received a message of type " <<typeMess<<endl;
00205    if (typeMess == "EV") 
00206       {
00207          int typeEv ;
00208          in >> typeEv ;
00209          cerr << "PsnPvmReferenceObjectHandle::extract: received an event message of type " <<typeEv<<endl;
00210          if (typeEv == Registration) 
00211             {
00212                // Frequency max des refs du pss distant
00213                PsFrequency freqPssDist ;
00214                // Frequency de ce pss
00215                PsFrequency freqLocale ;
00216                // Frequency de communication
00217                PsFrequency  freqComm ;
00218 
00219                // On recupere le nom du processus associe
00220                in >> processName ;
00221 #ifdef _DEBUGPVMMESS
00222                cout << "PsnPvmReferenceObjectHandle::extract "<<processName << " registred a mirror "<< endl ;
00223 #endif
00224                // On recupere le processus associe
00225                PsnSvmLink * canal = dynamic_cast<PsPvmController &>(_controller).getDistributedVirtualMachine()->getLinkToProcessNamed (processName) ;
00226                
00227                PsnProcess * processDescriptor = dynamic_cast<PsPvmController &>(_controller).getDistributedVirtualMachine()->getProcessDescriptorNamed (processName) ;
00228                
00229                //the registering process needs a complete version of the outputs of the object in the next synchronisation message
00230                _needAllOutputValues.insert ( make_pair (processName,canal) ) ;
00231 
00232 //          // On recupere la frequency max des refs du pss distant
00233 //          freqPssDist = processDescriptor->getMaxFrequencyOfHostedObjects () ;
00234 //          // On recupere la frequency locale
00235 //          freqLocale = _myObject. getObjectDescriptor ().getFrequency () ;
00236 //          // On calcule la frequency de communication
00237 //  #ifdef _DEBUGPVMMESS
00238 //          cout << "freqLocale : " << freqLocale << endl ;
00239 //          cout << "freqPssDist : " << freqPssDist << endl ;
00240 //  #endif
00241 //          if (freqLocale > freqPssDist) {
00242 //             freqComm = plusPetitSSMultSup(freqLocale,
00243 //                                            freqPssDist) ;
00244 //  #ifdef _DEBUGPVMMESS
00245 //             cout << "freqComm : " << freqComm << endl ;
00246 //  #endif
00247 //          } else {
00248 //          freqComm = freqLocale ;
00249 //  #ifdef _DEBUGPVMMESS
00250 //          cout << "freqComm  : " << freqComm << endl ;
00251 //  #endif
00252 //          }
00253 //       // On la stocke
00254 //          _processFrequencies.insert(ProcessFrequenciesType::value_type(processName, freqComm)) ;
00255          } 
00256          else if (typeEv == CancelRegistration) {
00257             cout << "On se desabonne" << endl ;
00258          } 
00259          else if (typeEv == EventReceived) {
00260 #ifdef DEBUG
00261          cerr << "On recoit un evenement en provenance d'un miroir" << endl ;
00262 #endif
00263          assert ( false ) ;
00264          //PsEvent evt ( in ) ;
00265          //in >> evt ;
00266          //receiveReallyEvent (evt) ;
00267       } 
00268          else if (typeEv == RegisterForSignal) 
00269             {
00270 #ifdef DEBUG
00271       cout << "On recoit un signal en provenance d'un miroir" << endl ;
00272 #endif
00273       PsName sigId ;
00274       PsName abonne ;
00275       PsName eventId ;
00276       in >> sigId >> abonne >> eventId ;
00277       receiveRegistrationForSignal (sigId, abonne, eventId );
00278       } 
00279       else {
00280          cerr<<"PsnPvmReferenceObjectHandle::extract : Type d'evenement incorrect"<<endl ;
00281       }
00282    }
00283    else {
00284       cerr<<"PsnPvmReferenceObjectHandle::extract : Type d'evenement incorrect" <<endl ;
00285    }
00286 }
00287 
00288 
00289 //-----------------------------------------------------------------------------
00291 
00292 void PsnPvmReferenceObjectHandle::makeSynchronisationMessage ( const PsDate & date ) 
00293 {
00294 #if defined (_DEBUGEXECPVM) || defined (_DEBUGPVMMESS) 
00295    cerr<<"PsnPvmReferenceObjectHandle::makeSynchronisationMessage ( const PsDate & "<<date<< ")"<<endl;
00296 #endif
00297    PsnPvmOutgoingMessage * message ;
00298 
00299    if ( _dateOfLastActivation == date )
00300       // only send a synchronisation message if the handled object has been activated
00301       {
00302          PsNameToPointerMap<PsnSvmLink>::iterator pCanal ; // iterateur
00303 //       ProcessFrequenciesType::iterator pFreq ; // iterateur
00304 //       PsDate dtComm ;
00305 //       PsFrequency freqComm ;
00306 #ifdef _DEBUGPVMMESS
00307          cout<<"makeSynchronisationMessages of "<<getSimulatedObject().getName()<<endl;
00308 #endif
00309          // On initialise l'iterateur sur la frequency
00310          //pFreq = _processFrequencies.begin () ;
00311          //Pour tous les abonnes
00312          for (pCanal = _needUpdateOutputValues.begin () ;
00313               pCanal != _needUpdateOutputValues.end ();
00314               pCanal ++) 
00315             {
00316                // On calcule le pas de temps de la communication
00317 //             freqComm = (*pFreq).second ;
00318 //             dtComm = 1000 / freqComm ;
00319 #ifdef _DEBUGPVMMESS
00320                cout << "dtComm : " << dtComm << endl ;
00321 #endif
00322                // On verifie qu'il faut reellement emettre
00323                // devrait maintenant etre inutile a cause des Frames majeures et mineures
00324 //             if (_controller.getSimulatedDate () % dtComm == 0) 
00325 //                {
00326                      // On recupere le message ou stocker les donnees
00327                      message = &(*pCanal).second->getOutgoingBuffer () ;  
00328 #ifdef _DEBUGPVMMESS
00329                      cout <<"PsnPvmReferenceObjectHandle::makeSynchronisationMessage writing to the buffer: " <<message<< endl ;
00330 #endif
00331           // On va construire le message
00332           // On ajoute le destinataire, puis le type du message puis les outputs
00333           *message << _myObject.getName ()  
00334                    << static_cast<int> (SynchronisationMessage) 
00335                    <<  _myObject ;
00336   
00337 #ifdef _DEBUGDISTRIBUTEDINIT
00338           cerr<<"PsnPvmReferenceObjectHandle::makeSynchronisationMessage : sending a message to ";
00339           (*pCanal).second->printDebuggingInformation();
00340           cerr<<" for object "<<_myObject.getName()<<endl;
00341 #endif
00342         }
00343         // On passe a la frequency suivante
00344 //      pFreq ++ ;
00345 //        }
00346     }
00347   else
00348     {
00349 #ifdef _DEBUGPVMMESS
00350       cerr <<"PsnPvmReferenceObjectHandle::makeSynchronisationMessage : No synchronisation needed at " << date 
00351            <<", last activation : "<<_dateOfLastActivation<<endl ;
00352 #endif
00353     }
00354    // send complete values to the processes needing a complete list of the values with their associated production date.
00355    // this is done after updating, because processes in that list are then automatically inserted in the list of process needing only updates
00356    for (map<PsName, PsnSvmLink *>::iterator i = _needAllOutputValues.begin() ;
00357         i != _needAllOutputValues.end() ;
00358         ++i)
00359       {
00360          packInitialValues ( (i->second)->getOutgoingBuffer () ) ; 
00361 
00362          _needUpdateOutputValues.insert ( *i ) ;
00363       }
00364    _needAllOutputValues.clear() ;
00365 #ifdef _DEBUGPVMMESS
00366    cerr <<"PsnPvmReferenceObjectHandle::makeSynchronisationMessage end" <<endl ;
00367 #endif
00368 }
00369 
00370 //-----------------------------------------------------------------------------
00371 
00372 int PsnPvmReferenceObjectHandle::plusPetitSSMultSup (const int A, const int B) {
00373    // Fournit le plus petit sous-multiple de A plus grand que B
00374    int i = B ; // Valeur testee
00375    // Valeur max au dela de laquelle pas ss-multiple
00376    int valMax = div (A, 2).quot ; 
00377    bool ssMult = false ; // i ss-multiple de A ???
00378 
00379 #ifdef DEBUG
00380    cout << "plusPetitSSMultSup***************************************" << endl ;
00381    cout << "A : " << A << ", B : " << B << endl ;
00382    cout << "valMax : " << valMax << endl ;
00383 #endif
00384   
00385    // On verifie si i ss-multiple de A
00386    ssMult = (div (A, i).rem == 0) ;
00387    while ((! ssMult) && (i <= valMax)) {
00388       i++ ;
00389       // On verifie si i ss-multiple de A
00390       ssMult = (div (A, i).rem == 0) ;
00391    }
00392    if (i > valMax) {
00393 #ifdef DEBUG
00394       cout << "res : " << A << endl ;
00395       cout << "Fin de plusPetitSSMultSup***************************************" << endl;
00396 #endif  
00397       return A ;
00398    } else {
00399 #ifdef DEBUG
00400       cout << "res : " << i << endl ;
00401       cout << "Fin de plusPetitSSMultSup***************************************" << endl;
00402 #endif  
00403       return i ;
00404    }
00405 }
00406 
00407 
00408 void PsnPvmReferenceObjectHandle::packInitialValues ( PsnPvmOutgoingMessage & message ) 
00409 {
00410    _myObject.getName ().pack ( message ) ; 
00411    message << static_cast<int> (InitialValuesMessage) ;
00412    _myObject.packAllValues ( message ) ;
00413 }
00414 

logo OpenMask

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

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