00001 #include "OMKPvmOutgoingMessage.h" 00002 00003 #include <cassert> 00004 #include <pvm3.h> 00005 #include "OMKController.h" 00006 #include "OMKPvmException.h" 00007 #include "OMKPvmSvm.h" 00008 using namespace std ; 00009 using namespace OMK ; 00010 00011 const Date & PvmOutgoingMessage::getMessageDate () const 00012 { 00013 return _timestamp ; 00014 } 00015 00016 void PvmOutgoingMessage::pack (bool val) 00017 { 00018 #ifdef _DEBUGPVMMESS 00019 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack (bool val) "<<val << " Buffer " << _currentBuffer <<endl; 00020 #endif 00021 //assert ( _timeStamped ) ; 00022 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00023 char realVal = val ; 00024 int info = pvm_pkbyte (&realVal, 1, 1) ; 00025 checkForPackErrors ( info ) ; 00026 pvm_setsbuf ( oldbuf ) ; 00027 } 00028 00029 00030 void PvmOutgoingMessage::pack (char val) 00031 { 00032 #ifdef _DEBUGPVMMESS 00033 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack (char val) "<<val << " Buffer " << _currentBuffer <<endl; 00034 #endif 00035 //assert ( _timeStamped ) ; 00036 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00037 int info = pvm_pkbyte (&val, 1, 1) ; 00038 checkForPackErrors ( info ) ; 00039 pvm_setsbuf ( oldbuf ) ; 00040 } 00041 00042 void PvmOutgoingMessage::pack (long val) 00043 { 00044 #ifdef _DEBUGPVMMESS 00045 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack (long val) "<<val << " Buffer " << _currentBuffer <<endl; 00046 00047 #endif 00048 //assert ( _timeStamped ) ; 00049 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00050 int info = pvm_pklong (&val, 1, 1) ; 00051 checkForPackErrors ( info ) ; 00052 pvm_setsbuf ( oldbuf ) ; 00053 } 00054 00055 00056 void PvmOutgoingMessage::pack (unsigned long val) 00057 { 00058 #ifdef _DEBUGPVMMESS 00059 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack (unsigned long val) "<<val<< " Buffer " << _currentBuffer << endl; 00060 #endif 00061 //assert ( _timeStamped ) ; 00062 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00063 int info = pvm_pkulong (&val, 1, 1) ; 00064 checkForPackErrors ( info ) ; 00065 pvm_setsbuf ( oldbuf ) ; 00066 } 00067 00068 void PvmOutgoingMessage::pack (int val) 00069 { 00070 #ifdef _DEBUGPVMMESS 00071 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack (int val) "<<val<< " Buffer " << _currentBuffer << endl; 00072 #endif 00073 //assert ( _timeStamped ) ; 00074 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00075 int info = pvm_pkint (&val, 1, 1) ; 00076 checkForPackErrors ( info ) ; 00077 pvm_setsbuf ( oldbuf ) ; 00078 } 00079 00080 00081 void PvmOutgoingMessage::pack (unsigned int val) 00082 { 00083 #ifdef _DEBUGPVMMESS 00084 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack (unsigned int val) "<<val<< " Buffer " << _currentBuffer << endl; 00085 #endif 00086 //assert ( _timeStamped ) ; 00087 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00088 int info = pvm_pkuint (&val, 1, 1) ; 00089 checkForPackErrors ( info ) ; 00090 pvm_setsbuf ( oldbuf ) ; 00091 } 00092 00093 void PvmOutgoingMessage::pack (float val) 00094 { 00095 #ifdef _DEBUGPVMMESS 00096 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack (float val) "<<val<< " Buffer " << _currentBuffer << endl; 00097 #endif 00098 //assert ( _timeStamped ) ; 00099 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00100 int info = pvm_pkfloat (&val, 1, 1) ; 00101 checkForPackErrors ( info ) ; 00102 pvm_setsbuf ( oldbuf ) ; 00103 } 00104 00105 00106 void PvmOutgoingMessage::pack (double val) 00107 { 00108 #ifdef _DEBUGPVMMESS 00109 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack (double val) "<<val<< " Buffer " << _currentBuffer << endl; 00110 #endif 00111 //assert ( _timeStamped ) ; 00112 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00113 int info = pvm_pkdouble (&val, 1, 1) ; 00114 checkForPackErrors ( info ) ; 00115 pvm_setsbuf ( oldbuf ) ; 00116 } 00117 00118 00119 00120 void PvmOutgoingMessage::pack (short val) 00121 { 00122 #ifdef _DEBUGPVMMESS 00123 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack (short val) "<<val<< " Buffer " << _currentBuffer << endl; 00124 #endif 00125 //assert ( _timeStamped ) ; 00126 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00127 int info = pvm_pkshort (&val, 1, 1) ; 00128 checkForPackErrors ( info ) ; 00129 pvm_setsbuf ( oldbuf ) ; 00130 } 00131 00132 00133 00134 void PvmOutgoingMessage::pack (unsigned short val) 00135 { 00136 #ifdef _DEBUGPVMMESS 00137 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack (unsigned short val) "<<val<< " Buffer " << _currentBuffer << endl; 00138 #endif 00139 //assert ( _timeStamped ) ; 00140 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00141 int info = pvm_pkushort (&val, 1, 1) ; 00142 checkForPackErrors ( info ) ; 00143 pvm_setsbuf ( oldbuf ) ; 00144 } 00145 00146 00147 00148 void PvmOutgoingMessage::pack (char * val) 00149 { 00150 #ifdef _DEBUGPVMMESS 00151 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack (char * val) "<<val<< " Buffer " << _currentBuffer << endl; 00152 #endif 00153 //assert ( _timeStamped ) ; 00154 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00155 int info = pvm_pkstr ( val ) ; 00156 checkForPackErrors ( info ) ; 00157 pvm_setsbuf ( oldbuf ) ; 00158 } 00159 00160 void PvmOutgoingMessage::pack (const char * val) 00161 { 00162 #ifdef _DEBUGPVMMESS 00163 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack (char * val) "<<val<< " Buffer " << _currentBuffer << endl; 00164 #endif 00165 //assert ( _timeStamped ) ; 00166 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00167 int info = pvm_pkstr ( const_cast<char *>( val ) ) ; 00168 checkForPackErrors ( info ) ; 00169 pvm_setsbuf ( oldbuf ) ; 00170 } 00171 00172 void PvmOutgoingMessage::pack (const std::string & val) 00173 { 00174 #ifdef _DEBUGPVMMESS 00175 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack (const std::string & val) "<<val<< " Buffer " << _currentBuffer << endl; 00176 #endif 00177 //assert ( _timeStamped ) ; 00178 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00179 //the string is packed, with the length needed for unpacking 00180 unsigned int strSize = val.size() + 1 ; 00181 int info = pvm_pkuint ( &strSize, 1, 1 ) ; 00182 00183 checkForPackErrors ( info ) ; 00184 00185 info = pvm_pkstr ( const_cast<char *>( val.c_str() ) ) ; 00186 checkForPackErrors ( info ) ; 00187 00188 pvm_setsbuf ( oldbuf ) ; 00189 } 00190 00191 00192 PvmOutgoingMessage::PvmOutgoingMessage ( ) : 00193 PvmMessage(0), 00194 _timeStamped ( false ) 00195 { 00196 #ifdef _DEBUGPVMMESS 00197 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":PvmOutgoingMessage ()"<<endl; 00198 #endif 00199 00200 _currentBuffer = pvm_mkbuf ( PvmSvm::pvmDataEncoding ) ; 00201 00202 #ifdef _DEBUGPVMMESS 00203 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":PvmOutgoingMessage (): new send buffer"<<_currentBuffer<<endl; 00204 #endif 00205 } 00206 00207 00208 PvmOutgoingMessage::~PvmOutgoingMessage () 00209 { 00210 pvm_freebuf ( _currentBuffer ) ; 00211 } 00212 00213 00214 00215 void PvmOutgoingMessage::reinitAndRevertPvmContext(int oldbuf) 00216 { 00217 assert (oldbuf != 0 ) ; 00218 #ifdef _DEBUGPVMMESS 00219 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":reinitAndRevertPvmContext () send buffer "<<_currentBuffer<<endl; 00220 #endif 00221 00222 // As send has been done, reinitialise everything 00223 OutgoingSynchronisationMessage::reinit() ; 00224 00225 _timeStamped = false ; 00226 00227 pvm_freebuf ( _currentBuffer ) ; 00228 00229 _currentBuffer = pvm_mkbuf ( PvmSvm::pvmDataEncoding ) ; 00230 00231 // remplaced by the prepeceeding lines, because init_send changes the current buffer 00232 // _currentBuffer = pvm_initsend ( PvmSvm::pvmDataEncoding ) ; changes _currentBuffer ) 00233 00234 int info = pvm_setsbuf ( oldbuf ) ; 00235 00236 checkForChangedBuffer ( info, __LINE__, __FILE__ ) ; 00237 #ifdef _DEBUGPVMMESS 00238 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":new send buffer "<<_currentBuffer<<endl; 00239 #endif 00240 } 00241 00242 bool PvmOutgoingMessage::isTimeStamped() const 00243 { 00244 return _timeStamped ; 00245 } 00246 00247 00248 void PvmOutgoingMessage::insertTimeStamp ( const Date & date ) 00249 { 00250 00251 #ifdef _DEBUGPVMMESS 00252 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":insertTimeStamp ("<<date<<") "<<_currentBuffer 00253 <<" of size "<<getSize() 00254 <<endl; 00255 #endif 00256 00257 if ( !_timeStamped ) 00258 { 00259 _timeStamped = true ; 00260 00261 *this<<date; 00262 00263 _timestamp = date ; 00264 00265 assert ( getSize() == 4 ) ; 00266 00267 } 00268 else 00269 { 00270 if ( date != _timestamp ) { 00271 //cerr<<"WARNING : timestamping at"<<date<<" message with timestamp "<<_timestamp<<endl; 00272 //assert ( date == _timestamp ) ; 00273 } 00274 } 00275 } 00276 00277 void PvmOutgoingMessage::checkForChangedBuffer (int info, int lineNumber, char * file) 00278 { 00279 if ( info < 0 ) 00280 { 00281 cerr<<"PvmOutgoingMessage::checkForChangedBuffer line "<<lineNumber<<" of "<<file<<" "; 00282 switch ( info ) 00283 { 00284 case PvmSysErr: 00285 cerr<<"pvmd not responding"; 00286 break; 00287 case PvmBadParam: 00288 cerr<<"giving an invalid bufid."; 00289 break; 00290 case PvmNoSuchBuf: 00291 cerr<<"Switching to a nonexistent message buffer."; 00292 break; 00293 default: 00294 cerr<<"unexpected error: "; 00295 } 00296 cerr<<endl; 00297 OMASSERT( false ) ; 00298 } 00299 } 00300 00301 00302 void PvmOutgoingMessage::checkForSendErrors (int info) 00303 { 00304 if ( info < 0 ) 00305 { 00306 cerr<<"PvmOutgoingMessage::checkForSendErrors ERROR"; 00307 switch ( info ) 00308 { 00309 case PvmSysErr: 00310 cerr<<"pvmd not responding"; 00311 break; 00312 case PvmBadParam: 00313 cerr<<"giving an invalid tid or a msgtag."; 00314 break; 00315 case PvmNoBuf: 00316 cerr<<"There is no active send buffer to pack into. Try calling pvm_initsend before sending."; 00317 break; 00318 default: 00319 cerr<<"unexpected error: "; 00320 } 00321 cerr<<endl; 00322 OMASSERT( false ) ; 00323 } 00324 } 00325 00326 void PvmOutgoingMessage::checkForPackErrors (int info) 00327 { 00328 if (info < 0 ) 00329 { 00330 cerr<<"PvmOutgoingMessage::checkForPackErrors ERROR"; 00331 switch ( info ) 00332 { 00333 case PvmNoMem: 00334 cerr<<"Malloc has failed. Message buffer size has exceeded the available memory on this host."; 00335 break; 00336 case PvmNoBuf: 00337 cerr<<"There is no active send buffer to pack into. Try calling pvm_initsend before packing message."; 00338 break; 00339 default: 00340 cerr<<"unexpected error: "; 00341 } 00342 cerr<<endl; 00343 OMASSERT( false ) ; 00344 } 00345 } 00346 00347 00348 void PvmOutgoingMessage::pack ( const long * val, int cnt ) 00349 { 00350 #ifdef _DEBUGPVMMESS 00351 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack ( const long * val, int cnt) "<<val<<endl; 00352 #endif 00353 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00354 int info = pvm_pklong ( const_cast<long *>(val), cnt, 1) ; 00355 checkForPackErrors ( info ) ; 00356 pvm_setsbuf ( oldbuf ) ; 00357 } 00358 00359 void PvmOutgoingMessage::pack ( const unsigned long * val, int cnt ) 00360 { 00361 #ifdef _DEBUGPVMMESS 00362 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack ( const unsigned long * val, int cnt) "<<val<<endl; 00363 #endif 00364 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00365 int info = pvm_pkulong ( const_cast<unsigned long *>(val), cnt, 1) ; 00366 checkForPackErrors ( info ) ; 00367 pvm_setsbuf ( oldbuf ) ; 00368 } 00369 00370 void PvmOutgoingMessage::pack ( const int * val, int cnt ) 00371 { 00372 #ifdef _DEBUGPVMMESS 00373 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack ( const int * val, int cnt) "<<val<<endl; 00374 #endif 00375 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00376 int info = pvm_pkint ( const_cast<int *>(val), cnt, 1) ; 00377 checkForPackErrors ( info ) ; 00378 pvm_setsbuf ( oldbuf ) ; 00379 } 00380 00381 void PvmOutgoingMessage::pack ( const unsigned int * val, int cnt ) 00382 { 00383 #ifdef _DEBUGPVMMESS 00384 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack ( const unsigned int * val, int cnt) "<<val<<endl; 00385 #endif 00386 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00387 int info = pvm_pkuint ( const_cast<unsigned int *>(val), cnt, 1) ; 00388 checkForPackErrors ( info ) ; 00389 pvm_setsbuf ( oldbuf ) ; 00390 } 00391 00392 void PvmOutgoingMessage::pack ( const float * val, int cnt ) 00393 { 00394 #ifdef _DEBUGPVMMESS 00395 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack ( const float * val, int cnt) "<<val<<endl; 00396 #endif 00397 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00398 int info = pvm_pkfloat ( const_cast<float *>(val), cnt, 1) ; 00399 checkForPackErrors ( info ) ; 00400 pvm_setsbuf ( oldbuf ) ; 00401 } 00402 00403 void PvmOutgoingMessage::pack ( const double * val, int cnt ) 00404 { 00405 #ifdef _DEBUGPVMMESS 00406 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack ( const double * val, int cnt) "<<val<<endl; 00407 #endif 00408 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00409 int info = pvm_pkdouble ( const_cast<double *>(val), cnt, 1) ; 00410 checkForPackErrors ( info ) ; 00411 pvm_setsbuf ( oldbuf ) ; 00412 } 00413 00414 00415 void PvmOutgoingMessage::pack ( const short * val, int cnt ) 00416 { 00417 #ifdef _DEBUGPVMMESS 00418 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack ( const short * val, int cnt) "<<val<<endl; 00419 #endif 00420 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00421 int info = pvm_pkshort ( const_cast< short *>(val), cnt, 1) ; 00422 checkForPackErrors ( info ) ; 00423 pvm_setsbuf ( oldbuf ) ; 00424 } 00425 00426 void PvmOutgoingMessage::pack ( const unsigned short * val, int cnt ) 00427 { 00428 #ifdef _DEBUGPVMMESS 00429 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack (const unsigned short * val, int cnt) "<<val<<endl; 00430 #endif 00431 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00432 int info = pvm_pkushort ( const_cast<unsigned short *>(val), cnt, 1) ; 00433 checkForPackErrors ( info ) ; 00434 pvm_setsbuf ( oldbuf ) ; 00435 } 00436 00437 00438 00439 void PvmOutgoingMessage::pack ( long * val, int cnt ) 00440 { 00441 #ifdef _DEBUGPVMMESS 00442 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack ( long * val, int cnt) "<<val<<endl; 00443 #endif 00444 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00445 int info = pvm_pklong ( val, cnt, 1) ; 00446 checkForPackErrors ( info ) ; 00447 pvm_setsbuf ( oldbuf ) ; 00448 } 00449 00450 void PvmOutgoingMessage::pack ( unsigned long * val, int cnt ) 00451 { 00452 #ifdef _DEBUGPVMMESS 00453 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack ( unsigned long * val, int cnt) "<<val<<endl; 00454 #endif 00455 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00456 int info = pvm_pkulong ( val, cnt, 1) ; 00457 checkForPackErrors ( info ) ; 00458 pvm_setsbuf ( oldbuf ) ; 00459 } 00460 00461 void PvmOutgoingMessage::pack ( int * val, int cnt ) 00462 { 00463 #ifdef _DEBUGPVMMESS 00464 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack ( int * val, int cnt) "<<val<<endl; 00465 #endif 00466 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00467 int info = pvm_pkint ( val, cnt, 1) ; 00468 checkForPackErrors ( info ) ; 00469 pvm_setsbuf ( oldbuf ) ; 00470 } 00471 00472 void PvmOutgoingMessage::pack ( unsigned int * val, int cnt ) 00473 { 00474 #ifdef _DEBUGPVMMESS 00475 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack ( unsigned int * val, int cnt) "<<val<<endl; 00476 #endif 00477 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00478 int info = pvm_pkuint ( val, cnt, 1) ; 00479 checkForPackErrors ( info ) ; 00480 pvm_setsbuf ( oldbuf ) ; 00481 } 00482 00483 void PvmOutgoingMessage::pack ( float * val, int cnt ) 00484 { 00485 #ifdef _DEBUGPVMMESS 00486 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack ( float * val, int cnt) "<<val<<endl; 00487 #endif 00488 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00489 int info = pvm_pkfloat ( val, cnt, 1) ; 00490 checkForPackErrors ( info ) ; 00491 pvm_setsbuf ( oldbuf ) ; 00492 } 00493 00494 void PvmOutgoingMessage::pack ( double * val, int cnt ) 00495 { 00496 #ifdef _DEBUGPVMMESS 00497 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack ( double * val, int cnt) "<<val<<endl; 00498 #endif 00499 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00500 int info = pvm_pkdouble ( val, cnt, 1) ; 00501 checkForPackErrors ( info ) ; 00502 pvm_setsbuf ( oldbuf ) ; 00503 } 00504 00505 00506 void PvmOutgoingMessage::pack ( short * val, int cnt ) 00507 { 00508 #ifdef _DEBUGPVMMESS 00509 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack ( short * val, int cnt) "<<val<<endl; 00510 #endif 00511 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00512 int info = pvm_pkshort ( val, cnt, 1) ; 00513 checkForPackErrors ( info ) ; 00514 pvm_setsbuf ( oldbuf ) ; 00515 } 00516 00517 void PvmOutgoingMessage::pack ( unsigned short * val, int cnt ) 00518 { 00519 #ifdef _DEBUGPVMMESS 00520 cerr<<"PvmOutgoingMessage:"<<(void *)this<<":pack (unsigned short * val, int cnt) "<<val<<endl; 00521 #endif 00522 int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00523 int info = pvm_pkushort ( val, cnt, 1) ; 00524 checkForPackErrors ( info ) ; 00525 pvm_setsbuf ( oldbuf ) ; 00526 } 00527 00530 void PvmOutgoingMessage::flushCurrentBuffer() 00531 { 00532 // TDTD remplacement par un simple reinit 00533 //int oldbuf = pvm_setsbuf ( _currentBuffer ) ; 00534 //reinitAndRevertPvmContext ( oldbuf ) ; 00535 reinit () ; 00536 } 00537
Documentation generated on Mon Jun 9 11:45:57 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |