OMKPvmCentralNameServer.cxx

Go to the documentation of this file.
00001 #include "OMKPvmCentralNameServer.h"
00002 
00003 #include <pvm3.h>
00004 #include "OMKSvmLink.h"
00005 #include "OMKController.h"
00006 
00007 #include "OMKPvmMessage.h"
00008 #include "OMKPvmSvm.h"
00009 using namespace std ;
00010 using namespace OMK ;
00011 
00012 PvmCentralNameServer::PvmCentralNameServer ( const NameServer & nameServer ) :
00013   NameServer ( 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<Name *>(nameServer.getNamesOfId ((*i).second) ) ) ) ;
00023 
00024          OMASSERT( (*_idToNamesUsingIdContainer.find((*i).second)).second->size() == _tableNbInstances[(*i).second] ) ;
00025       }
00026 }
00027 
00028 
00029 
00030 PvmCentralNameServer::~PvmCentralNameServer () 
00031 {
00032 
00033 } 
00034 
00035 
00036 void PvmCentralNameServer::verifyCompatibilityWithLocalNameServer (int distantTid,
00037                                                                      PvmIncomingMessage & receivedMessage) 
00038 {
00039   std::map<Name::idType, Name::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       correspondenceContainerType::iterator foundReceivedString = _stringToIdCorrespondenceContainer.find( std::string( receivedString ) );
00061       if ( foundReceivedString == _stringToIdCorrespondenceContainer.end() )
00062       {
00063         pair<correspondenceContainerType::iterator,bool> res = _stringToIdCorrespondenceContainer.insert(correspondenceContainerType::value_type( std::string( receivedString ), receivedId ) ) ; 
00064         _fastStringAccessTable[receivedId] = res.first ;
00065 
00066         if ( receivedId >= _nextIdentifier ) 
00067         {
00068           _nextIdentifier = receivedId + 1 ;
00069         }
00070         cerr<<"Added Id "<<receivedId<<" for "<<receivedString<<endl;
00071       }
00072       else
00073       {
00074         Name::idType correctId = (*foundReceivedString).second ;
00075         cerr<<"Correct id for "<<receivedString<<" is "<<correctId<<" and not "<<receivedId<<endl;
00076         listOfNeededConversions[receivedId] = correctId ;
00077         ++numberOfIncompatibilities ;
00078       }
00079     }
00080     else 
00081     {
00082       if ( (*(*foundIterator).second).first  != std::string( receivedString ) )
00083       {
00084         //find the id corresponding to the string
00085         Name::idType correctId = getIdentifier (receivedString) ;
00086         cerr<<"Correct id for "<<receivedString<<" is "<<correctId<<" and not "<<receivedId<<endl;
00087         listOfNeededConversions[receivedId] = correctId ;
00088         ++numberOfIncompatibilities ;
00089       }
00090     }
00091   }
00092 
00093   int oldbufid = pvm_setsbuf ( 0 ) ; //save the current send buffer 
00094   int bufid = pvm_initsend( PvmSvm::pvmDataEncoding ) ; 
00095   if ( bufid < 0 )
00096   {
00097     cerr<<"PvmCentralNameServer::PvmCentralNameServer: pvm_initsend error "<<bufid<<endl;
00098     OMASSERT( false ) ;
00099   }
00100 
00101   int info = pvm_pkint ( &numberOfIncompatibilities, 1, 1 ) ;
00102 
00103   if (info < 0 )
00104   {
00105     cerr<<"PvmCentralNameServer::PvmCentralNameServer: pvm_pkint error "<<info<<endl;
00106     OMASSERT( false ) ;
00107   }
00108 
00109   OMASSERT (listOfNeededConversions.size() == numberOfIncompatibilities ) ;
00110 
00111   for ( std::map<Name::idType, Name::idType>::iterator  j = listOfNeededConversions.begin() ;
00112     j != listOfNeededConversions.end() ;
00113     ++j )
00114   {
00115     pvm_pklong ( const_cast<Name::idType *>(&((*j).first)) , 1 , 1 ) ;
00116     pvm_pklong ( &((*j).second) , 1 , 1 ) ;
00117   }
00118 
00119   info = pvm_send (distantTid, PvmMessage::NameServiceVerifyResult ) ;
00120 
00121   if (info < 0 )
00122   {
00123     cerr<<"PvmCentralNameServer::PvmCentralNameServer: pvm_send error "<<info<<endl;
00124     OMASSERT( false ) ;
00125   }
00126 
00127   info = pvm_setsbuf ( oldbufid ) ; //restore the old send buffer
00128 
00129 }
00130 
00131 

logo OpenMask

Documentation generated on Mon Jun 9 11:45:57 2008

Generated with doxygen by Dimitri van Heesch ,   1997-2007