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 <PsnPvmSvmLink.h> 00019 00020 #include <stdio.h> 00021 #include <pvm3.h> 00022 #include <signal.h> 00023 00024 #include <PsnPvmMessage.h> 00025 #include <PsController.h> 00026 #include "PsPvmException.h" 00027 00028 //----------------------------------------------------------------------------- 00029 00030 PsnPvmSvmLink::PsnPvmSvmLink (int td) : 00031 PsnSvmLink(), 00032 _outgoingBuffer ( td ), 00033 _distantSiteId ( td ) 00034 { 00035 } 00036 00037 //----------------------------------------------------------------------------- 00038 00039 PsnPvmSvmLink::~PsnPvmSvmLink() 00040 { 00041 } 00042 00043 00044 00045 void PsnPvmSvmLink::send (PsnPvmOutgoingMessage & m, PsnPvmMessage::MessageTag tag) 00046 { 00047 m.send ( tag ) ; 00048 } 00049 00050 00051 00052 void PsnPvmSvmLink::sendOutgoingBuffer(PsnPvmMessage::MessageTag tag) 00053 { 00054 #ifdef _DEBUGPVMMESS 00055 cerr << "PsnPvmSvmLink::sendOutgoingBuffer ("<< force << "," << tag <<") "<<endl; 00056 #endif 00057 _outgoingBuffer.send ( tag ) ; 00058 } 00059 00060 //----------------------------------------------------------------------------- 00061 00062 PsnPvmIncomingMessage & PsnPvmSvmLink::waitForMessage(PsnPvmMessage::MessageTag tag) 00063 { 00064 // attente en reception 00065 int res = pvm_recv (_distantSiteId, tag) ; 00066 00067 _incomingBuffer.initialise ( res ) ; 00068 #ifdef _DEBUGPVMMESS 00069 cerr << "waitForMessage : On recoit un message tag: " << tag << " de " << hex << _distantSiteId << dec << endl; 00070 #endif 00071 // On renvoie le message 00072 return _incomingBuffer ; 00073 } 00074 00075 //----------------------------------------------------------------------------- 00076 00077 PsnPvmIncomingMessage * PsnPvmSvmLink::testForMessage (PsnPvmMessage::MessageTag tag) 00078 { 00079 #ifdef _DEBUGPVMMESS 00080 cerr << "PsnPvmSvmLink::testForMessage: tag " <<tag<<endl; 00081 #endif 00082 00083 int res = pvm_nrecv (_distantSiteId, tag) ; 00084 00085 if (res >= 0) 00086 { 00087 _incomingBuffer.initialise ( res ); 00088 return &_incomingBuffer ; 00089 } 00090 else 00091 { 00092 return NULL ; 00093 } 00094 } 00095 00096 PsnPvmMessage::MessageTag 00097 PsnPvmSvmLink::testForAnyMessage (PsnPvmIncomingMessage & receiveBuffer) 00098 { 00099 PsnPvmMessage::MessageTag result ; 00100 00101 int bufid = pvm_nrecv ( _distantSiteId, -1 ) ; //test if any message has arrived from distantDiteId 00102 00103 if ( bufid < 0 ) 00104 { 00105 cerr<<"PsnSvm::waitForAnyRequests ERROR "; 00106 switch (bufid) 00107 { 00108 case PvmBadParam: 00109 cerr<<"giving an invalid tid value, or msgtag < -1"; 00110 break; 00111 case PvmSysErr: 00112 cerr<<"pvmd not responding"; 00113 break; 00114 default: 00115 cerr<<"unexpected error"; 00116 if (PsController::warningLevel >= PsController::FatalWarnings) 00117 { 00118 exit (2) ; 00119 } 00120 } 00121 cerr<<endl; 00122 } 00123 00124 if ( bufid != 0 ) 00125 { 00126 int bytes ; 00127 int senderSiteId ; 00128 int msgtag ; 00129 int info = pvm_bufinfo( bufid, &bytes , &msgtag , &senderSiteId ) ; 00130 00131 result = static_cast<PsnPvmMessage::MessageTag>(msgtag) ; 00132 00133 if ( info < 0 ) 00134 { 00135 cerr<<"PsnSvm::waitForAnyRequests ERROR in pvm_bufinfo "; 00136 switch (info) 00137 { 00138 case PvmBadParam: 00139 cerr<<"invalid argument"; 00140 break; 00141 case PvmNoSuchBuf: 00142 cerr<<"specified buffer does not exist"; 00143 break; 00144 default: 00145 cerr<<"unexpected error"; 00146 if (PsController::warningLevel >= PsController::FatalWarnings) 00147 { 00148 exit (2) ; 00149 } 00150 } 00151 cerr<<endl; 00152 } 00153 } 00154 00155 receiveBuffer.initialise ( bufid ) ; 00156 00157 return result ; 00158 } 00159 00160 //----------------------------------------------------------------------------- 00161 00162 void PsnPvmSvmLink::printDebuggingInformation () 00163 { 00164 cerr << "PsnPvmSvmLink:"<<this<<":printDebuggingInformation:_distantSiteIdant : " << hex << _distantSiteId << dec << endl ; 00165 } 00166 00167 //----------------------------------------------------------------------------- 00168 00169 int PsnPvmSvmLink::getTID () 00170 { 00171 return _distantSiteId ; 00172 } 00173 00174 void PsnPvmSvmLink::pack (PsOutgoingSynchronisationMessage & out) const 00175 { 00176 out << _distantSiteId ; 00177 } 00178 00179 00180 void PsnPvmSvmLink::unpack (PsIncomingSynchronisationMessage & in) 00181 { 00182 #ifdef _DEBUGPVMMESS 00183 cerr<<"PsnPvmSvmLink::unpack: "; 00184 #endif 00185 in >> _distantSiteId ; 00186 00187 _outgoingBuffer.setDistantSiteId ( _distantSiteId ) ; 00188 #ifdef _DEBUGPVMMESS 00189 cerr<<"distant site Id: "<<_distantSiteId<<endl; 00190 #endif 00191 } 00192 00193 00194 00195 PsnPvmOutgoingMessage & PsnPvmSvmLink::getOutgoingBuffer () 00196 { 00197 return _outgoingBuffer ; 00198 }
| Documentation generated on Mon Nov 25 15:25:01 2002 |
Generated with doxygen 1.2.12 by Dimitri van Heesch , 1997-2001 |