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 "OMKTracer.h" 00019 #include <cassert> 00020 #include <OMKPvmMirrorObjectHandle.h> 00021 #include <OMKSimulatedObject.h> 00022 #include <OMKPvmController.h> 00023 #include <OMKPvmSvmLink.h> 00024 #include <OMKPvmMessage.h> 00025 #include "OMKEvent.h" 00026 #include "OMKObjectDescriptor.h" 00027 #include "OMKSvm.h" 00028 using namespace std ; 00029 #ifndef _MSC_VER 00030 #include <sys/time.h> 00031 #endif 00032 using namespace OMK ; 00033 00034 //----------------------------------------------------------------------------- 00035 //recevoir la liste des outputs exportables 00036 00037 PvmMirrorObjectHandle::PvmMirrorObjectHandle (SimulatedObject & objetSimul) : 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 } 00050 00051 //----------------------------------------------------------------------------- 00052 00053 PvmMirrorObjectHandle::~PvmMirrorObjectHandle () { 00054 00055 } 00056 00057 void PvmMirrorObjectHandle::attributeRead () 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 } 00072 00073 //----------------------------------------------------------------------------- 00074 // s'abonner Flot de Donnees aupres du referentiel 00075 00076 void PvmMirrorObjectHandle::registerToReferenceObject (bool needValues) 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 } 00112 00113 //----------------------------------------------------------------------------- 00114 00115 void PvmMirrorObjectHandle::cancelRegistrationToReferenceObject () 00116 { 00117 #ifdef _DEBUGPVMSYNCHRO 00118 cout << "PvmMirrorObjectHandle::cancelRegistrationToReferenceObject" << endl ; 00119 #endif 00120 sendRequestToReferenceObject (CancelRegistration) ; 00121 _registered = false ; 00122 } 00123 00124 //----------------------------------------------------------------------------- 00125 00126 void PvmMirrorObjectHandle::insertInStream (ostream & out) const { 00127 out << "PvmMirrorObjectHandle::insertInStream nothing to insert" << endl ; 00128 } 00129 00130 //----------------------------------------------------------------------------- 00131 void PvmMirrorObjectHandle::unpack (IncomingSynchronisationMessage & in) 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 } 00170 00171 00172 00173 void PvmMirrorObjectHandle::extract (istream & in) 00174 { 00175 assert (false) ; //use of extract deprecated 00176 } 00177 00178 //----------------------------------------------------------------------------- 00179 void PvmMirrorObjectHandle::receiveEvent (const Event & event) 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 } 00188 00189 00190 00191 void PvmMirrorObjectHandle::receiveEvent (Event * event) 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 } 00203 00204 00205 //----------------------------------------------------------------------------- 00206 00207 bool PvmMirrorObjectHandle::receiveRegistrationForSignal ( const EventIdentifier & sigId, 00208 const Name & registrant, 00209 const EventIdentifier & eventId ) 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 } 00220 00221 bool PvmMirrorObjectHandle::cancelRegistrationForSignal( const EventIdentifier & sigId , 00222 const Name & registrant ) 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 } 00231 00232 void PvmMirrorObjectHandle::sendEventsForSignal( Event & event , const EventIdentifier & sigId ) 00233 { 00234 assert ( false ) ; 00235 } 00236 00237 void PvmMirrorObjectHandle::sendRequestToReferenceObject (RequestType typeMess) 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 } 00262 00263 00264 00265 00268 void PvmMirrorObjectHandle::linkToNewReferential (Name newProcessName) 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 } 00292 00293 void PvmMirrorObjectHandle::setMorphosisPhaseTrue () 00294 { 00295 morphosisPhase = true ; 00296 _migrationCase = true ; 00297 } 00298 00299
Documentation generated on Mon Jun 9 11:45:57 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |