00001 #include "PsnPvmIncomingMessage.h" 00002 00003 #include "stdio.h" 00004 #include "pvm3.h" 00005 00006 #include "PsController.h" 00007 #include "PsPvmException.h" 00008 int PsnPvmIncomingMessage::pvmActiveBuffer = 0 ; 00009 00010 00011 00012 PsnPvmIncomingMessage::PsnPvmIncomingMessage() : 00013 PsIncomingSynchronisationMessage (), 00014 PsnPvmMessage (0) 00015 { 00016 00017 } 00018 00019 00020 00021 PsnPvmIncomingMessage::PsnPvmIncomingMessage(int bufId) : 00022 PsIncomingSynchronisationMessage (), 00023 PsnPvmMessage (bufId) 00024 { 00025 pvmActiveBuffer = bufId ; 00026 } 00027 00028 00029 00030 void PsnPvmIncomingMessage::initialise ( int bufId ) 00031 { 00032 _currentBuffer = bufId ; 00033 pvmActiveBuffer = bufId ; 00034 if (_myis != 0 ) 00035 { 00036 delete _myis ; 00037 _myis = 0 ; 00038 } 00039 if (_currentBuffer != 0) _messageTimestamp.unpack(*this) ; 00040 } 00041 00042 00043 //-------------------------------------------------------------------- 00044 PsnPvmIncomingMessage::~PsnPvmIncomingMessage () 00045 { 00046 } 00047 00048 const PsDate & PsnPvmIncomingMessage::getMessageDate() 00049 { 00050 return _messageTimestamp ; 00051 } 00052 00053 bool PsnPvmIncomingMessage::hasMessage () const 00054 { 00055 return _currentBuffer != 0 ; 00056 } 00057 00058 00059 //-------------------------------------------------------------------- 00060 void PsnPvmIncomingMessage::checkForGetErrors( int info) 00061 { 00062 if (info < 0 ) 00063 { 00064 cerr<<"PsnPvmIncomingMessage::checkForGetErrors ERROR "; 00065 assert ( false ) ; 00066 switch ( info ) 00067 { 00068 case PvmNoData: 00069 cerr<<"Reading beyond the end of the receive buffer. Most likely cause is trying to get more items than were originally packed into the buffer. This can also happen if a new reception without buffer saving happened in the course of geting all the data of a previous message"; 00070 break; 00071 case PvmNoBuf: 00072 cerr<<"There is no active receive buffer to get."; 00073 break; 00074 case PvmBadMsg: 00075 cerr<<"The received message can to be decoded. Most likely because the hosts are heterogeneous and the users specified an incompatible encoding."; 00076 break; 00077 default: 00078 cerr<<"unexpected error: "; 00079 } 00080 cerr<<endl; 00081 if ( PsController::warningLevel >= PsController::ExceptionOnWarnings ) 00082 { 00083 throw PsPvmException ( info ) ; 00084 } 00085 } 00086 } 00087 00088 00089 00090 void PsnPvmIncomingMessage::get (bool & val) 00091 { 00092 assert ( pvmActiveBuffer == _currentBuffer ) ; 00093 char realVal ; 00094 int info = pvm_upkbyte ( &realVal, 1, 1 ) ; 00095 val = realVal ; 00096 #ifdef _DEBUGPVMMESS 00097 cerr<<"PsnPvmIncomingMessage::get (char & "<<val<<" )"<<endl; 00098 #endif 00099 checkForGetErrors ( info ) ; 00100 } 00101 00102 00103 void PsnPvmIncomingMessage::get (char & val) 00104 { 00105 assert ( pvmActiveBuffer == _currentBuffer ) ; 00106 int info = pvm_upkbyte ( &val, 1, 1 ) ; 00107 #ifdef _DEBUGPVMMESS 00108 cerr<<"PsnPvmIncomingMessage::get (char & "<<val<<" )"<<endl; 00109 #endif 00110 checkForGetErrors ( info ) ; 00111 } 00112 00113 00114 void PsnPvmIncomingMessage::get (long & val) 00115 { 00116 assert ( pvmActiveBuffer == _currentBuffer ) ; 00117 int info = pvm_upklong ( &val, 1, 1 ) ; 00118 #ifdef _DEBUGPVMMESS 00119 cerr<<"PsnPvmIncomingMessage::get (long & "<<val<<" )"<<endl; 00120 #endif 00121 checkForGetErrors ( info ) ; 00122 } 00123 00124 00125 00126 00127 void PsnPvmIncomingMessage::get (unsigned long & val) 00128 { 00129 assert ( pvmActiveBuffer == _currentBuffer ); 00130 int info = pvm_upkulong ( &val, 1, 1 ) ; 00131 #ifdef _DEBUGPVMMESS 00132 cerr<<"PsnPvmIncomingMessage::get (unsigned long & "<<val<<" )"<<endl; 00133 #endif 00134 checkForGetErrors ( info ) ; 00135 } 00136 00137 00138 00139 00140 00141 void PsnPvmIncomingMessage::get (int & val) 00142 { 00143 assert ( pvmActiveBuffer == _currentBuffer ); 00144 int info = pvm_upkint ( &val, 1, 1 ) ; 00145 #ifdef _DEBUGPVMMESS 00146 cerr<<"PsnPvmIncomingMessage::get (int & "<<val<<" )"<<endl; 00147 #endif 00148 checkForGetErrors ( info ) ; 00149 } 00150 00151 00152 00153 void PsnPvmIncomingMessage::get (unsigned int & val) 00154 { 00155 assert ( pvmActiveBuffer == _currentBuffer ); 00156 int info = pvm_upkuint ( &val, 1, 1 ) ; 00157 #ifdef _DEBUGPVMMESS 00158 cerr<<"PsnPvmIncomingMessage::get (unsigned int & "<<val<<" )"<<endl; 00159 #endif 00160 checkForGetErrors ( info ) ; 00161 } 00162 00163 00164 00165 00166 void PsnPvmIncomingMessage::get (float & val) 00167 { 00168 assert ( pvmActiveBuffer == _currentBuffer ); 00169 int info = pvm_upkfloat ( &val, 1, 1 ) ; 00170 #ifdef _DEBUGPVMMESS 00171 cerr<<"PsnPvmIncomingMessage::get (float & "<<val<<" )"<<endl; 00172 #endif 00173 checkForGetErrors ( info ) ; 00174 } 00175 00176 00177 00178 00179 void PsnPvmIncomingMessage::get (double & val) 00180 { 00181 assert ( pvmActiveBuffer == _currentBuffer ); 00182 int info = pvm_upkdouble ( &val, 1, 1 ) ; 00183 #ifdef _DEBUGPVMMESS 00184 cerr<<"PsnPvmIncomingMessage::get (double & "<<val<<" )"<<endl; 00185 #endif 00186 checkForGetErrors ( info ) ; 00187 } 00188 00189 00190 00191 00192 void PsnPvmIncomingMessage::get (short & val) 00193 { 00194 assert ( pvmActiveBuffer == _currentBuffer ); 00195 int info = pvm_upkshort ( &val, 1, 1 ) ; 00196 #ifdef _DEBUGPVMMESS 00197 cerr<<"PsnPvmIncomingMessage::get (short & "<<val<<" )"<<endl; 00198 #endif 00199 checkForGetErrors ( info ) ; 00200 } 00201 00202 00203 00204 void PsnPvmIncomingMessage::get (unsigned short & val) 00205 { 00206 assert ( pvmActiveBuffer == _currentBuffer ); 00207 int info = pvm_upkushort ( &val, 1, 1 ) ; 00208 #ifdef _DEBUGPVMMESS 00209 cerr<<"PsnPvmIncomingMessage::get (unsigned short & "<<val<<" )"<<endl; 00210 #endif 00211 checkForGetErrors ( info ) ; 00212 } 00213 00214 00215 00216 void PsnPvmIncomingMessage::get (char * ch) 00217 { 00218 assert ( pvmActiveBuffer == _currentBuffer ); 00219 int info = pvm_upkstr ( ch ) ; 00220 #ifdef _DEBUGPVMMESS 00221 cerr<<"PsnPvmIncomingMessage::get (char * "<<ch<<" )"<<endl; 00222 #endif 00223 checkForGetErrors ( info ) ; 00224 } 00225 00226 00227 void PsnPvmIncomingMessage::get (string & str) 00228 { 00229 assert ( pvmActiveBuffer == _currentBuffer ); 00230 00231 unsigned int stringSize ; 00232 int info = pvm_upkuint ( &stringSize, 1, 1 ) ; 00233 checkForGetErrors ( info ) ; 00234 00235 char * Cstr = new char [stringSize] ; 00236 00237 info = pvm_upkstr ( Cstr ) ; 00238 checkForGetErrors ( info ) ; 00239 assert (Cstr[stringSize-1] == '\0' ) ; 00240 00241 str = Cstr ; 00242 #ifdef _DEBUGPVMMESS 00243 cerr<<"PsnPvmIncomingMessage::get (string & "<<str<<" )"<<endl; 00244 #endif 00245 delete [] Cstr ; 00246 00247 } 00248 void PsnPvmIncomingMessage::get (char * val, int cnt) 00249 { 00250 assert ( pvmActiveBuffer == _currentBuffer ) ; 00251 int info = pvm_upkbyte ( val, cnt, 1 ) ; 00252 #ifdef _DEBUGPVMMESS 00253 cerr<<"PsnPvmIncomingMessage::get (char * "<<val<<" )"<<endl; 00254 #endif 00255 checkForGetErrors ( info ) ; 00256 } 00257 00258 00259 void PsnPvmIncomingMessage::get (long * val, int cnt) 00260 { 00261 assert ( pvmActiveBuffer == _currentBuffer ) ; 00262 int info = pvm_upklong ( val, cnt, 1 ) ; 00263 #ifdef _DEBUGPVMMESS 00264 cerr<<"PsnPvmIncomingMessage::get (long * "<<val<<" )"<<endl; 00265 #endif 00266 checkForGetErrors ( info ) ; 00267 } 00268 00269 00270 00271 00272 void PsnPvmIncomingMessage::get (unsigned long * val, int cnt) 00273 { 00274 assert ( pvmActiveBuffer == _currentBuffer ); 00275 int info = pvm_upkulong ( val, cnt, 1 ) ; 00276 #ifdef _DEBUGPVMMESS 00277 cerr<<"PsnPvmIncomingMessage::get (unsigned long * "<<val<<" )"<<endl; 00278 #endif 00279 checkForGetErrors ( info ) ; 00280 } 00281 00282 00283 00284 00285 00286 void PsnPvmIncomingMessage::get (int * val, int cnt) 00287 { 00288 assert ( pvmActiveBuffer == _currentBuffer ); 00289 int info = pvm_upkint ( val, cnt, 1 ) ; 00290 #ifdef _DEBUGPVMMESS 00291 cerr<<"PsnPvmIncomingMessage::get (int * "<<val<<" )"<<endl; 00292 #endif 00293 checkForGetErrors ( info ) ; 00294 } 00295 00296 00297 00298 void PsnPvmIncomingMessage::get (unsigned int * val, int cnt) 00299 { 00300 assert ( pvmActiveBuffer == _currentBuffer ); 00301 int info = pvm_upkuint ( val, cnt, 1 ) ; 00302 #ifdef _DEBUGPVMMESS 00303 cerr<<"PsnPvmIncomingMessage::get (unsigned int * "<<val<<" )"<<endl; 00304 #endif 00305 checkForGetErrors ( info ) ; 00306 } 00307 00308 00309 00310 00311 void PsnPvmIncomingMessage::get (float * val, int cnt) 00312 { 00313 assert ( pvmActiveBuffer == _currentBuffer ); 00314 int info = pvm_upkfloat ( val, cnt, 1 ) ; 00315 #ifdef _DEBUGPVMMESS 00316 cerr<<"PsnPvmIncomingMessage::get (float * "<<val<<" )"<<endl; 00317 #endif 00318 checkForGetErrors ( info ) ; 00319 } 00320 00321 00322 00323 00324 void PsnPvmIncomingMessage::get (double * val, int cnt) 00325 { 00326 assert ( pvmActiveBuffer == _currentBuffer ); 00327 int info = pvm_upkdouble ( val, 1, 1 ) ; 00328 #ifdef _DEBUGPVMMESS 00329 cerr<<"PsnPvmIncomingMessage::get (double * "<<val<<" )"<<endl; 00330 #endif 00331 checkForGetErrors ( info ) ; 00332 } 00333 00334 00335 00336 00337 void PsnPvmIncomingMessage::get (short * val, int cnt) 00338 { 00339 assert ( pvmActiveBuffer == _currentBuffer ); 00340 int info = pvm_upkshort ( val, cnt, 1 ) ; 00341 #ifdef _DEBUGPVMMESS 00342 cerr<<"PsnPvmIncomingMessage::get (short * "<<val<<" )"<<endl; 00343 #endif 00344 checkForGetErrors ( info ) ; 00345 } 00346 00347 00348 00349 void PsnPvmIncomingMessage::get (unsigned short * val, int cnt) 00350 { 00351 assert ( pvmActiveBuffer == _currentBuffer ); 00352 int info = pvm_upkushort ( val, cnt, 1 ) ; 00353 #ifdef _DEBUGPVMMESS 00354 cerr<<"PsnPvmIncomingMessage::get (unsigned short * "<<val<<" )"<<endl; 00355 #endif 00356 checkForGetErrors ( info ) ; 00357 } 00358 00359
| Documentation generated on Mon Nov 25 15:25:01 2002 |
Generated with doxygen 1.2.12 by Dimitri van Heesch , 1997-2001 |