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 <OMKPvmSvmLink.h> 00019 00020 #include <pvm3.h> 00021 00022 #include <OMKPvmMessage.h> 00023 #include <OMKController.h> 00024 #include "OMKPvmException.h" 00025 using namespace std ; 00026 using namespace OMK ; 00027 00028 //----------------------------------------------------------------------------- 00029 00030 PvmSvmLink::PvmSvmLink (int td) : 00031 SvmLink(), 00032 _outgoingBuffer ( td ), 00033 _distantSiteId ( td ) 00034 { 00035 } 00036 00037 //----------------------------------------------------------------------------- 00038 00039 PvmSvmLink::~PvmSvmLink() 00040 { 00041 } 00042 00043 00044 00045 void PvmSvmLink::send (PvmOutgoingMessage & m, PvmMessage::MessageTag tag) 00046 { 00047 m.send ( tag ) ; 00048 } 00049 00050 00051 00052 void PvmSvmLink::sendOutgoingBuffer(PvmMessage::MessageTag tag) 00053 { 00054 #ifdef _DEBUGPVMMESS 00055 cerr << "PvmSvmLink::sendOutgoingBuffer (" << tag <<") "<<endl; 00056 #endif 00057 _outgoingBuffer.send ( tag ) ; 00058 } 00059 00060 //----------------------------------------------------------------------------- 00061 00062 PvmIncomingMessage & PvmSvmLink::waitForMessage(PvmMessage::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 PvmIncomingMessage * PvmSvmLink::testForMessage (PvmMessage::MessageTag tag) 00078 { 00079 #ifdef _DEBUGPVMMESS 00080 cerr << "PvmSvmLink::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 00097 PvmIncomingMessage* PvmSvmLink::testIfRequestUpdateProcessTable (PvmMessage::MessageTag tag) 00098 { 00099 #ifdef _DEBUGPVMMESS 00100 cerr << "PvmSvmLink::testForMessage: tag " <<tag<<endl; 00101 #endif 00102 00103 int res = pvm_nrecv (_distantSiteId, PvmMessage::updateProcessTable) ; 00104 00105 if (res > 0) 00106 { 00107 _incomingBuffer.initialise ( res ); 00108 return &_incomingBuffer ; 00109 } 00110 else 00111 { 00112 return NULL ; 00113 } 00114 } 00117 PvmMessage::MessageTag 00118 PvmSvmLink::testForAnyMessage (PvmIncomingMessage & receiveBuffer) 00119 { 00120 PvmMessage::MessageTag result ; 00121 00122 int bufid = pvm_nrecv ( _distantSiteId, -1 ) ; //test if any message has arrived from distantDiteId 00123 00124 if ( bufid < 0 ) 00125 { 00126 std::cerr<<"Svm::waitForAnyRequests ERROR "; 00127 switch (bufid) 00128 { 00129 case PvmBadParam: 00130 std::cerr<<"giving an invalid tid value, or msgtag < -1"; 00131 break; 00132 case PvmSysErr: 00133 std::cerr<<"pvmd not responding"; 00134 break; 00135 default: 00136 std::cerr<<"unexpected error"; 00137 OMASSERT( false ) ; 00138 } 00139 std::cerr<<std::endl; 00140 } 00141 00142 if ( bufid != 0 ) 00143 { 00144 int bytes ; 00145 int senderSiteId ; 00146 int msgtag ; 00147 int info = pvm_bufinfo( bufid, &bytes , &msgtag , &senderSiteId ) ; 00148 00149 result = static_cast<PvmMessage::MessageTag>(msgtag) ; 00150 00151 if ( info < 0 ) 00152 { 00153 cerr<<"Svm::waitForAnyRequests ERROR in pvm_bufinfo "; 00154 switch (info) 00155 { 00156 case PvmBadParam: 00157 cerr<<"invalid argument"; 00158 break; 00159 case PvmNoSuchBuf: 00160 cerr<<"specified buffer does not exist"; 00161 break; 00162 default: 00163 cerr<<"unexpected error"; 00164 OMASSERT( false ) ; 00165 } 00166 cerr<<endl; 00167 } 00168 } 00169 00170 receiveBuffer.initialise ( bufid ) ; 00171 00172 return result ; 00173 } 00174 00175 //----------------------------------------------------------------------------- 00176 00177 void PvmSvmLink::printDebuggingInformation () 00178 { 00179 cerr << "PvmSvmLink:"<<this<<":printDebuggingInformation:_distantSiteIdant : " << hex << _distantSiteId << dec << endl ; 00180 } 00181 00182 //----------------------------------------------------------------------------- 00183 00184 int PvmSvmLink::getTID () 00185 { 00186 return _distantSiteId ; 00187 } 00188 00189 void PvmSvmLink::pack (OutgoingSynchronisationMessage & out) const 00190 { 00191 out << _distantSiteId ; 00192 } 00193 00194 00195 void PvmSvmLink::unpack (IncomingSynchronisationMessage & in) 00196 { 00197 #ifdef _DEBUGPVMMESS 00198 cerr<<"PvmSvmLink::unpack: "; 00199 #endif 00200 in >> _distantSiteId ; 00201 00202 _outgoingBuffer.setDistantSiteId ( _distantSiteId ) ; 00203 #ifdef _DEBUGPVMMESS 00204 cerr<<"distant site Id: "<<_distantSiteId<<endl; 00205 #endif 00206 } 00207 00208 00209 00210 PvmOutgoingMessage & PvmSvmLink::getOutgoingBuffer () 00211 { 00212 return _outgoingBuffer ; 00213 }
Documentation generated on Mon Jun 9 11:45:57 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |