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