00001 #ifdef _PVM 00002 #include "PsPvmCentralNameServer.h" 00003 00004 #include <stdio.h> 00005 #include "pvm3.h" 00006 #include "PsnSvmLink.h" 00007 #include "PsController.h" 00008 00009 #include "PsnPvmMessage.h" 00010 #include "PsnPvmSvm.h" 00011 00012 PsPvmCentralNameServer::PsPvmCentralNameServer ( const PsNameServer & nameServer ) : 00013 PsClassicalNameServer ( nameServer.getCanonicalRepresentation() ) 00014 { 00015 00016 correspondenceContainerType::const_iterator i ; 00017 for ( i = _stringToIdCorrespondenceContainer.begin() ; 00018 i != _stringToIdCorrespondenceContainer.end(); 00019 ++i ) 00020 { 00021 _idToNamesUsingIdContainer.insert(placeOfNamesContainerType::value_type((*i).second, 00022 new list<PsName *>(nameServer.getNamesOfId ((*i).second) ) ) ) ; 00023 00024 assert ( (*_idToNamesUsingIdContainer.find((*i).second)).second->size() == _tableNbInstances[(*i).second] ) ; 00025 } 00026 } 00027 00028 00029 00030 PsPvmCentralNameServer::~PsPvmCentralNameServer () 00031 { 00032 00033 } 00034 00035 00036 void PsPvmCentralNameServer::verifyCompatibilityWithLocalNameServer (int distantTid, 00037 PsnPvmIncomingMessage & receivedMessage) 00038 { 00039 map<PsName::idType, PsName::idType> listOfNeededConversions ; 00040 int numberOfIncompatibilities = 0 ; 00041 long numberOfElements ; 00042 int stringLength ; 00043 long receivedId; 00044 char * receivedString = NULL ; 00045 00046 receivedMessage >> numberOfElements ; 00047 for ( long i = 0 ; i < numberOfElements ; ++ i) 00048 { 00049 receivedMessage >> stringLength ; 00050 if ( receivedString != NULL ) delete [] receivedString ; 00051 receivedString = new char [stringLength] ; 00052 receivedMessage >> receivedString ; 00053 receivedMessage >> receivedId ; 00054 fastStringAccessTableType::iterator foundIterator = _fastStringAccessTable.find(receivedId) ; 00055 if ( foundIterator == _fastStringAccessTable.end() ) 00056 { 00057 //the id is unknown to the central name server 00058 // either the received String is also unknown or a permutation is necessary 00059 //Therefore, add the sent pair 00060 PsString receivedPsString (receivedString ) ; 00061 correspondenceContainerType::iterator foundReceivedString = _stringToIdCorrespondenceContainer.find( receivedPsString ); 00062 if ( foundReceivedString == _stringToIdCorrespondenceContainer.end() ) 00063 { 00064 pair<correspondenceContainerType::iterator,bool> res = _stringToIdCorrespondenceContainer.insert(correspondenceContainerType::value_type(PsString (receivedString), receivedId)) ; 00065 _fastStringAccessTable[receivedId] = res.first ; 00066 00067 if ( receivedId >= _nextIdentifier ) 00068 { 00069 _nextIdentifier = receivedId + 1 ; 00070 } 00071 cerr<<"Added Id "<<receivedId<<" for "<<receivedString<<endl; 00072 } 00073 else 00074 { 00075 PsName::idType correctId = (*foundReceivedString).second ; 00076 cerr<<"Correct id for "<<receivedString<<" is "<<correctId<<" and not "<<receivedId<<endl; 00077 listOfNeededConversions[receivedId] = correctId ; 00078 ++numberOfIncompatibilities ; 00079 } 00080 } 00081 else 00082 { 00083 if ( (*(*foundIterator).second).first != PsString ( receivedString ) ) 00084 { 00085 //find the id corresponding to the string 00086 PsName::idType correctId = getIdentifier (receivedString) ; 00087 cerr<<"Correct id for "<<receivedString<<" is "<<correctId<<" and not "<<receivedId<<endl; 00088 listOfNeededConversions[receivedId] = correctId ; 00089 ++numberOfIncompatibilities ; 00090 } 00091 } 00092 } 00093 00094 int oldbufid = pvm_setsbuf ( 0 ) ; //save the current send buffer 00095 int bufid = pvm_initsend( PsnPvmSvm::pvmDataEncoding ) ; 00096 if ( bufid < 0 ) 00097 { 00098 cerr<<"PsPvmCentralNameServer::PsPvmCentralNameServer: pvm_initsend error "<<bufid<<endl; 00099 if (PsController::warningLevel == PsController::FatalWarnings ) exit (2) ; 00100 } 00101 00102 int info = pvm_pkint ( &numberOfIncompatibilities, 1, 1 ) ; 00103 00104 if (info < 0 ) 00105 { 00106 cerr<<"PsPvmCentralNameServer::PsPvmCentralNameServer: pvm_pkint error "<<info<<endl; 00107 if (PsController::warningLevel == PsController::FatalWarnings ) exit (2) ; 00108 } 00109 00110 assert (listOfNeededConversions.size() == numberOfIncompatibilities ) ; 00111 00112 for ( map<PsName::idType, PsName::idType>::iterator j = listOfNeededConversions.begin() ; 00113 j != listOfNeededConversions.end() ; 00114 ++j ) 00115 { 00116 pvm_pklong ( const_cast<PsName::idType *>(&((*j).first)) , 1 , 1 ) ; 00117 pvm_pklong ( &((*j).second) , 1 , 1 ) ; 00118 } 00119 00120 info = pvm_send (distantTid, PsnPvmMessage::NameServiceVerifyResult ) ; 00121 00122 if (info < 0 ) 00123 { 00124 cerr<<"PsPvmCentralNameServer::PsPvmCentralNameServer: pvm_send error "<<info<<endl; 00125 if (PsController::warningLevel == PsController::FatalWarnings ) exit (2) ; 00126 } 00127 00128 info = pvm_setsbuf ( oldbufid ) ; //restore the old send buffer 00129 00130 } 00131 #endif 00132 00133
| Documentation generated on Mon Nov 25 15:25:02 2002 |
Generated with doxygen 1.2.12 by Dimitri van Heesch , 1997-2001 |