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 <PsClassicalNameServer.h> 00019 #include <PsName.h> 00020 #include <PsString.h> 00021 #include <PsNameServer.h> 00022 #include <PsPolatorNT.h> 00023 #include <PsPolator.h> 00024 #include "PsnPvmMessage.h" 00025 00026 PsNameServer * PsName::_nameServer = getNameServer() ; 00027 const PsName::idType PsName::_maxReservedId = 18 ; 00028 00029 PsNameServer * 00030 PsName::getNameServer () 00031 { 00032 static bool initialised = false ; 00033 if ( ! initialised ) 00034 { 00035 _nameServer = new PsClassicalNameServer () ; 00036 initialised = true ; 00037 } 00038 return _nameServer ; 00039 } 00040 00041 00042 void 00043 PsName::setNameServer ( PsNameServer * newNameServer ) 00044 { 00045 // the new name server is only installed if it has the same pairs <id,char *> as the old one. 00046 if ( newNameServer->includes( *_nameServer ) ) 00047 { 00048 _nameServer = newNameServer ; 00049 } 00050 else 00051 { 00052 cerr<<"WARNING : the name server wasn't changed because it wasn't equal to the old one"<<endl; 00053 } 00054 } 00055 00056 00057 PsName::PsName(idType i) 00058 { 00059 #ifdef _DEBUGNOMSYM 00060 cerr<<"PsName::PsName(idType i)"<<endl; 00061 #endif 00062 assert ( i < _maxReservedId ) ; 00063 _identifier = i ; 00064 getNameServer()->created( _identifier , this ); 00065 #ifdef _DEBUGNOMSYM 00066 cerr<<"PsName::PsName(idType i) fin"<<endl; 00067 #endif 00068 } 00069 00070 PsName::PsName() 00071 { 00072 #ifdef _DEBUGNOMSYM 00073 cerr<<"PsName::PsName()"<<endl; 00074 #endif 00075 _identifier=0; 00076 getNameServer()->created( _identifier, this ); 00077 #ifdef _DEBUGNOMSYM 00078 cerr<<"PsName::PsName() fin"<<endl; 00079 #endif 00080 } 00081 00082 PsName::PsName(const char * nom) 00083 { 00084 #ifdef _DEBUGNOMSYM 00085 cerr<<"PsName::PsName(const char * "<<(void*)nom<<")"<<endl; 00086 cerr<<"Serveur de Nom = "<<(void*)getNameServer()<<endl; 00087 #endif 00088 _identifier = getNameServer()->getIdentifier(PsString(nom)); 00089 getNameServer()->created( _identifier, this ) ; 00090 #ifdef _DEBUGNOMSYM 00091 cerr<<"PsName::PsName(const char * nom) fin"<<endl; 00092 #endif 00093 } 00094 00095 00096 00097 PsName::PsName(const string & name) 00098 { 00099 #ifdef _DEBUGNOMSYM 00100 cerr<<"PsName::PsName(const string & "<<name<<")"<<endl; 00101 cerr<<"Name server = "<<(void*)getNameServer()<<endl; 00102 #endif 00103 _identifier = getNameServer()->getIdentifier(PsString(name)); 00104 getNameServer()->created( _identifier, this ) ; 00105 #ifdef _DEBUGNOMSYM 00106 cerr<<"PsName::PsName(const string & ) done"<<endl; 00107 #endif 00108 } 00109 00110 00111 00112 PsName::PsName(const PsString & nom) 00113 { 00114 #ifdef _DEBUGNOMSYM 00115 cerr<<"PsName::PsName(const PsString & nom)"<<endl; 00116 #endif 00117 _identifier=getNameServer()->getIdentifier (nom) ; 00118 00119 getNameServer()->created(_identifier, this); 00120 #ifdef _DEBUGNOMSYM 00121 cerr<<"PsName::PsName(const PsString & nom) done"<<endl; 00122 #endif 00123 } 00124 00125 PsName::PsName(const PsName & aCopier) 00126 { 00127 #ifdef _DEBUGNOMSYM 00128 cerr<<"PsName::PsName(const PsName & aCopier)"<<endl; 00129 #endif 00130 00131 _identifier = aCopier._identifier; 00132 getNameServer()->created(_identifier,this); 00133 00134 #ifdef _DEBUGNOMSYM 00135 cerr<<"PsName::PsName(const PsName & aCopier) fait"<<endl; 00136 #endif 00137 } 00138 00139 PsName::~PsName() 00140 { 00141 getNameServer()->deleted( _identifier, this ); 00142 } 00143 00144 00145 00146 PsPolatorNT * PsName::createPolator (void) 00147 { 00148 return new PsPolator<PsName>(); 00149 } 00150 00151 00152 const char * PsName::getCString() const 00153 { 00154 #ifdef _DEBUGNOMSYM 00155 cerr<<"PsName::getCString()"<<endl; 00156 #endif 00157 const char * resul((getNameServer()->getStringAssociatedTo(_identifier)).getCString()); 00158 #ifdef _DEBUGNOMSYM 00159 cerr<<"PsName::getCString() fin"<<endl; 00160 #endif 00161 return resul ; 00162 } 00163 00164 const PsString & PsName::getPsString() const 00165 { 00166 #ifdef _DEBUGNOMSYM 00167 cerr<<"PsName::getPsString()"<<endl; 00168 #endif 00169 return getNameServer()->getStringAssociatedTo(_identifier); 00170 #ifdef _DEBUGNOMSYM 00171 cerr<<"PsName::getPsString() fin"<<endl; 00172 #endif 00173 } 00174 00175 00176 void PsName::insertInStream(ostream & out) const 00177 { 00178 // cerr<<"PsName::insertInStream of id "<<_identifier<<endl; 00179 // cerr<<"PsName::insertInStream of "<<getNameServer()->getStringAssociatedTo(_identifier)<<endl; 00180 out <<getNameServer()->getStringAssociatedTo(_identifier); 00181 } 00182 00183 00184 void PsName::extract(istream & in) 00185 { 00186 PsString nom; 00187 in>>nom; 00188 idType oldIdentifier = _identifier ; 00189 00190 _identifier = getNameServer()->getIdentifier ( nom ); 00191 00192 getNameServer()->created( _identifier, this ); 00193 00194 getNameServer()->deleted( oldIdentifier, this ); 00195 } 00196 00197 00198 00199 00200 00201 00202 PsName & PsName::operator = (const string & original) 00203 { 00204 // copy into onself : creation must happen before deletion 00205 idType oldIdentifier = _identifier ; 00206 00207 _identifier = getNameServer()->getIdentifier( original ); 00208 00209 getNameServer()->created(_identifier, this); 00210 00211 getNameServer()->deleted( oldIdentifier, this ); 00212 00213 return *this; 00214 } 00215 00216 00217 PsName & PsName::operator = (const char * original) 00218 { 00219 // copy into onself 00220 idType oldIdentifier = _identifier ; 00221 00222 _identifier = getNameServer()->getIdentifier( original ); 00223 getNameServer()->created( _identifier, this ); 00224 00225 getNameServer()->deleted( oldIdentifier, this ); 00226 00227 return *this; 00228 } 00229 00230 00231 PsName & PsName::operator = (const PsString & original) 00232 { 00233 // copy into onself 00234 idType oldIdentifier = _identifier ; 00235 00236 _identifier = getNameServer()->getIdentifier( original ); 00237 getNameServer()->created( _identifier, this ); 00238 00239 getNameServer()->deleted( oldIdentifier, this ); 00240 00241 return *this; 00242 } 00243 00244 00245 PsName & PsName::operator = (const PsName & aCopier) 00246 { 00247 // copy into onself 00248 idType oldIdentifier = _identifier ; 00249 00250 _identifier=aCopier._identifier; 00251 getNameServer()->created( _identifier, this ); 00252 00253 getNameServer()->deleted( oldIdentifier, this ); 00254 00255 return *this; 00256 } 00257 00258 00259 int operator < (const PsName & premier, const PsName & second) 00260 { 00261 return premier._identifier < second._identifier; 00262 } 00263 00264 00265 int operator > (const PsName & premier, const PsName & second) 00266 { 00267 return premier._identifier > second._identifier; 00268 } 00269 00270 00271 int operator <= (const PsName & premier, const PsName & second) 00272 { 00273 return premier._identifier <= second._identifier; 00274 } 00275 00276 00277 00278 int operator >= (const PsName & premier, const PsName & second) 00279 { 00280 return premier._identifier >= second._identifier; 00281 } 00282 00283 00284 void PsName::unpack (PsIncomingSynchronisationMessage & in ) 00285 { 00286 idType oldIdentifier = _identifier ; 00287 00288 in>>_identifier ; 00289 getNameServer()->created( _identifier, this ); 00290 00291 getNameServer()->deleted( oldIdentifier, this ); 00292 } 00293 00294 00295 void PsName::pack (PsOutgoingSynchronisationMessage & out) const 00296 { 00297 out<<_identifier ; 00298 } 00299 00300 void PsName::changeId ( idType oldId, idType newId ) 00301 { 00302 //cerr<<"PsName::changeId ( "<<oldId<<", "<<newId<<" ) "<<endl; 00303 //this is called by the name server : do not need to call back to keep the books 00304 assert ( oldId == _identifier ) ; 00305 00306 _identifier = newId ; 00307 } 00308 00309 00310 00311
| Documentation generated on Mon Nov 25 15:25:00 2002 |
Generated with doxygen 1.2.12 by Dimitri van Heesch , 1997-2001 |