OMK::PvmCentralNameServer Class Reference

a central name servers for the PVm version of OpenMASK More...

#include <OMKPvmCentralNameServer.h>

Inheritance diagram for OMK::PvmCentralNameServer:

Inheritance graph
[legend]
Collaboration diagram for OMK::PvmCentralNameServer:

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual ~PvmCentralNameServer ()
 destructor
 PvmCentralNameServer (const NameServer &origServer)
 copy constructor
virtual void verifyCompatibilityWithLocalNameServer (int distantTid, PvmIncomingMessage &receivedMessage)
 a member function to test and correct Id to Sting known by the local servers

Detailed Description

a central name servers for the PVm version of OpenMASK

Author:
David Margery
Version:
1.0

Definition at line 16 of file OMKPvmCentralNameServer.h.


Constructor & Destructor Documentation

PvmCentralNameServer::~PvmCentralNameServer (  )  [virtual]

destructor

Definition at line 30 of file OMKPvmCentralNameServer.cxx.

00031 {
00032 
00033 } 

PvmCentralNameServer::PvmCentralNameServer ( const NameServer origServer  ) 

copy constructor

Definition at line 12 of file OMKPvmCentralNameServer.cxx.

References OMK::NameServer::_idToNamesUsingIdContainer, OMK::NameServer::_stringToIdCorrespondenceContainer, OMK::NameServer::_tableNbInstances, OMK::NameServer::getNamesOfId(), and OMASSERT.

00012                                                                            :
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 }


Member Function Documentation

void PvmCentralNameServer::verifyCompatibilityWithLocalNameServer ( int  distantTid,
PvmIncomingMessage receivedMessage 
) [virtual]

a member function to test and correct Id to Sting known by the local servers

Definition at line 36 of file OMKPvmCentralNameServer.cxx.

References OMK::NameServer::_fastStringAccessTable, OMK::NameServer::_nextIdentifier, OMK::NameServer::_stringToIdCorrespondenceContainer, OMK::NameServer::getIdentifier(), OMK::PvmMessage::NameServiceVerifyResult, OMASSERT, and OMK::PvmSvm::pvmDataEncoding.

Referenced by OMK::Svm::serveNameRequestsUntilEnd().

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 }


logo OpenMask

Documentation generated on Mon Jun 9 11:46:03 2008

Generated with doxygen by Dimitri van Heesch ,   1997-2007