From: prascle Date: Wed, 2 Nov 2005 15:51:32 +0000 (+0000) Subject: PR: Naming Service Comments, add unit tests X-Git-Tag: BR_UT_V310a2_20051115~12 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ac04c017cf0e1d5866fac6ca66b68bb652697395;p=modules%2Fkernel.git PR: Naming Service Comments, add unit tests --- diff --git a/src/LifeCycleCORBA/Test/Makefile.in b/src/LifeCycleCORBA/Test/Makefile.in index dff2dac82..50253ddf5 100644 --- a/src/LifeCycleCORBA/Test/Makefile.in +++ b/src/LifeCycleCORBA/Test/Makefile.in @@ -62,7 +62,8 @@ LDFLAGSFORBIN+= \ -lSALOMELocalTraceTest -lSALOMELocalTrace -lSALOMEBasics \ -lSALOMETraceCollectorTest \ -lUtilsTest -lOpUtil \ - -lSalomeNS -lSalomeContainer -lSalomeResourcesManager \ + -lNamingServiceTest -lSalomeNS \ + -lSalomeContainer -lSalomeResourcesManager \ -lRegistry -lSalomeNotification \ -lLifeCycleCORBATest -lSalomeLifeCycleCORBA diff --git a/src/LifeCycleCORBA/Test/TestLifeCycleCORBA.cxx b/src/LifeCycleCORBA/Test/TestLifeCycleCORBA.cxx index 987e3049c..ee91e638e 100644 --- a/src/LifeCycleCORBA/Test/TestLifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/Test/TestLifeCycleCORBA.cxx @@ -4,6 +4,7 @@ #include "SALOMELocalTraceTest.hxx" #include "SALOMETraceCollectorTest.hxx" #include "UtilsTest.hxx" +#include "NamingServiceTest.hxx" #include "LifeCycleCORBATest.hxx" // --- Registers the fixture into the 'registry' @@ -11,6 +12,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION( SALOMELocalTraceTest ); CPPUNIT_TEST_SUITE_REGISTRATION( SALOMETraceCollectorTest ); CPPUNIT_TEST_SUITE_REGISTRATION( UtilsTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( NamingServiceTest ); CPPUNIT_TEST_SUITE_REGISTRATION( LifeCycleCORBATest ); // --- generic Main program from Basic/Test diff --git a/src/Makefile.in b/src/Makefile.in index 2b5bb4c7d..66f591413 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -76,6 +76,7 @@ ifeq (@cppunit_ok@,yes) Logger/Test \ SALOMETraceCollector/Test \ Utils/Test \ + NamingService/Test \ LifeCycleCORBA/Test \ UnitTests endif diff --git a/src/NamingService/SALOME_NamingService.cxx b/src/NamingService/SALOME_NamingService.cxx index 0692af495..9a9511ef7 100644 --- a/src/NamingService/SALOME_NamingService.cxx +++ b/src/NamingService/SALOME_NamingService.cxx @@ -1,23 +1,23 @@ // SALOME NamingService : wrapping NamingService services // // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org // // // @@ -37,23 +37,28 @@ using namespace std; -//---------------------------------------------------------------------- -/*! Function : SALOME_NamingService - * Purpose : Constructor and Initialisation of _root_context - */ -//---------------------------------------------------------------------- +// ============================================================================ +/*! \brief Default Constructor without ORB reference. + * + * After Default Constructor, one needs to initialize ORB. + * \sa init_orb(CORBA::ORB_ptr orb), SALOME_NamingService(CORBA::ORB_ptr orb) + */ +// ============================================================================ SALOME_NamingService::SALOME_NamingService() { MESSAGE("SALOME_NamingService default constructor"); _orb = CORBA::ORB::_nil(); + _root_context = CosNaming::NamingContext::_nil(); } -//---------------------------------------------------------------------- -/*! Function : SALOME_NamingService +// ============================================================================ +/*! \brief Standard Constructor, with ORB reference. + * + * Initializes the naming service root context * \param orb CORBA::ORB_ptr arguments - */ -//---------------------------------------------------------------------- + */ +// ============================================================================ SALOME_NamingService::SALOME_NamingService(CORBA::ORB_ptr orb) { @@ -62,421 +67,534 @@ SALOME_NamingService::SALOME_NamingService(CORBA::ORB_ptr orb) _initialize_root_context(); } -//---------------------------------------------------------------------- -/*! Function : ~SALOME_NamingService - * Purpose : Destructor - */ -//---------------------------------------------------------------------- +// ============================================================================ +/*! \brief Standard destructor. + * + * The standard destructor does nothing special. + */ +// ============================================================================ SALOME_NamingService::~SALOME_NamingService() { - // Problem MESSAGE with singleton: late destruction, after trace system destruction ? + // Problem MESSAGE with singleton: late destruction, + // after trace system destruction ? //MESSAGE("SALOME_NamingService destruction"); } -//---------------------------------------------------------------------- -/*! Function : init_orb - * initialize ORB reference after default constructor - */ -//---------------------------------------------------------------------- +// ============================================================================ +/*! \brief initializes ORB reference and naming service root context. + * + * Initializes ORB reference and naming service root context. + * For use after default constructor. + * \param orb CORBA::ORB_ptr arguments + */ +// ============================================================================ void SALOME_NamingService::init_orb(CORBA::ORB_ptr orb) { MESSAGE("SALOME_NamingService initialisation"); - Utils_Locker lock(&_myMutex); - _orb = orb ; + + Utils_Locker lock (&_myMutex); + _orb = orb; + _initialize_root_context(); } -//---------------------------------------------------------------------- -/*! Function : Register - * Method to create an association in the NamingService between ObjRef - * and Path. - * If the NamingService is out, the exception ServiceUnreachable is thrown - * \param ObjRef CORBA::Object_ptr arguments - * \param Path const char* arguments +// ============================================================================ +/*! \brief Registers a CORBA object reference under a path. + * + * Registers a CORBA object reference under a path. + * If the NamingService is out, the exception ServiceUnreachable is thrown. + * \param ObjRef CORBA object reference to associate to the path. + * \param Path A relative or absolute pathname to store the object reference. + * If the pathname begins with a '/', pathname is taken + * as an absolute oathname. Else, pathname is taken as a relative + * path, to current context. Prefer absolute pathname, relative + * pathname are not safe, when SALOME_NamingService object is + * shared or use in multithreaded context. + * \sa Change_Directory(const char* Path), + * CORBA::Object_ptr Resolve(const char* Path) */ -//---------------------------------------------------------------------- +// ============================================================================ void SALOME_NamingService::Register(CORBA::Object_ptr ObjRef, - const char* Path) + const char* Path) throw(ServiceUnreachable) { - MESSAGE("BEGIN OF Register: "<< Path); - Utils_Locker lock(&_myMutex); + MESSAGE("BEGIN OF Register: " << Path); + + Utils_Locker lock (&_myMutex); int dimension_Path = strlen(Path) + 1; - char** resultat_resolve_Path = new char* [dimension_Path]; - // _current_context is replaced to the _root_context - // if the Path begins whith '/' - if (Path[0]=='/') { - _current_context = _root_context; - // MESSAGE("Gone to the _root_context"); - } - - //the resolution of the directory path has to be done - //to place the currect_context to the correct node + char** resultat_resolve_Path = new char * [dimension_Path]; + + // --- _current_context is replaced to the _root_context + // if the Path begins whith '/' + + if (Path[0] == '/') + { + _current_context = _root_context; + } + + // --- the resolution of the directory path has to be done + // to place the current_context to the correct node + int dimension_resultat = 0; + _result_resolve_Path (Path, dimension_resultat, resultat_resolve_Path); - + CosNaming::Name _context_name; CORBA::Boolean _not_exist = false ; + CosNaming::NamingContext_var _temp_context; - - if(dimension_resultat>1) - { - // A directory is treated (not only an object name) - // We had to test if the directory where ObjRef should be recorded - // is already done - // If not, the new context has to be created - // MESSAGE("A complet Path has to be treated, not only an object name"); - _context_name.length(dimension_resultat-1); + if (dimension_resultat > 1) + { + // A directory is treated (not only an object name) + // test if the directory where ObjRef should be recorded already exists + // If not, create the new context - _create_context_name_dir(resultat_resolve_Path,dimension_resultat-1, - _context_name); + _context_name.length(dimension_resultat - 1); + _create_context_name_dir(resultat_resolve_Path, + dimension_resultat - 1, + _context_name); try - { - CORBA::Object_var _obj = _current_context->resolve(_context_name); - _current_context = CosNaming::NamingContext::_narrow(_obj); - } - catch (CosNaming::NamingContext::NotFound &) - { - // failed to resolve, therefore assume cold start - _not_exist = true; - } - catch (CosNaming::NamingContext::InvalidName &) - { - INFOS("!!!Register() : CosNaming::NamingContext::InvalidName"); - } + { + CORBA::Object_var _obj = _current_context->resolve(_context_name); + _current_context = CosNaming::NamingContext::_narrow(_obj); + } + + catch (CosNaming::NamingContext::NotFound &) + { + // --- failed to resolve, therefore assume cold start + _not_exist = true; + } + + catch (CosNaming::NamingContext::InvalidName &) + { + INFOS("Register() : CosNaming::NamingContext::InvalidName"); + } + catch (CosNaming::NamingContext::CannotProceed &) - { - INFOS("!!!Register() : CosNaming::NamingContext::CannotProceed"); - } - catch(CORBA::SystemException&) - { - INFOS("!!!Register() : CORBA::SystemException : unable to contact" - << " the naming service"); - throw ServiceUnreachable(); - } - if(_not_exist) - { - try - { - _context_name.length(1); - // MESSAGE("The Path indicated is not yet created. It will soon be done"); - for (int i = 0 ; i resolve(_context_name); - _current_context = - CosNaming::NamingContext::_narrow(_obj); - //MESSAGE("This context was already created"); - } - catch (CosNaming::NamingContext::NotFound &) - { - // This context is not created. It will be done - _temp_context = - _current_context->bind_new_context(_context_name); - _current_context = _temp_context; - //INFOS("This context was'nt created, it's now done"); - } - } - } - catch (CosNaming::NamingContext::AlreadyBound&) - { - INFOS("!!!Register() : CosNaming::NamingContext::AlreadyBound"); - } - catch(CosNaming::NamingContext::NotFound& ex) - { - CosNaming::Name n = ex.rest_of_name; - if (ex.why == CosNaming::NamingContext::missing_node) - INFOS("Register() : " << (char *) n[0].id - << " (" << (char *) n[0].kind << ") not found"); - if (ex.why == CosNaming::NamingContext::not_context) - INFOS("Register() : " << (char *) n[0].id - << " (" << (char *) n[0].kind - << ") is not a context"); - if (ex.why == CosNaming::NamingContext::not_object) - INFOS("Register() : " << (char *) n[0].id - << " (" << (char *) n[0].kind - << ") is not an object"); - } - catch(CosNaming::NamingContext::CannotProceed&) - { - INFOS("!!!Register() : CosNaming::NamingContext::CannotProceed"); - } - catch(CosNaming::NamingContext::InvalidName&) - { - INFOS("!!!Register() : CosNaming::NamingContext::InvalidName"); - } - catch(CORBA::SystemException&) - { - INFOS("!!!Register() :CORBA::SystemException : unable to contact" - << " the naming service"); - throw ServiceUnreachable(); - } - } + { + INFOS("Register() : CosNaming::NamingContext::CannotProceed"); + } + + catch (CORBA::SystemException&) + { + INFOS("Register() : CORBA::SystemException: " + << "unable to contact the naming service"); + throw ServiceUnreachable(); + } + + if (_not_exist) + { + try + { + _context_name.length(1); + for (int i = 0 ; i < dimension_resultat - 1 ;i++) + { + _context_name[0].id = + CORBA::string_dup(resultat_resolve_Path[i]); + _context_name[0].kind = CORBA::string_dup("dir"); + // SCRUTE(_context_name[0].id); + // --- check if the path is created + try + { + // --- if the context is already created, nothing to do + CORBA::Object_var _obj = + _current_context->resolve(_context_name); + _current_context = + CosNaming::NamingContext::_narrow(_obj); + } + + catch (CosNaming::NamingContext::NotFound &) + { + // --- the context must be created + _temp_context = + _current_context->bind_new_context(_context_name); + _current_context = _temp_context; + } + } + } + + catch (CosNaming::NamingContext::AlreadyBound&) + { + INFOS("Register() : CosNaming::NamingContext::AlreadyBound"); + } + + catch (CosNaming::NamingContext::NotFound& ex) + { + CosNaming::Name n = ex.rest_of_name; + + if (ex.why == CosNaming::NamingContext::missing_node) + INFOS("Register() : " << (char *) n[0].id + << " (" << (char *) n[0].kind << ") not found"); + + if (ex.why == CosNaming::NamingContext::not_context) + INFOS("Register() : " << (char *) n[0].id + << " (" << (char *) n[0].kind + << ") is not a context"); + + if (ex.why == CosNaming::NamingContext::not_object) + INFOS("Register() : " << (char *) n[0].id + << " (" << (char *) n[0].kind + << ") is not an object"); + } + + catch (CosNaming::NamingContext::CannotProceed&) + { + INFOS("Register(): CosNaming::NamingContext::CannotProceed"); + } + + catch (CosNaming::NamingContext::InvalidName&) + { + INFOS("Register(): CosNaming::NamingContext::InvalidName"); + } + + catch (CORBA::SystemException&) + { + INFOS("Register():CORBA::SystemException: " + << "unable to contact the naming service"); + throw ServiceUnreachable(); + } + } } - // The current directory is now the directory where the object should - // be recorded + // --- The current directory is now the directory where the object should + // be recorded + _context_name.length(1); - try + + try { - // the last element is an object an not a directory - _context_name[0].id = - CORBA::string_dup(resultat_resolve_Path[dimension_resultat -1]); + // --- the last element is an object and not a directory + + _context_name[0].id = + CORBA::string_dup(resultat_resolve_Path[dimension_resultat - 1]); _context_name[0].kind = CORBA::string_dup("object"); //SCRUTE(_context_name[0].id); - + _current_context->bind(_context_name, ObjRef); - // MESSAGE("A new element " << _context_name[0].id - // << " is recorded in the _current_context"); } - catch(CosNaming::NamingContext::NotFound& ex) + + catch (CosNaming::NamingContext::NotFound& ex) { CosNaming::Name n = ex.rest_of_name; + if (ex.why == CosNaming::NamingContext::missing_node) - INFOS("Register() : " << (char *) n[0].id - << " (" << (char *) n[0].kind << ") not found"); + INFOS("Register() : " << (char *) n[0].id + << " (" << (char *) n[0].kind << ") not found"); + if (ex.why == CosNaming::NamingContext::not_context) - INFOS("Register() : " << (char *) n[0].id - << " (" << (char *) n[0].kind - << ") is not a context"); + INFOS("Register() : " << (char *) n[0].id + << " (" << (char *) n[0].kind + << ") is not a context"); + if (ex.why == CosNaming::NamingContext::not_object) - INFOS("Register() : " << (char *) n[0].id - << " (" << (char *) n[0].kind - << ") is not an object"); + INFOS("Register() : " << (char *) n[0].id + << " (" << (char *) n[0].kind + << ") is not an object"); } - catch(CosNaming::NamingContext::CannotProceed&) + + catch (CosNaming::NamingContext::CannotProceed&) { - INFOS("!!!Register() : CosNaming::NamingContext::CannotProceed"); - } - catch(CosNaming::NamingContext::InvalidName&) + INFOS("Register(): CosNaming::NamingContext::CannotProceed"); + } + + catch (CosNaming::NamingContext::InvalidName&) { - INFOS("!!!Register() : CosNaming::NamingContext::InvalidName"); + INFOS("Register(): CosNaming::NamingContext::InvalidName"); } - catch(CosNaming::NamingContext::AlreadyBound&) + + catch (CosNaming::NamingContext::AlreadyBound&) { - INFOS("!!!Register() : CosNaming::NamingContext::AlreadyBound, object will be rebind"); + INFOS("Register(): CosNaming::NamingContext::AlreadyBound, " + << "object will be rebind"); _current_context->rebind(_context_name, ObjRef); } - catch(CORBA::SystemException&) + + catch (CORBA::SystemException&) { - INFOS("!!!Register() :CORBA::SystemException : unable to contact" - << " the naming service"); + INFOS("!!!Register(): CORBA::SystemException: " + << "unable to contact the naming service"); throw ServiceUnreachable(); } - - - // Memory destruction - for (int i = 0 ; i resolve(_context_name); + _obj = _current_context->resolve(_context_name); } - catch(CosNaming::NamingContext::NotFound& ex) + + catch (CosNaming::NamingContext::NotFound& ex) { CosNaming::Name n = ex.rest_of_name; + if (ex.why == CosNaming::NamingContext::missing_node) - INFOS("Resolve() : " << (char *) n[0].id - << " (" << (char *) n[0].kind << ") not found"); + INFOS("Resolve() : " << (char *) n[0].id + << " (" << (char *) n[0].kind << ") not found"); + if (ex.why == CosNaming::NamingContext::not_context) - INFOS("Resolve() : " - << (char *) n[0].id << " (" << (char *) n[0].kind - << ") is not a context"); + INFOS("Resolve() : " + << (char *) n[0].id << " (" << (char *) n[0].kind + << ") is not a context"); + if (ex.why == CosNaming::NamingContext::not_object) - INFOS("Resolve() : " << (char *) n[0].id - << " (" << (char *) n[0].kind - << ") is not an object"); + INFOS("Resolve() : " << (char *) n[0].id + << " (" << (char *) n[0].kind + << ") is not an object"); } - catch(CosNaming::NamingContext::CannotProceed&) + + catch (CosNaming::NamingContext::CannotProceed&) { - INFOS("!!!Resolve() : CosNaming::NamingContext::CannotProceed"); - } - catch(CosNaming::NamingContext::InvalidName&) + INFOS("Resolve(): CosNaming::NamingContext::CannotProceed"); + } + + catch (CosNaming::NamingContext::InvalidName&) { - INFOS("!!!Resolve() : CosNaming::NamingContext::InvalidName"); + INFOS("Resolve(): CosNaming::NamingContext::InvalidName"); } - catch(CORBA::SystemException&) + + catch (CORBA::SystemException&) { - INFOS("!!!Resolve() :CORBA::SystemException : unable to contact" - << "the naming service"); + INFOS("Resolve():CORBA::SystemException : unable to contact" + << "the naming service"); throw ServiceUnreachable(); } - // Memory destruction - for (int i = 0 ; i listElem = list_directory(); vector::iterator its = listElem.begin(); + while (its != listElem.end()) { MESSAGE(*its); + if ((*its).find(name) == 0) { - //string instance = basePath + "/" + *its; return Resolve((*its).c_str()); } + its++; } } + return obj; } -//---------------------------------------------------------------------- -/*! Function : Resolve Component from hostname, containername, componentName and number of prcoessors - * Purpose : method to get the ObjRef of a component +// ============================================================================ +/*! \brief find a component instance from hostname, containername, + * componentName and number of processors + * + * find a component instance from hostname, containername, componentName and + * number of processors. * If the NamingService is out, the exception ServiceUnreachable is thrown - * \param hostname const char* argument - * \param containername const char* argument - * \param componentname const char* argument - * \param nbproc const int argument + * \param hostname name of the machine on which the component is searched. + * \param containername name of the container in which the component is + instanciated. + * \param componentname name of the component we are looking for an existing + instance. + * \param nbproc in case of multi processor machine, container name is + * suffixed with _nbproc. * \return the object reference - */ -//---------------------------------------------------------------------- + */ +// ============================================================================ -CORBA::Object_ptr SALOME_NamingService::ResolveComponent(const char* hostname, const char* containerName, const char* componentName, const int nbproc) +CORBA::Object_ptr +SALOME_NamingService::ResolveComponent(const char* hostname, + const char* containerName, + const char* componentName, + const int nbproc) + throw(ServiceUnreachable) { MESSAGE("ResolveComponent"); - Utils_Locker lock(&_myMutex); - string name="/Containers/"; + Utils_Locker lock (&_myMutex); + + string name = "/Containers/"; + name += hostname; - if( strlen(containerName) != 0 ){ - name += "/"; - if( nbproc >=1 ){ - char *newContainerName = new char[strlen(containerName)+8]; - sprintf(newContainerName,"%s_%d",containerName,nbproc); - name += newContainerName; - } - else - name += containerName; - name += "/"; - name += componentName; - return ResolveFirst(name.c_str()); - } - else { - Change_Directory(name.c_str()); - vector contList = list_directory(); - for(unsigned int ind = 0; ind < contList.size(); ind++){ - name = contList[ind].c_str(); + + if ( strlen(containerName) != 0 ) + { + name += "/"; + + if ( nbproc >= 1 ) + { + char *newContainerName = new char[strlen(containerName) + 8]; + sprintf(newContainerName, "%s_%d", containerName, nbproc); + name += newContainerName; + delete [] newContainerName; + } + + else + name += containerName; + name += "/"; + name += componentName; - CORBA::Object_ptr obj = ResolveFirst(name.c_str()); - if( !CORBA::is_nil(obj) ) - return obj; + + return ResolveFirst(name.c_str()); } - return CORBA::Object::_nil(); - } + else + { + Change_Directory(name.c_str()); + vector contList = list_directory(); + + for (unsigned int ind = 0; ind < contList.size(); ind++) + { + name = contList[ind].c_str(); + name += "/"; + name += componentName; + CORBA::Object_ptr obj = ResolveFirst(name.c_str()); + + if ( !CORBA::is_nil(obj) ) + return obj; + } + + return CORBA::Object::_nil(); + } } +// ============================================================================ +/*! \brief provide a default container name if empty + * + * the given container name is returned unchanged, unless it is empty. + * \param containerName + * \return container name, where empty input is replaced by "FactoryServer" + */ +// ============================================================================ + string SALOME_NamingService::ContainerName(const char *containerName) { string ret; - if (strlen(containerName)== 0) + if (strlen(containerName) == 0) ret = "FactoryServer"; else ret = containerName; @@ -484,52 +602,83 @@ string SALOME_NamingService::ContainerName(const char *containerName) return ret; } -string SALOME_NamingService::ContainerName(const Engines::MachineParameters& params) +// ============================================================================ +/*! \brief build a container name, given a MachineParameters struct. + * + * Build a container name with a MachineParameters struct. In case of multi + * processor machine, container name is suffixed with _nbproc. + * \param MachineParameters struct from which we get container name (may be + * empty), number of nodes and number of processor + * per node. + * \return a container name + */ +// ============================================================================ + +string +SALOME_NamingService::ContainerName(const Engines::MachineParameters& params) { int nbproc; - if( !params.isMPI ) + + if ( !params.isMPI ) nbproc = 0; - else if( (params.nb_node <= 0) && (params.nb_proc_per_node <= 0) ) + else if ( (params.nb_node <= 0) && (params.nb_proc_per_node <= 0) ) nbproc = 1; - else if( params.nb_node == 0 ) + else if ( params.nb_node == 0 ) nbproc = params.nb_proc_per_node; - else if( params.nb_proc_per_node == 0 ) + else if ( params.nb_proc_per_node == 0 ) nbproc = params.nb_node; else nbproc = params.nb_node * params.nb_proc_per_node; - string ret=ContainerName(params.container_name); + string ret = ContainerName(params.container_name); - if( nbproc >=1 ){ - char *suffix = new char[8]; - sprintf(suffix,"_%d",nbproc); - ret += suffix; - } + if ( nbproc >= 1 ) + { + char *suffix = new char[8]; + sprintf(suffix, "_%d", nbproc); + ret += suffix; + } return ret; } -string SALOME_NamingService::BuildContainerNameForNS(const char *containerName, const char *hostname) +// ============================================================================ +/*! + * + */ +// ============================================================================ + +string SALOME_NamingService::BuildContainerNameForNS(const char *containerName, + const char *hostname) { - string ret="/Containers/"; + string ret = "/Containers/"; ret += hostname; - ret+="/"; - ret+=ContainerName(containerName); + ret += "/"; + ret += ContainerName(containerName); return ret; } -string SALOME_NamingService::BuildContainerNameForNS(const Engines::MachineParameters& params, const char *hostname) +// ============================================================================ +/*! + * + */ +// ============================================================================ + +string +SALOME_NamingService:: +BuildContainerNameForNS(const Engines::MachineParameters& params, + const char *hostname) { - string ret="/Containers/"; + string ret = "/Containers/"; ret += hostname; - ret+="/"; - ret+=ContainerName(params); + ret += "/"; + ret += ContainerName(params); return ret; } -//---------------------------------------------------------------------- +// ============================================================================ /*! Function : Find * Purpose : method to research a name from the current directory * of the naming service. @@ -539,169 +688,206 @@ string SALOME_NamingService::BuildContainerNameForNS(const Engines::MachineParam * \param name const char* arguments * \return the number of occurences found * \sa _Find - */ -//---------------------------------------------------------------------- + */ +// ============================================================================ int SALOME_NamingService::Find(const char* name) - throw(ServiceUnreachable) +throw(ServiceUnreachable) { MESSAGE("BEGIN OF Find " << name); - Utils_Locker lock(&_myMutex); - CORBA::Long occurence_number = 0 ; + + Utils_Locker lock (&_myMutex) + + ; + CORBA::Long occurence_number = 0 ; + try { - _Find(name,occurence_number); + _Find(name, occurence_number); } - catch(CORBA::SystemException&) + + catch (CORBA::SystemException&) { INFOS("!!!Find() : CORBA::SystemException : unable to contact" - << " the naming service"); + << " the naming service"); throw ServiceUnreachable(); } + return occurence_number; } -//---------------------------------------------------------------------- -/*! Function : Create_Directory +// ============================================================================ +/*! Function : Create_Directory * Purpose : method to create a directory from the current directory. * If the NamingService is out, the exception ServiceUnreachable is thrown * \param Path const char* arguments * \return a boolean to indicate if the creation succeeded - */ -//---------------------------------------------------------------------- + */ +// ============================================================================ bool SALOME_NamingService::Create_Directory(const char* Path) - throw(ServiceUnreachable) +throw(ServiceUnreachable) { MESSAGE("BEGIN OF Create_Directory"); - Utils_Locker lock(&_myMutex); + + Utils_Locker lock (&_myMutex) + + ; int dimension_Path = strlen(Path) + 1; - char** resultat_resolve_Path= new char* [dimension_Path];; + + char** resultat_resolve_Path = new char * [dimension_Path]; + + ; CORBA::Boolean _return_code = true ; - // _current_context is replaced to the _root_context + // _current_context is replaced to the _root_context // if the Path begins whith '/' - if (Path[0]=='/') _current_context = _root_context; + if (Path[0] == '/') + _current_context = _root_context; int dimension_resultat = 0; + _result_resolve_Path (Path, dimension_resultat, resultat_resolve_Path); - - // We had to test if a part of the directory to treat + + // We had to test if a part of the directory to treat // is already done // If not, the new context has to be created - + CosNaming::Name _context_name; + _context_name.length(1); + CosNaming::NamingContext_var _temp_context; + ASSERT(!CORBA::is_nil(_current_context)); + // Context creation try { - - for (int i = 0 ; i resolve(_context_name); - _current_context = - CosNaming::NamingContext::_narrow(_obj); - MESSAGE("This context was already created"); - } - catch (CosNaming::NamingContext::NotFound &) - { - // This context is not created. It will be done - _temp_context = - _current_context->bind_new_context(_context_name); - _current_context = _temp_context; - INFOS("This context was'nt created, it's now done"); - } - } + + for (int i = 0 ; i < dimension_resultat ;i++) + { + _context_name[0].id = + CORBA::string_dup(resultat_resolve_Path[i]); + _context_name[0].kind = CORBA::string_dup("dir"); + // SCRUTE(_context_name[0].id); + //The Path could be in part already created. + //We had to test it + + try + { + // this context is already created. + // Nothing to be done + CORBA::Object_var _obj = + _current_context->resolve(_context_name); + _current_context = + CosNaming::NamingContext::_narrow(_obj); + MESSAGE("This context was already created"); + } + + catch (CosNaming::NamingContext::NotFound &) + { + // This context is not created. It will be done + _temp_context = + _current_context->bind_new_context(_context_name); + _current_context = _temp_context; + INFOS("This context was'nt created, it's now done"); + } + } } + catch (CosNaming::NamingContext::AlreadyBound&) { INFOS("!!! Create_Directory() CosNaming::NamingContext::AlreadyBound"); - _return_code = false; + _return_code = false; } - catch(CosNaming::NamingContext::NotFound& ex) + + catch (CosNaming::NamingContext::NotFound& ex) { _return_code = false; CosNaming::Name n = ex.rest_of_name; + if (ex.why == CosNaming::NamingContext::missing_node) - INFOS("Create_Directory() : " << (char *) n[0].id - << " (" << (char *) n[0].kind << ") not found"); + INFOS("Create_Directory() : " << (char *) n[0].id + << " (" << (char *) n[0].kind << ") not found"); + if (ex.why == CosNaming::NamingContext::not_context) - INFOS("Create_Directory() : " << (char *) n[0].id - << " (" << (char *) n[0].kind - << ") is not a context"); + INFOS("Create_Directory() : " << (char *) n[0].id + << " (" << (char *) n[0].kind + << ") is not a context"); + if (ex.why == CosNaming::NamingContext::not_object) - INFOS("Create_Directory() : " << (char *) n[0].id - << " (" << (char *) n[0].kind - << ") is not an object"); + INFOS("Create_Directory() : " << (char *) n[0].id + << " (" << (char *) n[0].kind + << ") is not an object"); } - catch(CosNaming::NamingContext::CannotProceed&) + + catch (CosNaming::NamingContext::CannotProceed&) { _return_code = false; - INFOS("!!!Create_Directory():CosNaming::NamingContext::CannotProceed"); - } - catch(CosNaming::NamingContext::InvalidName&) + INFOS("!!!Create_Directory():CosNaming::NamingContext::CannotProceed"); + } + + catch (CosNaming::NamingContext::InvalidName&) { _return_code = false; INFOS("!!!Create_Directory():CosNaming::NamingContext::InvalidName"); } - catch(CORBA::SystemException&) + + catch (CORBA::SystemException&) { _return_code = false; INFOS("!!!Register() :CORBA::SystemException : unable to contact" - << " the naming service"); + << " the naming service"); throw ServiceUnreachable(); } + // Memory destruction - for (int i = 0 ; i resolve(_context_name); - _current_context = CosNaming::NamingContext::_narrow(_obj); - ASSERT(!CORBA::is_nil(_current_context)) - } - catch(CosNaming::NamingContext::NotFound& ex) - { - _return_code = false; - CosNaming::Name n = ex.rest_of_name; - if (ex.why == CosNaming::NamingContext::missing_node) - INFOS( "Change_Directory() : " << (char *) n[0].id - << " (" << (char *) n[0].kind << ") not found") - if (ex.why == CosNaming::NamingContext::not_context) - INFOS("Change_Directory() : " << (char *) n[0].id - << " (" << (char *) n[0].kind - << ") is not a context" ) - if (ex.why == CosNaming::NamingContext::not_object) - INFOS( "Change_Directory() : " << (char *) n[0].id - << " (" << (char *) n[0].kind - << ") is not an object" ) - } - catch(CosNaming::NamingContext::CannotProceed&) - { - _return_code = false; - INFOS( "!!!Change_Directory() : CosNaming::NamingContext::CannotProceed" ) - } - catch(CosNaming::NamingContext::InvalidName&) - { - _return_code = false; - INFOS( "!!!Change_Directory() : CosNaming::NamingContext::InvalidName" ) - } - catch(CORBA::SystemException&) - { - _return_code = false; - INFOS( "!!!Change_Directory() :CORBA::SystemException : unable to contact" - << "the naming service") - throw ServiceUnreachable(); - } + + try + { + _obj = _current_context->resolve(_context_name); + _current_context = CosNaming::NamingContext::_narrow(_obj); + ASSERT(!CORBA::is_nil(_current_context)) + } + + catch (CosNaming::NamingContext::NotFound& ex) + { + _return_code = false; + CosNaming::Name n = ex.rest_of_name; + + if (ex.why == CosNaming::NamingContext::missing_node) + INFOS( "Change_Directory() : " << (char *) n[0].id + << " (" << (char *) n[0].kind << ") not found") + if (ex.why == CosNaming::NamingContext::not_context) + INFOS("Change_Directory() : " << (char *) n[0].id + << " (" << (char *) n[0].kind + << ") is not a context" ) + if (ex.why == CosNaming::NamingContext::not_object) + INFOS( "Change_Directory() : " << (char *) n[0].id + << " (" << (char *) n[0].kind + << ") is not an object" ) + } + + catch (CosNaming::NamingContext::CannotProceed&) + { + _return_code = false; + INFOS( "!!!Change_Directory() : CosNaming::NamingContext::CannotProceed" ) + } + + catch (CosNaming::NamingContext::InvalidName&) + { + _return_code = false; + INFOS( "!!!Change_Directory() : CosNaming::NamingContext::InvalidName" ) + } + + catch (CORBA::SystemException&) + { + _return_code = false; + INFOS( "!!!Change_Directory() :CORBA::SystemException : unable to contact" + << "the naming service") + throw ServiceUnreachable(); + } + // Memory destruction - for (int i = 0 ; i list(nb, _binding_list, _binding_iterator) ; - while (_binding_iterator->next_one(_binding)) { - CosNaming::Name _bindingName = _binding->binding_name; - if (_binding->binding_type == CosNaming::ncontext) { - MESSAGE( "Context : " << _bindingName[0].id ); - try - { - Change_Directory(_bindingName[0].id); - } - catch (ServiceUnreachable&) - { - INFOS( "!!!list(): ServiceUnreachable" ) - throw ServiceUnreachable(); - } + _current_context->list(nb, _binding_list, _binding_iterator) ; - list(); - _current_context = _ref_context ; - } - else if (_binding->binding_type == CosNaming::nobject) { - MESSAGE( "Object : " << _bindingName[0].id ); + while (_binding_iterator->next_one(_binding)) + { + CosNaming::Name _bindingName = _binding->binding_name; + + if (_binding->binding_type == CosNaming::ncontext) + { + MESSAGE( "Context : " << _bindingName[0].id ); + + try + { + Change_Directory(_bindingName[0].id); + } + + catch (ServiceUnreachable&) + { + INFOS( "!!!list(): ServiceUnreachable" ) + throw ServiceUnreachable(); + } + + list(); + _current_context = _ref_context ; + } + + else if (_binding->binding_type == CosNaming::nobject) + { + MESSAGE( "Object : " << _bindingName[0].id ); + } } - } + _binding_iterator->destroy(); } -//---------------------------------------------------------------------- +// ============================================================================ /*! Function : list_directory * Purpose : method to get all the contexts contained in the current * directory * Get only objects, isn't iterative * If the NamingService is out, the exception ServiceUnreachable is thrown */ -//---------------------------------------------------------------------- +// ============================================================================ vector SALOME_NamingService::list_directory() - throw(ServiceUnreachable) +throw(ServiceUnreachable) { vector _list ; _list.resize(0); CosNaming::BindingList_var _binding_list; CosNaming::BindingIterator_var _binding_iterator; - unsigned long nb=0 ; // for using only the BindingIterator to access the bindings + unsigned long nb = 0 ; // for using only the BindingIterator to access the bindings CosNaming::Binding_var _binding ; CosNaming::NamingContext_var _ref_context = _current_context; _current_context->list(nb, _binding_list, _binding_iterator) ; - if (_binding_iterator->_is_nil()) return _list; - while (_binding_iterator->next_one(_binding)) { - CosNaming::Name _bindingName = _binding->binding_name; - if (_binding->binding_type == CosNaming::nobject) { - _list.push_back(CORBA::string_dup(_bindingName[0].id)); + if (_binding_iterator->_is_nil()) + return _list; + + while (_binding_iterator->next_one(_binding)) + { + CosNaming::Name _bindingName = _binding->binding_name; + + if (_binding->binding_type == CosNaming::nobject) + { + _list.push_back(CORBA::string_dup(_bindingName[0].id)); + } } - } + //for (unsigned int ind = 0; ind < _list.size(); ind++) // MESSAGE("list_directory : Object : " << _list[ind]); _binding_iterator->destroy(); + return _list; } -//---------------------------------------------------------------------- +// ============================================================================ /*! Function : list_directory_recurs * Purpose : method to get all the contexts contained in the current * directory * Get only objects and is recursive * If the NamingService is out, the exception ServiceUnreachable is thrown */ -//---------------------------------------------------------------------- +// ============================================================================ + vector SALOME_NamingService::list_directory_recurs() - throw(ServiceUnreachable) +throw(ServiceUnreachable) { MESSAGE("list_directory_recurs"); - Utils_Locker lock(&_myMutex); + + Utils_Locker lock (&_myMutex) + + ; vector _list ; - char *currentDir=Current_Directory(); - _list_directory_recurs(_list,0,currentDir); + + char *currentDir = Current_Directory(); + + _list_directory_recurs(_list, 0, currentDir); + delete [] currentDir; + return _list; } -//---------------------------------------------------------------------- -/*! Function : Destroy_Name +// ============================================================================ +/*! Function : Destroy_Name * Purpose : method to destroy an association Path-Object Reference. * WARNING : The complete Path should be given. * If the NamingService is out, the exception ServiceUnreachable is thrown * \param Path const char* arguments - */ -//---------------------------------------------------------------------- + */ +// ============================================================================ void SALOME_NamingService::Destroy_Name(const char* Path) - throw(ServiceUnreachable) +throw(ServiceUnreachable) { MESSAGE("BEGIN OF Destroy_Name"); - Utils_Locker lock(&_myMutex); + + Utils_Locker lock (&_myMutex) + + ; int dimension_Path = strlen(Path) + 1; - char** resultat_resolve_Path = new char* [dimension_Path]; - // _current_context is replaced to the _root_context + char** resultat_resolve_Path = new char * [dimension_Path]; + + // _current_context is replaced to the _root_context // if the Path begins whith '/' - if (Path[0]=='/') _current_context = _root_context; + if (Path[0] == '/') + _current_context = _root_context; + - //the resolution of the directory path has to be done //to place the currect_context to the correct node int dimension_resultat = 0; + _result_resolve_Path (Path, dimension_resultat, resultat_resolve_Path); - + CosNaming::Name _context_name; - if (dimension_resultat>1) + + if (dimension_resultat > 1) { // We go in the directory where the object to destroy is - _context_name.length(dimension_resultat-1); - - _create_context_name_dir(resultat_resolve_Path,dimension_resultat -1, - _context_name); + _context_name.length(dimension_resultat - 1); + + _create_context_name_dir(resultat_resolve_Path, dimension_resultat - 1, + _context_name); + try - { - CORBA::Object_var _obj = _current_context->resolve(_context_name); - _current_context = CosNaming::NamingContext::_narrow(_obj); - } - catch (CosNaming::NamingContext::NotFound& ex) - { - CosNaming::Name n = ex.rest_of_name; - if (ex.why == CosNaming::NamingContext::missing_node) - INFOS( "Destroy_Name() : " << (char *) n[0].id - << " (" << (char *) n[0].kind << ") not found" ) - if (ex.why == CosNaming::NamingContext::not_context) - INFOS( "Destroy_Name() : " << (char *) n[0].id - << " (" << (char *) n[0].kind - << ") is not a context" ) - if (ex.why == CosNaming::NamingContext::not_object) - INFOS( "Destroy_Name() : " << (char *) n[0].id - << " (" << (char *) n[0].kind - << ") is not an object" ) - } - catch (CosNaming::NamingContext::InvalidName &) - { - INFOS( "!!!Destroy_Name() : CosNaming::NamingContext::InvalidName" ) - } + { + CORBA::Object_var _obj = _current_context->resolve(_context_name); + _current_context = CosNaming::NamingContext::_narrow(_obj); + } + + catch (CosNaming::NamingContext::NotFound& ex) + { + CosNaming::Name n = ex.rest_of_name; + + if (ex.why == CosNaming::NamingContext::missing_node) + INFOS( "Destroy_Name() : " << (char *) n[0].id + << " (" << (char *) n[0].kind << ") not found" ) + if (ex.why == CosNaming::NamingContext::not_context) + INFOS( "Destroy_Name() : " << (char *) n[0].id + << " (" << (char *) n[0].kind + << ") is not a context" ) + if (ex.why == CosNaming::NamingContext::not_object) + INFOS( "Destroy_Name() : " << (char *) n[0].id + << " (" << (char *) n[0].kind + << ") is not an object" ) + } + + catch (CosNaming::NamingContext::InvalidName &) + { + INFOS( "!!!Destroy_Name() : CosNaming::NamingContext::InvalidName" ) + } + catch (CosNaming::NamingContext::CannotProceed &) - { - INFOS( "!!!Destroy_Name(): CosNaming::NamingContext::CannotProceed" ) - } - catch(CORBA::SystemException&) - { - INFOS( "!!!Destroy_Name() : CORBA::SystemException : unable to contact" - << " the naming service") - throw ServiceUnreachable(); - } + { + INFOS( "!!!Destroy_Name(): CosNaming::NamingContext::CannotProceed" ) + } + + catch (CORBA::SystemException&) + { + INFOS( "!!!Destroy_Name() : CORBA::SystemException : unable to contact" + << " the naming service") + throw ServiceUnreachable(); + } } // the last element is the object to destroy - _context_name.length(1); - _context_name[0].id = - CORBA::string_dup(resultat_resolve_Path[dimension_resultat -1]); + _context_name.length(1); + + _context_name[0].id = + CORBA::string_dup(resultat_resolve_Path[dimension_resultat - 1]); + _context_name[0].kind = CORBA::string_dup("object"); + SCRUTE(_context_name[0].id); + ASSERT(!CORBA::is_nil(_current_context)); + // Object destruction - try + try { _current_context->unbind(_context_name); - MESSAGE( "The object " << _context_name[0].id << " has been deleted" ) + MESSAGE( "The object " << _context_name[0].id << " has been deleted" ) } - catch(CosNaming::NamingContext::NotFound& ex) + + catch (CosNaming::NamingContext::NotFound& ex) { CosNaming::Name n = ex.rest_of_name; + if (ex.why == CosNaming::NamingContext::missing_node) - INFOS( "Destroy_Name() : " << (char *) n[0].id - << " (" << (char *) n[0].kind << ") not found" ) - if (ex.why == CosNaming::NamingContext::not_context) - INFOS( "Destroy_Name() : " << (char *) n[0].id - << " (" << (char *) n[0].kind - << ") is not a context" ) - if (ex.why == CosNaming::NamingContext::not_object) - INFOS( "Destroy_Name() : " << (char *) n[0].id - << " (" << (char *) n[0].kind - << ") is not an object" ) - } - catch(CosNaming::NamingContext::CannotProceed&) + INFOS( "Destroy_Name() : " << (char *) n[0].id + << " (" << (char *) n[0].kind << ") not found" ) + if (ex.why == CosNaming::NamingContext::not_context) + INFOS( "Destroy_Name() : " << (char *) n[0].id + << " (" << (char *) n[0].kind + << ") is not a context" ) + if (ex.why == CosNaming::NamingContext::not_object) + INFOS( "Destroy_Name() : " << (char *) n[0].id + << " (" << (char *) n[0].kind + << ") is not an object" ) + } + + catch (CosNaming::NamingContext::CannotProceed&) { INFOS( "!!!Destroy_Name() : CosNaming::NamingContext::CannotProceed") - } - catch(CosNaming::NamingContext::InvalidName&) + } + + catch (CosNaming::NamingContext::InvalidName&) { INFOS( "!!!Destroy_Name() : CosNaming::NamingContext::InvalidName") } - catch(CORBA::SystemException&) + + catch (CORBA::SystemException&) { - INFOS( "!!!Destroy_Name() :CORBA::SystemException : unable to contact" - << " the naming service") + INFOS( "!!!Destroy_Name() :CORBA::SystemException : unable to contact" + << " the naming service") throw ServiceUnreachable(); } + // Memory destruction - for (int i = 0 ; i 1) + + if (dimension_resultat > 1) { // We go in the directory where the context to destroy is - _context_name.length(dimension_resultat-1); - - _create_context_name_dir(resultat_resolve_Path,dimension_resultat -1, - _context_name); + _context_name.length(dimension_resultat - 1); + + _create_context_name_dir(resultat_resolve_Path, dimension_resultat - 1, + _context_name); + try - { - CORBA::Object_var _obj = _current_context->resolve(_context_name); - _current_context = CosNaming::NamingContext::_narrow(_obj); + { + CORBA::Object_var _obj = _current_context->resolve(_context_name); + _current_context = CosNaming::NamingContext::_narrow(_obj); _ref_context = _current_context ; - } - catch (CosNaming::NamingContext::NotFound& ex) - { - CosNaming::Name n = ex.rest_of_name; - if (ex.why == CosNaming::NamingContext::missing_node) - INFOS( "Destroy_Directory() : " << (char *) n[0].id - << " (" << (char *) n[0].kind << ") not found") - if (ex.why == CosNaming::NamingContext::not_context) - INFOS( "Destroy_Directory() : " << (char *) n[0].id - << " (" << (char *) n[0].kind - << ") is not a context" ) - if (ex.why == CosNaming::NamingContext::not_object) - INFOS( "Destroy_Directory() : " << (char *) n[0].id - << " (" << (char *) n[0].kind - << ") is not an object" ) - } - catch (CosNaming::NamingContext::InvalidName &) - { - INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::InvalidName" ) - } + } + + catch (CosNaming::NamingContext::NotFound& ex) + { + CosNaming::Name n = ex.rest_of_name; + + if (ex.why == CosNaming::NamingContext::missing_node) + INFOS( "Destroy_Directory() : " << (char *) n[0].id + << " (" << (char *) n[0].kind << ") not found") + if (ex.why == CosNaming::NamingContext::not_context) + INFOS( "Destroy_Directory() : " << (char *) n[0].id + << " (" << (char *) n[0].kind + << ") is not a context" ) + if (ex.why == CosNaming::NamingContext::not_object) + INFOS( "Destroy_Directory() : " << (char *) n[0].id + << " (" << (char *) n[0].kind + << ") is not an object" ) + } + + catch (CosNaming::NamingContext::InvalidName &) + { + INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::InvalidName" ) + } + catch (CosNaming::NamingContext::CannotProceed &) - { - INFOS("!!!Destroy_Directory(): CosNaming::NamingContext::CannotProceed" ) - } - catch(CORBA::SystemException&) - { - INFOS( "!!!Destroy_Directory() : CORBA::SystemException : unable to contact" - << " the naming service" ) - throw ServiceUnreachable(); - } + { + INFOS("!!!Destroy_Directory(): CosNaming::NamingContext::CannotProceed" ) + } + + catch (CORBA::SystemException&) + { + INFOS( "!!!Destroy_Directory() : CORBA::SystemException : unable to contact" + << " the naming service" ) + throw ServiceUnreachable(); + } } // the last element is the context to destroy - _context_name.length(1); - _context_name[0].id = - CORBA::string_dup(resultat_resolve_Path[dimension_resultat -1]); + _context_name.length(1); + + _context_name[0].id = + CORBA::string_dup(resultat_resolve_Path[dimension_resultat - 1]); + _context_name[0].kind = CORBA::string_dup("dir"); + SCRUTE(_context_name[0].id); try @@ -1134,156 +1414,178 @@ void SALOME_NamingService::Destroy_Directory(const char* Path) // We go in the context to destroy CORBA::Object_var _obj = _current_context->resolve(_context_name); _current_context = CosNaming::NamingContext::_narrow(_obj); - } - catch (CosNaming::NamingContext::NotFound& ex) + } + + catch (CosNaming::NamingContext::NotFound& ex) { CosNaming::Name n = ex.rest_of_name; + if (ex.why == CosNaming::NamingContext::missing_node) - INFOS( "Destroy_Directory() : " << (char *) n[0].id - << " (" << (char *) n[0].kind << ") not found" ) - if (ex.why == CosNaming::NamingContext::not_context) - INFOS( "Destroy_Directory() : " << (char *) n[0].id - << " (" << (char *) n[0].kind - << ") is not a context" ) - if (ex.why == CosNaming::NamingContext::not_object) - INFOS( "Destroy_Directory() : " << (char *) n[0].id - << " (" << (char *) n[0].kind - << ") is not an object" ) - } - catch (CosNaming::NamingContext::InvalidName &) + INFOS( "Destroy_Directory() : " << (char *) n[0].id + << " (" << (char *) n[0].kind << ") not found" ) + if (ex.why == CosNaming::NamingContext::not_context) + INFOS( "Destroy_Directory() : " << (char *) n[0].id + << " (" << (char *) n[0].kind + << ") is not a context" ) + if (ex.why == CosNaming::NamingContext::not_object) + INFOS( "Destroy_Directory() : " << (char *) n[0].id + << " (" << (char *) n[0].kind + << ") is not an object" ) + } + + catch (CosNaming::NamingContext::InvalidName &) { INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::InvalidName" ) } + catch (CosNaming::NamingContext::CannotProceed &) { INFOS( "!!!Destroy_Directory(): CosNaming::NamingContext::CannotProceed" ) } - catch(CORBA::SystemException&) + + catch (CORBA::SystemException&) { INFOS( "!!!Destroy_Directory() : CORBA::SystemException : unable to contact" - << " the naming service" ) + << " the naming service" ) throw ServiceUnreachable(); } ASSERT(!CORBA::is_nil(_current_context)); // Context Destruction - try + + try { _current_context->destroy(); MESSAGE( "The context " << _context_name[0].id << " has been deleted" ) } - catch(CosNaming::NamingContext::NotEmpty&) + + catch (CosNaming::NamingContext::NotEmpty&) { INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::NoEmpty " - << Path << " is not empty" ) - } - catch(CORBA::SystemException&) + << Path << " is not empty" ) + } + + catch (CORBA::SystemException&) { INFOS( "!!!Destroy_Directory() :CORBA::SystemException : " - << "unable to contact the naming service") + << "unable to contact the naming service") throw ServiceUnreachable(); } + // We go to the directory just before the context to delete - _current_context = _ref_context ; + _current_context = _ref_context ; + try { _current_context->unbind(_context_name); - MESSAGE( "The bind to the context " << _context_name[0].id << " has been deleted" ) + MESSAGE( "The bind to the context " << _context_name[0].id << " has been deleted" ) } - catch(CosNaming::NamingContext::NotFound& ex) + + catch (CosNaming::NamingContext::NotFound& ex) { CosNaming::Name n = ex.rest_of_name; + if (ex.why == CosNaming::NamingContext::missing_node) - INFOS( "Destroy_Directory() : " << (char *) n[0].id - << " (" << (char *) n[0].kind << ") not found" ) - if (ex.why == CosNaming::NamingContext::not_context) - INFOS( "Destroy_Directory() : " << (char *) n[0].id - << " (" << (char *) n[0].kind - << ") is not a context" ) - if (ex.why == CosNaming::NamingContext::not_object) - INFOS( "Destroy_Directory() : " << (char *) n[0].id - << " (" << (char *) n[0].kind - << ") is not an object" ) - } - catch(CosNaming::NamingContext::CannotProceed&) + INFOS( "Destroy_Directory() : " << (char *) n[0].id + << " (" << (char *) n[0].kind << ") not found" ) + if (ex.why == CosNaming::NamingContext::not_context) + INFOS( "Destroy_Directory() : " << (char *) n[0].id + << " (" << (char *) n[0].kind + << ") is not a context" ) + if (ex.why == CosNaming::NamingContext::not_object) + INFOS( "Destroy_Directory() : " << (char *) n[0].id + << " (" << (char *) n[0].kind + << ") is not an object" ) + } + + catch (CosNaming::NamingContext::CannotProceed&) { INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::CannotProceed") - } - catch(CosNaming::NamingContext::InvalidName&) + } + + catch (CosNaming::NamingContext::InvalidName&) { INFOS( "!!!Destroy_Directory() : CosNaming::NamingContext::InvalidName") } - catch(CORBA::SystemException&) + + catch (CORBA::SystemException&) { - INFOS( "!!!Destroy_Directory() :CORBA::SystemException : unable to contact" - << " the naming service") + INFOS( "!!!Destroy_Directory() :CORBA::SystemException : unable to contact" + << " the naming service") throw ServiceUnreachable(); } + // Memory destruction - for (int i = 0 ; i contList = list_directory(); - for(unsigned int ind = 0; ind < contList.size(); ind++) + + for (unsigned int ind = 0; ind < contList.size(); ind++) Destroy_Name(contList[ind].c_str()); + Destroy_Directory(Path); + Destroy_Name(Path); } -//---------------------------------------------------------------------- +// ============================================================================ /*! Function : _initialize_root_context * Purpose : method called by constructor to initialize _root_context - */ -//---------------------------------------------------------------------- + */ +// ============================================================================ void SALOME_NamingService::_initialize_root_context() { //MESSAGE("Get the root context"); + try { CORBA::Object_var obj = _orb->resolve_initial_references("NameService"); _root_context = CosNaming::NamingContext::_narrow(obj); _current_context = _root_context ; - ASSERT(!CORBA::is_nil(_root_context)); + ASSERT(!CORBA::is_nil(_root_context)); } - catch(CORBA::SystemException&) + catch (CORBA::SystemException&) { INFOS("CORBA::SystemException: unable to contact the naming service"); throw ServiceUnreachable(); } - catch(...) + + catch (...) { INFOS("Unknown Exception: unable to contact the naming service"); throw ServiceUnreachable(); } } -//---------------------------------------------------------------------- +// ============================================================================ /*! Function : _resolve_Path * Purpose : method to decompose a Path : /Kernel/Services/Sessions. * * \return a char* containing the first char between '/' (in this case Kernel) - */ -//---------------------------------------------------------------------- + */ +// ============================================================================ char* SALOME_NamingService::_resolve_Path(char* Path) { @@ -1291,90 +1593,108 @@ char* SALOME_NamingService::_resolve_Path(char* Path) int length = strlen(Path); char *resultat; - if (length==0) return NULL; + if (length == 0) + return NULL; else { - while ((i0) + while (strlen(temp[j]) > 0) { // temp[j] contains the characters to be treated : // (Path - characters already treted) // tempslash[j] = temp[j] if the string temp[j] doesn't begin whith '/' // tempslash[j] = temp[j] without '/' if the string begins whith '/' int length_temp = strlen(temp[j]); - if (temp[j][0]=='/') - { - // the characters to be treated begin whith '/' - // we don't have to take the '/' - tempslash[j] = new char [length_temp] ; - for (int k = 0; k < length_temp-1; k++) - tempslash[j][k] = temp[j][k+1]; - tempslash[j][length_temp-1]='\0'; - } + + if (temp[j][0] == '/') + { + // the characters to be treated begin whith '/' + // we don't have to take the '/' + tempslash[j] = new char [length_temp] ; + + for (int k = 0; k < length_temp - 1; k++) + tempslash[j][k] = temp[j][k + 1]; + + tempslash[j][length_temp - 1] = '\0'; + } + else - { - //the characters to be trated don't begin with '/' - // Nothing to be done on the char - tempslash[j] = new char [length_temp+1] ; - strcpy(tempslash[j],temp[j]); - } - // decomposition of the Path - resultat_resolve_Path[j]= _resolve_Path(tempslash[j]); + { + //the characters to be trated don't begin with '/' + // Nothing to be done on the char + tempslash[j] = new char [length_temp + 1] ; + strcpy(tempslash[j], temp[j]); + } + + // decomposition of the Path + resultat_resolve_Path[j] = _resolve_Path(tempslash[j]); + //SCRUTE(resultat_resolve_Path[j]); int length_resultat = strlen(resultat_resolve_Path[j]) ; - int dimension_temp = length_temp -length_resultat ; + + int dimension_temp = length_temp - length_resultat ; + j++; - temp[j] = new char[dimension_temp +1]; - for (int i = 0 ; i list(nb, _binding_list, _binding_iterator) ; - while (_binding_iterator->next_one(_binding)) { - CosNaming::Name _bindingName = _binding->binding_name; - if (_binding->binding_type == CosNaming::ncontext) { - // We work on a directory, the search should be done in this directory - Change_Directory(_bindingName[0].id); - _Find(name,occurence_number); - // We'll go back to the initial context - _current_context = _ref_context ; - } - else if (_binding->binding_type == CosNaming::nobject) { - // We work on an object... - if (!strcmp( _bindingName[0].id,name)) - { - //MESSAGE("One occurence was found"); - occurence_number++; - // We keep in memory the directory where one occurence was found - _found_context = _current_context ; - } + while (_binding_iterator->next_one(_binding)) + { + CosNaming::Name _bindingName = _binding->binding_name; + + if (_binding->binding_type == CosNaming::ncontext) + { + // We work on a directory, the search should be done in this directory + Change_Directory(_bindingName[0].id); + _Find(name, occurence_number); + // We'll go back to the initial context + _current_context = _ref_context ; + } + + else if (_binding->binding_type == CosNaming::nobject) + { + // We work on an object... + + if (!strcmp( _bindingName[0].id, name)) + { + //MESSAGE("One occurence was found"); + occurence_number++; + // We keep in memory the directory where one occurence was found + _found_context = _current_context ; + } + } } - } - _binding_iterator->destroy(); + + _binding_iterator->destroy(); // We go to the last directory where an occurence was found _current_context = _found_context ; //SCRUTE(occurence_number); } -//---------------------------------------------------------------------- +// ============================================================================ /*! Function : _create_context_name_dir. * Purpose : method to create a Context_name from an array of char. * The number of elements to be copied are indicated @@ -1434,15 +1761,16 @@ void SALOME_NamingService::_Find(const char* name, * \param resultat_resolve_Path char** arguments * \param length_copy int arguments * \param _context_name CosNaming::Name arguments (by value) - */ -//---------------------------------------------------------------------- + */ +// ============================================================================ -void -SALOME_NamingService::_create_context_name_dir(char** resultat_resolve_Path - ,int length_copy, - CosNaming::Name& _context_name) +void +SALOME_NamingService::_create_context_name_dir(char** resultat_resolve_Path, + int length_copy, + CosNaming::Name& _context_name) { //MESSAGE("BEGIN OF _create_context_name_dir"); + for (int i = 0 ; i < length_copy;i++) { _context_name[i].id = CORBA::string_dup(resultat_resolve_Path[i]); @@ -1451,7 +1779,7 @@ SALOME_NamingService::_create_context_name_dir(char** resultat_resolve_Path } } -//---------------------------------------------------------------------- +// ============================================================================ /*! Function : _current_directory. * Purpose : method to parse the naming service tree to find a context * and determine the path to go to this context from the @@ -1460,115 +1788,136 @@ SALOME_NamingService::_create_context_name_dir(char** resultat_resolve_Path * \param length_result int arguments by value * \param context_to_found CosNaming::NamingContext_var arguments * \param _continue boolean arguments - */ -//---------------------------------------------------------------------- + */ +// ============================================================================ void -SALOME_NamingService::_current_directory(char** result_path, - int& length_result, - CosNaming::NamingContext_var context_to_found, - CORBA::Boolean& _continue) +SALOME_NamingService:: +_current_directory(char** result_path, + int& length_result, + CosNaming::NamingContext_var context_to_found, + CORBA::Boolean& _continue) { - //MESSAGE("BEGIN OF _current_Directory"); + //MESSAGE("BEGIN OF _current_Directory"); CosNaming::BindingList_var _binding_list; CosNaming::BindingIterator_var _binding_iterator; - unsigned long nb=0 ; //for using only the BindingIterator - // to access the bindings + unsigned long nb = 0 ; //for using only the BindingIterator + // to access the bindings CosNaming::Binding_var _binding ; CosNaming::NamingContext_var _ref_context = _current_context; CosNaming::NamingContext_var _temp_context = _current_context; - + _current_context->list(nb, _binding_list, _binding_iterator) ; - if ( !_binding_iterator->_is_nil() ) { - while ((_binding_iterator->next_one(_binding)) && _continue) { - CosNaming::Name _bindingName = _binding->binding_name; - if (_binding->binding_type == CosNaming::ncontext) - { - // We work on a directory, the search should be done in this directory - - result_path[length_result] = new char(strlen(_bindingName[0].id) + 1); - strcpy(result_path[length_result],_bindingName[0].id); - //SCRUTE(result_path[length_result]) - length_result++; - - CORBA::Object_var _obj =_current_context->resolve(_bindingName); - _temp_context = CosNaming::NamingContext::_narrow(_obj); - - if (_temp_context->_is_equivalent(context_to_found)) - { - //MESSAGE("The context is found, we stop the search"); - _continue = false; - //SCRUTE(_continue); - } - if(_continue) - { - //SCRUTE(_bindingName[0].id); - Change_Directory(_bindingName[0].id); - _current_directory(result_path,length_result, - context_to_found, _continue ); - if (_continue) - { - // We'll go back to the initial context - _current_context = _ref_context ; - //MESSAGE("Just before the delete of ") - //SCRUTE(result_path[length_result-1]); - delete result_path[length_result-1]; - length_result--; - } - } - } - } - _binding_iterator->destroy(); - } + + if ( !_binding_iterator->_is_nil() ) + { + while ((_binding_iterator->next_one(_binding)) && _continue) + { + CosNaming::Name _bindingName = _binding->binding_name; + + if (_binding->binding_type == CosNaming::ncontext) + { + // We work on a directory, the search should be done in this directory + + result_path[length_result] = new char(strlen(_bindingName[0].id) + 1); + strcpy(result_path[length_result], _bindingName[0].id); + //SCRUTE(result_path[length_result]) + length_result++; + + CORBA::Object_var _obj = _current_context->resolve(_bindingName); + _temp_context = CosNaming::NamingContext::_narrow(_obj); + + if (_temp_context->_is_equivalent(context_to_found)) + { + //MESSAGE("The context is found, we stop the search"); + _continue = false; + //SCRUTE(_continue); + } + + if (_continue) + { + //SCRUTE(_bindingName[0].id); + Change_Directory(_bindingName[0].id); + _current_directory(result_path, length_result, + context_to_found, _continue ); + + if (_continue) + { + // We'll go back to the initial context + _current_context = _ref_context ; + //MESSAGE("Just before the delete of ") + //SCRUTE(result_path[length_result-1]); + delete result_path[length_result - 1]; + length_result--; + } + } + } + } + + _binding_iterator->destroy(); + } + // We go to the last directory where an occurence was found - _current_context = _ref_context ; + _current_context = _ref_context ; } -//---------------------------------------------------------------------- +// ============================================================================ /*! Function :_list_directory_recurs. * Purpose : method to list recursively all the objects contained in the tree of absCurDirectory/relativeSubDir. * \param myList The list that will be filled. * \param relativeSubDir The directory from absCurDirectory in which the objects are found. * \param absCurDirectory The directory in ABSOLUTE form. * _current_context must refer to absCurDirectory. - */ -//---------------------------------------------------------------------- -void SALOME_NamingService::_list_directory_recurs(vector& myList, const char *relativeSubDir,const char *absCurDirectory) + */ +// ============================================================================ + +void SALOME_NamingService::_list_directory_recurs(vector& myList, + const char *relativeSubDir, + const char *absCurDirectory) { CosNaming::BindingList_var _binding_list; CosNaming::BindingIterator_var _binding_iterator; - unsigned long nb=0 ; // for using only the BindingIterator to access the bindings + unsigned long nb = 0 ; // for using only the BindingIterator to access the bindings CosNaming::Binding_var _binding ; char *absDir; CosNaming::NamingContext_var _ref_context = _current_context; - if(relativeSubDir) + + if (relativeSubDir) { Change_Directory(relativeSubDir); - absDir=new char[strlen(absCurDirectory)+2+strlen(relativeSubDir)]; - strcpy(absDir,absCurDirectory); - strcat(absDir,relativeSubDir); - strcat(absDir,"/"); + absDir = new char[strlen(absCurDirectory) + 2 + strlen(relativeSubDir)]; + strcpy(absDir, absCurDirectory); + strcat(absDir, relativeSubDir); + strcat(absDir, "/"); } + else - absDir=(char *)absCurDirectory; + absDir = (char *)absCurDirectory; + _current_context->list(nb, _binding_list, _binding_iterator) ; - while (_binding_iterator->next_one(_binding)) { - CosNaming::Name _bindingName = _binding->binding_name; - if (_binding->binding_type == CosNaming::ncontext) { - _list_directory_recurs(myList,_bindingName[0].id,absDir); - } - else if (_binding->binding_type == CosNaming::nobject) { - char *elt=new char[strlen(absDir)+2+strlen(_bindingName[0].id)]; - strcpy(elt,absDir); - strcat(elt,_bindingName[0].id); - myList.push_back(elt); - delete [] elt; + while (_binding_iterator->next_one(_binding)) + { + CosNaming::Name _bindingName = _binding->binding_name; + + if (_binding->binding_type == CosNaming::ncontext) + { + _list_directory_recurs(myList, _bindingName[0].id, absDir); + } + + else if (_binding->binding_type == CosNaming::nobject) + { + char *elt = new char[strlen(absDir) + 2 + strlen(_bindingName[0].id)]; + strcpy(elt, absDir); + strcat(elt, _bindingName[0].id); + myList.push_back(elt); + delete [] elt; + } } - } - if(relativeSubDir) + + if (relativeSubDir) { _current_context = _ref_context ; delete [] absDir; @@ -1577,10 +1926,14 @@ void SALOME_NamingService::_list_directory_recurs(vector& myList, const _binding_iterator->destroy(); } -//---------------------------------------------------------------------- +// ============================================================================ +/*! + * + */ +// ============================================================================ char * SALOME_NamingService::getIORaddr() { - return _orb->object_to_string(_root_context); + return _orb->object_to_string(_root_context); } diff --git a/src/NamingService/SALOME_NamingService.hxx b/src/NamingService/SALOME_NamingService.hxx index d418b47b7..4ddd8b6bf 100644 --- a/src/NamingService/SALOME_NamingService.hxx +++ b/src/NamingService/SALOME_NamingService.hxx @@ -29,16 +29,14 @@ #ifndef SALOME_NAMINGSERVICE_H #define SALOME_NAMINGSERVICE_H -#include "utilities.h" -#include -#include -#include -#include "Utils_Mutex.hxx" - #include #include CORBA_CLIENT_HEADER(SALOME_ContainerManager) #include CORBA_CLIENT_HEADER(SALOME_Component) -//class ServiceUnreachable; + +#include +#include +#include "utilities.h" +#include "Utils_Mutex.hxx" #include "ServiceUnreachable.hxx" #if defined NAMINGSERVICE_EXPORTS @@ -58,114 +56,74 @@ class NAMINGSERVICE_EXPORT SALOME_NamingService { public: - //! default constructor SALOME_NamingService(); - - //! standard constructor SALOME_NamingService(CORBA::ORB_ptr orb); - //! standard destructor virtual ~SALOME_NamingService(); - //! initialize ORB reference after default constructor void init_orb(CORBA::ORB_ptr orb); - - //! method to create an association in the NamingService between an object reference and a path - void Register(CORBA::Object_ptr ObjRef, const char* Path) + void Register(CORBA::Object_ptr ObjRef, + const char* Path) throw(ServiceUnreachable); - - //! method to get the ObjRef of a symbolic name CORBA::Object_ptr Resolve(const char* Path) throw( ServiceUnreachable); - - //! method to get the ObjRef of a component - CORBA::Object_ptr ResolveComponent(const char* hostname, const char* containerName, const char* componentName, const int nbproc=0); - - //! method to get an ObjRef, given a symbolic name without instance suffix "/Path/Name*.kind" CORBA::Object_ptr ResolveFirst(const char* Path) throw( ServiceUnreachable); - + CORBA::Object_ptr ResolveComponent(const char* hostname, + const char* containerName, + const char* componentName, + const int nbproc=0) + throw(ServiceUnreachable); std::string ContainerName(const char *ContainerName); std::string ContainerName(const Engines::MachineParameters& params); - - std::string BuildContainerNameForNS(const char *ContainerName, const char *hostname); - std::string BuildContainerNameForNS(const Engines::MachineParameters& params, const char *hostname); - - //! method to research a name from the naming service's current directory + std::string BuildContainerNameForNS(const char *ContainerName, + const char *hostname); + std::string + BuildContainerNameForNS(const Engines::MachineParameters& params, + const char *hostname); int Find(const char* name) throw(ServiceUnreachable); - - //! method to create a directory from the current directory bool Create_Directory(const char* Path) throw(ServiceUnreachable); - - //! method to change the current directory to the directory Path indicated in "in" Parameter bool Change_Directory(const char* Path) throw(ServiceUnreachable); - - //!method to get the current directory char* Current_Directory() throw(ServiceUnreachable); - - //!method to print all the contexts contained from the current directory void list() throw(ServiceUnreachable); - - //!method to get all the contexts contained in the current direcotry - // Get only objects, isn't iterative std::vector list_directory() throw(ServiceUnreachable); - - //!methods that lists all objects RECUSIVELY in the current directory std::vector list_directory_recurs() throw(ServiceUnreachable); - - //! method to destroy an association Path-Object Reference void Destroy_Name(const char* Path) throw(ServiceUnreachable); - - //! method to destroy a directory if it is empty virtual void Destroy_Directory(const char* Path) throw(ServiceUnreachable); - - //! method to destroy a directory even if it is not empty virtual void Destroy_FullDirectory(const char* Path) throw(ServiceUnreachable); - - //! get IORstring naming service address - char * getIORaddr(); + char* getIORaddr(); protected: Utils_Mutex _myMutex; CORBA::ORB_ptr _orb; CosNaming::NamingContext_var _root_context, _current_context; - //! method called by constructor to initialize _root_context void _initialize_root_context(); - - //! method to decompose a Path : /Kernel/Services/Sessions char* _resolve_Path(char* Path); - - //! method to decompose a Path : /Kernel/Services/Sessions - void _result_resolve_Path(const char* Path, int& j, + void _result_resolve_Path(const char* Path, + int& j, char ** resultat_resolve_Path); - - //! internal method called by Find to research a name from the naming service's current directory void _Find(const char* name, CORBA::Long& occurence_number); - - //! internal method to create a context name from a Path void _create_context_name_dir(char** resultat_resolve_Path, int length_copy, CosNaming::Name& _context_name); - - //! internal method to create a parse the naming service tree void _current_directory(char** result_path, int& length_result, CosNaming::NamingContext_var context_to_found, CORBA::Boolean& _continue); - - //! internal method to list all (recursively) the objects contains in absCurDirectory/relativeSubDir. - void _list_directory_recurs(std::vector& myList, const char *relativeSubDir,const char *absCurDirectory); + void _list_directory_recurs(std::vector& myList, + const char *relativeSubDir, + const char *absCurDirectory); }; diff --git a/src/NamingService/Test/Makefile.in b/src/NamingService/Test/Makefile.in new file mode 100644 index 000000000..e95d9f56b --- /dev/null +++ b/src/NamingService/Test/Makefile.in @@ -0,0 +1,67 @@ +# SALOMELocalTrace : log on local machine +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +# +# +# +# File : Makefile.in +# Author : Paul RASCLE (EDF) +# Module : SALOME +# $Header$ + +top_srcdir=@top_srcdir@ +top_builddir=../../.. +srcdir=@srcdir@ +VPATH=.:@srcdir@:@top_srcdir@/idl + + +@COMMENCE@ + +# header files +EXPORT_HEADERS= NamingServiceTest.hxx + +EXPORT_PYSCRIPTS = TestNamingService.py + +# Libraries targets + +LIB = libNamingServiceTest.la +LIB_SRC = NamingServiceTest.cxx +LIB_CLIENT_IDL = SALOME_Component.idl SALOME_TestComponent.idl \ + SALOME_Exception.idl + +# Executables targets + +BIN = TestNamingService +BIN_SRC = + +CXXFLAGS += @CPPUNIT_INCLUDES@ +CPPFLAGS += @CPPUNIT_INCLUDES@ + +LIBS= @LIBS@ @CPPUNIT_LIBS@ + +LDFLAGS+= + +LDFLAGSFORBIN+= \ + -lSALOMELocalTraceTest -lSALOMELocalTrace -lSALOMEBasics \ + -lSALOMETraceCollectorTest \ + -lUtilsTest -lOpUtil \ + -lSalomeNS + +@CONCLUDE@ diff --git a/src/NamingService/Test/NamingServiceTest.cxx b/src/NamingService/Test/NamingServiceTest.cxx new file mode 100644 index 000000000..fcac909c1 --- /dev/null +++ b/src/NamingService/Test/NamingServiceTest.cxx @@ -0,0 +1,129 @@ + +#include "NamingServiceTest.hxx" +#include "Utils_ORB_INIT.hxx" +#include "Utils_SINGLETON.hxx" + +#include +#include +#include +#include + +using namespace std; + +// --- uncomment to have some traces on standard error +// (useful only when adding new tests...) +//#define _DEVDEBUG_ + +#ifdef _DEVDEBUG_ +#define MYDEVTRACE {std::cerr << __FILE__ << " [" << __LINE__ << "] : ";} +#define DEVTRACE(msg) {MYDEVTRACE; std::cerr<deleteInstance(bp1); + + // --- trace on file + char *theFileName = TRACEFILE; + + string s = "file:"; + s += theFileName; + //s="local"; + //s="with_logger"; + CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite + + ofstream traceFile; + // traceFile.open(theFileName, ios::out | ios::trunc); + traceFile.open(theFileName, ios::out | ios::app); + CPPUNIT_ASSERT(traceFile); // file created empty, then closed + traceFile.close(); + + bp1 = LocalTraceBufferPool::instance(); + CPPUNIT_ASSERT(bp1); + + // --- Get or initialize the orb + + int _argc = 1; + char* _argv[] = {""}; + ORB_INIT &init = *SINGLETON_::Instance() ; + ASSERT(SINGLETON_::IsAlreadyExisting()); + _orb = init(_argc , _argv ) ; + + // --- Create a SALOME_NamingService instance + + _NS.init_orb(_orb) ; +} + +// ============================================================================ +/*! + * - delete trace classes + */ +// ============================================================================ + +void +NamingServiceTest::tearDown() +{ + + LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance(); + CPPUNIT_ASSERT(bp1); + bp1->deleteInstance(bp1); +} + +// ============================================================================ +/*! + * + */ +// ============================================================================ + +void +NamingServiceTest::testConstructorDefault() +{ + SALOME_NamingService NS; + //CPPUNIT_ASSERT_THROW(NS.getIORaddr(),CORBA::Exception); + NS.init_orb(_orb); + char *root = NS.getIORaddr(); + CORBA::Object_var obj = _orb->string_to_object(root); + CPPUNIT_ASSERT(!CORBA::is_nil(obj)); + CosNaming::NamingContext_var rootContext = + CosNaming::NamingContext::_narrow(obj); + CPPUNIT_ASSERT(!CORBA::is_nil(rootContext)); +} + +// ============================================================================ +/*! + * + */ +// ============================================================================ + +void +NamingServiceTest::testConstructorOrb() +{ + SALOME_NamingService NS(_orb); + char *root = NS.getIORaddr(); + CORBA::Object_var obj = _orb->string_to_object(root); + CPPUNIT_ASSERT(!CORBA::is_nil(obj)); + CosNaming::NamingContext_var rootContext = + CosNaming::NamingContext::_narrow(obj); + CPPUNIT_ASSERT(!CORBA::is_nil(rootContext)); +} + + + diff --git a/src/NamingService/Test/NamingServiceTest.hxx b/src/NamingService/Test/NamingServiceTest.hxx new file mode 100644 index 000000000..d82af640a --- /dev/null +++ b/src/NamingService/Test/NamingServiceTest.hxx @@ -0,0 +1,30 @@ + +#ifndef _NAMINGSERVICETEST_HXX_ +#define _NAMINGSERVICETEST_HXX_ + +#include +#include "SALOME_NamingService.hxx" + +class NamingServiceTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE( NamingServiceTest ); + CPPUNIT_TEST( testConstructorDefault ); + CPPUNIT_TEST( testConstructorOrb ); +// CPPUNIT_TEST( ); + CPPUNIT_TEST_SUITE_END(); + +public: + + void setUp(); + void tearDown(); + + void testConstructorDefault(); + void testConstructorOrb(); +// void testFindOrLoad_Component_(); + +protected: + CORBA::ORB_var _orb; + SALOME_NamingService _NS; +}; + +#endif diff --git a/src/NamingService/Test/TestNamingService.cxx b/src/NamingService/Test/TestNamingService.cxx new file mode 100644 index 000000000..5680c4ee0 --- /dev/null +++ b/src/NamingService/Test/TestNamingService.cxx @@ -0,0 +1,18 @@ + +// --- include all Unit Test from basics until the present directory + +#include "SALOMELocalTraceTest.hxx" +#include "SALOMETraceCollectorTest.hxx" +#include "UtilsTest.hxx" +#include "NamingServiceTest.hxx" + +// --- Registers the fixture into the 'registry' + +CPPUNIT_TEST_SUITE_REGISTRATION( SALOMELocalTraceTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( SALOMETraceCollectorTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( UtilsTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( NamingServiceTest ); + +// --- generic Main program from Basic/Test + +#include "BasicMainTest.hxx" diff --git a/src/NamingService/Test/TestNamingService.py b/src/NamingService/Test/TestNamingService.py new file mode 100644 index 000000000..153b71910 --- /dev/null +++ b/src/NamingService/Test/TestNamingService.py @@ -0,0 +1,35 @@ +import sys, os,signal,string,commands +import runSalome +import orbmodule +import TestKiller + +# get SALOME environment : + +args, modules_list, modules_root_dir = runSalome.get_config() +runSalome.set_env(args, modules_list, modules_root_dir) + +# set environment for trace in logger +# (with file, servers may be killed before the write to the file...) + +#os.environ["SALOME_trace"] = "file:/tmp/traceUnitTest.log" +#os.environ["SALOME_trace"] = "local" +os.environ["SALOME_trace"] = "with_logger" + +# launch CORBA naming server + +clt=orbmodule.client() + +# launch CORBA logger server + +myServer=runSalome.LoggerServer(args) +myServer.run() +clt.waitLogger("Logger") + +# execute Unit Test + +command = ['TestNamingService'] +ret = os.spawnvp(os.P_WAIT, command[0], command) + +# kill Test process + +TestKiller.killProcess(runSalome.process_id) diff --git a/src/UnitTests/Makefile.in b/src/UnitTests/Makefile.in index a0c154083..bdc46c93e 100644 --- a/src/UnitTests/Makefile.in +++ b/src/UnitTests/Makefile.in @@ -59,7 +59,8 @@ LDFLAGSFORBIN+= \ -lSALOMELocalTraceTest -lSALOMELocalTrace -lSALOMEBasics \ -lSALOMETraceCollectorTest \ -lUtilsTest -lOpUtil \ - -lSalomeNS -lSalomeContainer -lSalomeResourcesManager \ + -lNamingServiceTest -lSalomeNS \ + -lSalomeContainer -lSalomeResourcesManager \ -lRegistry -lSalomeNotification \ -lLifeCycleCORBATest -lSalomeLifeCycleCORBA \ diff --git a/src/UnitTests/UnitTests.cxx b/src/UnitTests/UnitTests.cxx index 987e3049c..ee91e638e 100644 --- a/src/UnitTests/UnitTests.cxx +++ b/src/UnitTests/UnitTests.cxx @@ -4,6 +4,7 @@ #include "SALOMELocalTraceTest.hxx" #include "SALOMETraceCollectorTest.hxx" #include "UtilsTest.hxx" +#include "NamingServiceTest.hxx" #include "LifeCycleCORBATest.hxx" // --- Registers the fixture into the 'registry' @@ -11,6 +12,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION( SALOMELocalTraceTest ); CPPUNIT_TEST_SUITE_REGISTRATION( SALOMETraceCollectorTest ); CPPUNIT_TEST_SUITE_REGISTRATION( UtilsTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( NamingServiceTest ); CPPUNIT_TEST_SUITE_REGISTRATION( LifeCycleCORBATest ); // --- generic Main program from Basic/Test