Back to index

salome-kernel  6.5.0
SALOME_NamingService.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME NamingService : wrapping NamingService services
00024 //  File   : SALOME_NamingService.cxx
00025 //  Author : Estelle Deville
00026 //  Module : SALOME
00027 //  $Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/NamingService/SALOME_NamingService.cxx,v 1.16.2.7.10.3.12.1 2012-04-12 14:05:18 vsr Exp $
00028 //
00029 #include "SALOME_NamingService.hxx"
00030 #include "ServiceUnreachable.hxx"
00031 
00032 #include "utilities.h"
00033 
00034 #include <iostream>
00035 #include <cstring>
00036 #include <string>
00037 #include <cstdio>
00038 
00039 #ifdef WNT
00040 #define strdup _strdup
00041 #endif
00042 
00048 // ============================================================================
00054 // ============================================================================
00055 
00056 SALOME_NamingService::SALOME_NamingService()
00057 {
00058   MESSAGE("SALOME_NamingService default constructor");
00059   _orb = CORBA::ORB::_nil();
00060   _root_context = CosNaming::NamingContext::_nil();
00061 }
00062 
00063 // ============================================================================
00069 // ============================================================================
00070 
00071 SALOME_NamingService::SALOME_NamingService(CORBA::ORB_ptr orb)
00072 {
00073   MESSAGE("SALOME_NamingService creation");
00074   _orb = CORBA::ORB::_duplicate(orb);
00075   _initialize_root_context();
00076 }
00077 
00078 // ============================================================================
00083 // ============================================================================
00084 
00085 SALOME_NamingService::~SALOME_NamingService()
00086 {
00087   // Problem MESSAGE with singleton: late destruction,
00088   // after trace system destruction ?
00089   //MESSAGE("SALOME_NamingService destruction");
00090 }
00091 
00092 // ============================================================================
00100 // ============================================================================
00101 
00102 void SALOME_NamingService::init_orb(CORBA::ORB_ptr orb)
00103 {
00104   MESSAGE("SALOME_NamingService initialisation");
00105 
00106   Utils_Locker lock (&_myMutex);
00107   if(orb)
00108     _orb = CORBA::ORB::_duplicate(orb);
00109   else
00110     {
00111       int argc=0;
00112       _orb = CORBA::ORB_init(argc, 0); // Here we make the assumption that the orb has already been initialized
00113     }
00114 
00115   _initialize_root_context();
00116 }
00117 
00118 // ============================================================================
00137 // ============================================================================
00138 
00139 void SALOME_NamingService::Register(CORBA::Object_ptr ObjRef,
00140                                     const char* Path)
00141   throw(ServiceUnreachable)
00142 {
00143   MESSAGE("BEGIN OF Register: " << Path);
00144 
00145   Utils_Locker lock (&_myMutex);
00146 
00147   // --- _current_context is replaced to the _root_context
00148   //     if the Path begins whith '/'
00149 
00150   if (Path[0] == '/'){
00151     _current_context = _root_context;
00152   }
00153 
00154   // --- the resolution of the directory path has to be done
00155   //      to place the current_context to the correct node
00156 
00157   CosNaming::Name context_name;
00158   std::vector<std::string> splitPath;
00159   int dimension_resultat = _createContextNameDir(Path,
00160                                                  context_name,
00161                                                  splitPath,
00162                                                  true);
00163 
00164   CORBA::Boolean not_exist = false;
00165 
00166   if (dimension_resultat > 0){
00167     // A directory is treated (not only an object name)
00168     // test if the directory where ObjRef should be recorded already exists
00169     // If not, create the new context
00170     
00171     try{
00172       CORBA::Object_var obj = _current_context->resolve(context_name);
00173       _current_context = CosNaming::NamingContext::_narrow(obj);
00174     }
00175 
00176     catch (CosNaming::NamingContext::NotFound &){
00177       // --- failed to resolve, therefore assume cold start
00178       not_exist = true;
00179     }
00180 
00181     catch (CosNaming::NamingContext::InvalidName &){
00182       INFOS("Register() : CosNaming::NamingContext::InvalidName");
00183     }
00184 
00185     catch (CosNaming::NamingContext::CannotProceed &){
00186       INFOS("Register() : CosNaming::NamingContext::CannotProceed");
00187     }
00188 
00189     catch (CORBA::SystemException&){
00190       INFOS("Register() : CORBA::SystemException: "
00191             << "unable to contact the naming service");
00192       throw ServiceUnreachable();
00193     }
00194 
00195     if (not_exist){
00196       try{
00197         context_name.length(1);
00198         for (int i = 0 ; i < dimension_resultat ;i++){
00199           context_name[0].id = CORBA::string_dup(splitPath[i].c_str());
00200           context_name[0].kind = CORBA::string_dup("dir");
00201           // SCRUTE(_context_name[0].id);
00202           // --- check if the path is created
00203           try{
00204             // --- if the context is already created, nothing to do
00205             CORBA::Object_var obj = _current_context->resolve(context_name);
00206             _current_context = CosNaming::NamingContext::_narrow(obj);
00207           }
00208 
00209           catch (CosNaming::NamingContext::NotFound &){
00210             try{
00211               // --- the context must be created
00212               CosNaming::NamingContext_var temp_context =
00213                 _current_context->bind_new_context(context_name);
00214               _current_context = temp_context;
00215             }
00216             catch (CosNaming::NamingContext::AlreadyBound&){
00217               CORBA::Object_var obj = _current_context->resolve(context_name);
00218               _current_context = CosNaming::NamingContext::_narrow(obj);
00219             }
00220           }
00221         }
00222       }
00223 
00224       catch (CosNaming::NamingContext::AlreadyBound&){
00225         INFOS("Register() : CosNaming::NamingContext::AlreadyBound");
00226       }
00227 
00228       catch (CosNaming::NamingContext::NotFound& ex){
00229         CosNaming::Name n = ex.rest_of_name;
00230 
00231         if (ex.why == CosNaming::NamingContext::missing_node)
00232           INFOS("Register() : " << (char *) n[0].id
00233                 << " (" << (char *) n[0].kind << ") not found");
00234 
00235         if (ex.why == CosNaming::NamingContext::not_context)
00236           INFOS("Register() : " << (char *) n[0].id
00237                 << " (" << (char *) n[0].kind
00238                 << ") is not a context");
00239 
00240         if (ex.why == CosNaming::NamingContext::not_object)
00241           INFOS("Register() : " << (char *) n[0].id
00242                 << " (" << (char *) n[0].kind
00243                 << ") is not an object");
00244       }
00245 
00246       catch (CosNaming::NamingContext::CannotProceed&){
00247         INFOS("Register(): CosNaming::NamingContext::CannotProceed");
00248       }
00249 
00250       catch (CosNaming::NamingContext::InvalidName&){
00251         INFOS("Register(): CosNaming::NamingContext::InvalidName");
00252       }
00253 
00254       catch (CORBA::SystemException&){
00255         INFOS("Register():CORBA::SystemException: "
00256               << "unable to contact the naming service");
00257         throw ServiceUnreachable();
00258       }
00259     }
00260   }
00261 
00262   // --- The current directory is now the directory where the object should
00263   //     be recorded
00264 
00265   int sizePath = splitPath.size();
00266   if (sizePath > dimension_resultat){
00267     ASSERT(sizePath == dimension_resultat+1);
00268     context_name.length(1);
00269 
00270     try{
00271       // --- the last element is an object and not a directory
00272 
00273       context_name[0].id = CORBA::string_dup(splitPath[dimension_resultat].c_str());
00274       context_name[0].kind = CORBA::string_dup("object");
00275       //SCRUTE(context_name[0].id);
00276 
00277       _current_context->bind(context_name, ObjRef);
00278     }
00279 
00280     catch (CosNaming::NamingContext::NotFound& ex){
00281       CosNaming::Name n = ex.rest_of_name;
00282 
00283       if (ex.why == CosNaming::NamingContext::missing_node)
00284         INFOS("Register() : " << (char *) n[0].id
00285               << " (" << (char *) n[0].kind << ") not found");
00286 
00287       if (ex.why == CosNaming::NamingContext::not_context)
00288         INFOS("Register() : " << (char *) n[0].id
00289               << " (" << (char *) n[0].kind
00290               << ") is not a context");
00291 
00292       if (ex.why == CosNaming::NamingContext::not_object)
00293         INFOS("Register() : " << (char *) n[0].id
00294               << " (" << (char *) n[0].kind
00295               << ") is not an object");
00296     }
00297 
00298     catch (CosNaming::NamingContext::CannotProceed&){
00299       INFOS("Register(): CosNaming::NamingContext::CannotProceed");
00300     }
00301 
00302     catch (CosNaming::NamingContext::InvalidName&){
00303       INFOS("Register(): CosNaming::NamingContext::InvalidName");
00304     }
00305 
00306     catch (CosNaming::NamingContext::AlreadyBound&){
00307       INFOS("Register(): CosNaming::NamingContext::AlreadyBound, "
00308             << "object will be rebind");
00309       _current_context->rebind(context_name, ObjRef);
00310     }
00311 
00312     catch (CORBA::SystemException&){
00313       INFOS("!!!Register(): CORBA::SystemException: "
00314             << "unable to contact the naming service");
00315       throw ServiceUnreachable();
00316     }
00317   }
00318 }
00319 
00320 // ============================================================================
00335 // ============================================================================
00336 
00337 CORBA::Object_ptr SALOME_NamingService::Resolve(const char* Path)
00338   throw(ServiceUnreachable)
00339 {
00340 //   MESSAGE("BEGIN OF Resolve: " << Path);
00341 
00342   Utils_Locker lock (&_myMutex);
00343 
00344   // --- _current_context is replaced to the _root_context
00345   //     if the Path begins whith '/'
00346 
00347   if (Path[0] == '/')
00348     {
00349       _current_context = _root_context;
00350     }
00351 
00352   // --- the resolution of the directory path has to be done
00353   //     to place the current_context to the correct node
00354 
00355   CosNaming::Name context_name;
00356   std::vector<std::string> splitPath;
00357   _createContextNameDir(Path,
00358                                                  context_name,
00359                                                  splitPath,
00360                                                  false);
00361 
00362   ASSERT(!CORBA::is_nil(_current_context));
00363 
00364   CORBA::Object_var obj =  CORBA::Object::_nil();
00365 
00366   try
00367     {
00368       obj = _current_context->resolve(context_name);
00369     }
00370 
00371   catch (CosNaming::NamingContext::NotFound& ex)
00372     {
00373       CosNaming::Name n = ex.rest_of_name;
00374 
00375       if (ex.why == CosNaming::NamingContext::missing_node)
00376         MESSAGE("Resolve() : " << (char *) n[0].id
00377               << " (" << (char *) n[0].kind << ") not found");
00378 
00379       if (ex.why == CosNaming::NamingContext::not_context)
00380         INFOS("Resolve() : "
00381               << (char *) n[0].id << " (" << (char *) n[0].kind
00382               << ") is not a context");
00383 
00384       if (ex.why == CosNaming::NamingContext::not_object)
00385         INFOS("Resolve() : " << (char *) n[0].id
00386               << " (" << (char *) n[0].kind
00387               << ") is not an object");
00388     }
00389 
00390   catch (CosNaming::NamingContext::CannotProceed&)
00391     {
00392       INFOS("Resolve(): CosNaming::NamingContext::CannotProceed");
00393     }
00394 
00395   catch (CosNaming::NamingContext::InvalidName&)
00396     {
00397       INFOS("Resolve(): CosNaming::NamingContext::InvalidName");
00398     }
00399 
00400   catch (CORBA::SystemException&)
00401     {
00402       INFOS("Resolve():CORBA::SystemException : unable to contact"
00403             << "the naming service");
00404       throw ServiceUnreachable();
00405     }
00406 
00407   return obj._retn();
00408 }
00409 
00410 // ============================================================================
00421 // ============================================================================
00422 
00423 CORBA::Object_ptr SALOME_NamingService::ResolveFirst(const char* Path)
00424   throw(ServiceUnreachable)
00425 {
00426 //   MESSAGE("ResolveFirst");
00427 
00428   Utils_Locker lock (&_myMutex);
00429 //   SCRUTE(Path);
00430 
00431   std::string thePath = Path;
00432   std::string basePath = "";
00433   std::string name = thePath;
00434 
00435   std::string::size_type idx = thePath.rfind('/');
00436 
00437   if (idx != std::string::npos) // at least one '/' found
00438     {
00439       basePath = thePath.substr(0, idx);
00440       name = thePath.substr(idx + 1);
00441 //       SCRUTE(basePath);
00442     }
00443 
00444 //   SCRUTE(name);
00445   CORBA::Object_var obj = CORBA::Object::_nil();
00446 
00447   bool isOk = false;
00448   if (basePath.empty())
00449     isOk =true;
00450   else
00451     isOk = Change_Directory(basePath.c_str());
00452   
00453   if (isOk)
00454     {
00455       std::vector<std::string> listElem = list_directory();
00456       std::vector<std::string>::iterator its = listElem.begin();
00457       
00458       while (its != listElem.end())
00459         {
00460           MESSAGE(*its);
00461           
00462           if ((*its).find(name) == 0)
00463             {
00464               return Resolve((*its).c_str());
00465             }
00466           
00467           its++;
00468         }
00469     }
00470 
00471   return obj._retn();
00472 }
00473 
00474 // ============================================================================
00490 // ============================================================================
00491 
00492 CORBA::Object_ptr
00493 SALOME_NamingService::ResolveComponent(const char* hostname,
00494                                        const char* containerName,
00495                                        const char* componentName,
00496                                        const int nbproc)
00497   throw(ServiceUnreachable)
00498 {
00499 //   MESSAGE("ResolveComponent");
00500 
00501   Utils_Locker lock (&_myMutex);
00502 
00503   std::string name = "/Containers/";
00504 
00505   name += hostname;
00506 
00507   if ( strlen(containerName) != 0 )
00508     {
00509       name += "/";
00510 
00511       if ( nbproc >= 1 )
00512         {
00513           char *newContainerName = new char[strlen(containerName) + 8];
00514           sprintf(newContainerName, "%s_%d", containerName, nbproc);
00515           name += newContainerName;
00516           delete [] newContainerName;
00517         }
00518 
00519       else
00520         name += containerName;
00521 
00522       name += "/";
00523 
00524       name += componentName;
00525 
00526       return ResolveFirst(name.c_str());
00527     }
00528 
00529   else
00530     {
00531       SCRUTE(name);
00532       std::string basename = name;
00533       if (Change_Directory(basename.c_str()))
00534         {
00535           std::vector<std::string> contList = list_subdirs();
00536 
00537           for (unsigned int ind = 0; ind < contList.size(); ind++)
00538             {
00539               name = contList[ind].c_str();
00540 
00541               if ( nbproc >= 1 )
00542                 {
00543                   char *str_nbproc = new char[8];
00544                   sprintf(str_nbproc, "_%d", nbproc);
00545                   if( strstr(name.c_str(),str_nbproc) == NULL)
00546                     continue; // check only containers with _%d in name
00547                   delete [] str_nbproc;
00548                 }
00549 
00550               name += "/";
00551               name += componentName;
00552               SCRUTE(name);
00553               CORBA::Object_ptr obj = ResolveFirst(name.c_str());
00554 
00555               if ( !CORBA::is_nil(obj) )
00556                 return obj;
00557               else
00558                 Change_Directory(basename.c_str());
00559             }
00560         }
00561 
00562       return CORBA::Object::_nil();
00563     }
00564 }
00565 
00566 // ============================================================================
00575 // ============================================================================
00576 
00577 std::string SALOME_NamingService::ContainerName(const char *containerName)
00578 {
00579   std::string ret;
00580 
00581   if (strlen(containerName) == 0)
00582     ret = "FactoryServer";
00583   else
00584     ret = containerName;
00585 
00586   return ret;
00587 }
00588 
00589 // ============================================================================
00602 // ============================================================================
00603 
00604 std::string 
00605 SALOME_NamingService::ContainerName(const Engines::MachineParameters& params)
00606 {
00607   int nbproc;
00608 
00609   if ( !params.isMPI )
00610     nbproc = 0;
00611   else if ( (params.nb_node <= 0) && (params.nb_proc_per_node <= 0) )
00612     nbproc = 1;
00613   else if ( params.nb_node == 0 )
00614     nbproc = params.nb_proc_per_node;
00615   else if ( params.nb_proc_per_node == 0 )
00616     nbproc = params.nb_node;
00617   else
00618     nbproc = params.nb_node * params.nb_proc_per_node;
00619 
00620   std::string ret = ContainerName(params.container_name);
00621 
00622   if ( nbproc >= 1 )
00623     {
00624       char *suffix = new char[8];
00625       sprintf(suffix, "_%d", nbproc);
00626       ret += suffix;
00627     }
00628 
00629   return ret;
00630 }
00631 
00632 std::string 
00633 SALOME_NamingService::ContainerName(const Engines::ContainerParameters& params)
00634 {
00635   int nbproc;
00636 
00637   if ( !params.isMPI )
00638     nbproc = 0;
00639   else if ( params.nb_proc <= 0 )
00640     nbproc = 1;
00641   else
00642     nbproc = params.nb_proc;
00643 
00644   std::string ret = ContainerName(params.container_name);
00645 
00646   if ( nbproc >= 1 )
00647     {
00648       char *suffix = new char[8];
00649       sprintf(suffix, "_%d", nbproc);
00650       ret += suffix;
00651     }
00652 
00653   return ret;
00654 }
00655 
00656 // ============================================================================
00668 // ============================================================================
00669 
00670 std::string SALOME_NamingService::BuildContainerNameForNS(const char *containerName,
00671                                                      const char *hostname)
00672 {
00673   std::string ret = "/Containers/";
00674   ret += hostname;
00675   ret += "/";
00676   ret += ContainerName(containerName);
00677 
00678   return ret;
00679 }
00680 
00681 // ============================================================================
00691 // ============================================================================
00692 
00693 std::string
00694 SALOME_NamingService::
00695 BuildContainerNameForNS(const Engines::MachineParameters& params,
00696                         const char *hostname)
00697 {
00698   std::string ret = "/Containers/";
00699   ret += hostname;
00700   ret += "/";
00701   ret += ContainerName(params);
00702 
00703   return ret;
00704 }
00705 
00706 std::string
00707 SALOME_NamingService::
00708 BuildContainerNameForNS(const Engines::ContainerParameters& params,
00709                         const char *hostname)
00710 {
00711   std::string ret = "/Containers/";
00712   ret += hostname;
00713   ret += "/";
00714   ret += ContainerName(params);
00715 
00716   return ret;
00717 }
00718 
00719 // ============================================================================
00731 // ============================================================================
00732 
00733 int SALOME_NamingService::Find(const char* name)
00734 throw(ServiceUnreachable)
00735 {
00736   MESSAGE("BEGIN OF Find " << name);
00737 
00738   Utils_Locker lock (&_myMutex);
00739 
00740   CORBA::Long occurence_number = 0 ;
00741 
00742   try
00743     {
00744       _Find(name, occurence_number);
00745     }
00746 
00747   catch (CORBA::SystemException&)
00748     {
00749       INFOS("!!!Find() : CORBA::SystemException : unable to contact"
00750             << " the naming service");
00751       throw ServiceUnreachable();
00752     }
00753 
00754   return occurence_number;
00755 }
00756 
00757 // ============================================================================
00776 // ============================================================================
00777 
00778 bool SALOME_NamingService::Create_Directory(const char* Path)
00779 throw(ServiceUnreachable)
00780 {
00781   MESSAGE("BEGIN OF Create_Directory");
00782 
00783   Utils_Locker lock (&_myMutex);
00784 
00785   std::string path(Path);
00786 
00787   // --- if path empty, nothing to create, no context change
00788 
00789   if (path.empty())
00790     return false;
00791 
00792   // --- if path ='/', nothing to create, only change to root_context
00793 
00794   if (path == "/")
00795     {
00796       MESSAGE("Create Directory '/', just change to root_context");
00797       _current_context = _root_context;
00798       return true;
00799     }
00800 
00801   // --- path must end with '/'
00802   
00803   if (path[path.length()-1] != '/') path += '/';
00804 
00805   Register(CORBA::Object::_nil(), path.c_str());
00806   return true;
00807 }
00808 
00809 // ============================================================================
00821 // ============================================================================
00822 
00823 bool SALOME_NamingService::Change_Directory(const char* Path)
00824 throw(ServiceUnreachable)
00825 {
00826 //   MESSAGE("BEGIN OF Change_Directory " << Path);
00827   Utils_Locker lock (&_myMutex);
00828 
00829   std::string path(Path);
00830 
00831   // --- if path empty, nothing to do
00832 
00833   if (path.empty())
00834     return true;
00835 
00836   // --- if path ='/', nothing to resolve, only change to root_context
00837 
00838   if (path == "/")
00839     {
00840 //       MESSAGE("Change_Directory is called to go to the root_context");
00841       _current_context = _root_context;
00842       return true;
00843     }
00844 
00845   CosNaming::NamingContext_var current_context = _current_context;
00846   bool changeOK = false;
00847 
00848   // --- replace _current_context with _root_context if Path begins whith '/'
00849 
00850   if (path[0] == '/')
00851     current_context = _root_context;
00852 
00853   // --- need to resolve directory path
00854 
00855   ASSERT(!CORBA::is_nil(current_context));
00856   
00857   if (path[path.length()-1] != '/') path += '/';
00858 //   SCRUTE(path);
00859   CosNaming::Name context_name;
00860   std::vector<std::string> splitPath;
00861   _createContextNameDir(path.c_str(),
00862                                                  context_name,
00863                                                  splitPath,
00864                                                  true);
00865   
00866   // --- Context creation
00867   
00868   try
00869     {
00870       CORBA::Object_var obj = current_context->resolve(context_name);
00871       current_context = CosNaming::NamingContext::_narrow(obj);
00872       ASSERT(!CORBA::is_nil(current_context));
00873       _current_context = current_context;
00874       changeOK = true;
00875     }
00876   
00877   catch (CosNaming::NamingContext::NotFound& ex)
00878     {
00879       CosNaming::Name n = ex.rest_of_name;
00880       
00881       if (ex.why == CosNaming::NamingContext::missing_node)
00882         MESSAGE( "Change_Directory() : " << (char *) n[0].id
00883                << " (" << (char *) n[0].kind << ") not found");
00884       if (ex.why == CosNaming::NamingContext::not_context)
00885         INFOS("Change_Directory() : " << (char *) n[0].id
00886               << " (" << (char *) n[0].kind
00887                   << ") is not a context" );
00888       if (ex.why == CosNaming::NamingContext::not_object)
00889         INFOS( "Change_Directory() : " << (char *) n[0].id
00890                << " (" << (char *) n[0].kind
00891                << ") is not an object" );
00892     }
00893   
00894   catch (CosNaming::NamingContext::CannotProceed&)
00895     {
00896       INFOS("Change_Directory(): CosNaming::NamingContext::CannotProceed");
00897     }
00898   
00899   catch (CosNaming::NamingContext::InvalidName&)
00900     {
00901       INFOS("Change_Directory(): CosNaming::NamingContext::InvalidName");
00902     }
00903   
00904   catch (CORBA::SystemException&)
00905     {
00906       INFOS("Change_Directory():CORBA::SystemException : unable to contact"
00907             << "the naming service");
00908       throw ServiceUnreachable();
00909     }
00910 
00911   return changeOK;
00912 }
00913 
00914 // ============================================================================
00922 // ============================================================================
00923 
00924 char* SALOME_NamingService::Current_Directory()
00925 throw(ServiceUnreachable)
00926 {
00927   MESSAGE("BEGIN OF Current_Directory");
00928 
00929   Utils_Locker lock (&_myMutex);
00930 
00931   CosNaming::NamingContext_var ref_context = _current_context;
00932 
00933   std::vector<std::string> splitPath;
00934   splitPath.resize(0);
00935   int lengthPath = 0;
00936   bool notFound = true ;
00937 
00938   // --- start search from root context
00939 
00940   _current_context = _root_context ;
00941 
00942   try
00943     {
00944       _current_directory(splitPath, lengthPath, ref_context, notFound );
00945     }
00946 
00947   catch (CORBA::SystemException&)
00948     {
00949       INFOS("Current_Directory(): CORBA::SystemException: unable to contact"
00950             << " the naming service" )
00951       throw ServiceUnreachable();
00952     }
00953 
00954   std::string path;
00955   lengthPath = splitPath.size();
00956   for (int k = 0 ; k < lengthPath ;k++)
00957     {
00958       path += "/";
00959       path += splitPath[k];
00960     }
00961 
00962   SCRUTE(path)
00963   _current_context = ref_context ;
00964 
00965   return strdup(path.c_str());
00966 }
00967 
00968 // ============================================================================
00975 // ============================================================================
00976 
00977 void SALOME_NamingService::list()
00978 throw(ServiceUnreachable)
00979 {
00980   MESSAGE("Begin of list");
00981 
00982   Utils_Locker lock (&_myMutex)
00983 
00984     ;
00985   CosNaming::BindingList_var binding_list;
00986   CosNaming::BindingIterator_var binding_iterator;
00987   CosNaming::Binding_var binding ;
00988 
00989   unsigned long nb = 0 ; // --- only for the BindingIterator use,
00990                          //     to access the bindings
00991 
00992   CosNaming::NamingContext_var ref_context = _current_context;
00993 
00994   _current_context->list(nb, binding_list, binding_iterator) ;
00995 
00996   if (! CORBA::is_nil(binding_iterator))
00997     {
00998       while (binding_iterator->next_one(binding))
00999         {
01000           CosNaming::Name bindingName = binding->binding_name;
01001 
01002           if (binding->binding_type == CosNaming::ncontext)
01003             {
01004               MESSAGE( "Context : " << bindingName[0].id );
01005 
01006               try
01007                 {
01008                   Change_Directory(bindingName[0].id);
01009                 }
01010 
01011               catch (ServiceUnreachable&)
01012                 {
01013                   INFOS( "list(): ServiceUnreachable" )
01014                     throw ServiceUnreachable();
01015                 }
01016 
01017               list();
01018               _current_context = ref_context ;
01019             }
01020 
01021           else if (binding->binding_type == CosNaming::nobject)
01022             {
01023               MESSAGE( "Object : " << bindingName[0].id );
01024             }
01025         }
01026 
01027       binding_iterator->destroy();
01028     }
01029 }
01030 
01031 // ============================================================================
01040 // ============================================================================
01041 
01042 std::vector<std::string> SALOME_NamingService::list_directory()
01043 throw(ServiceUnreachable)
01044 {
01045 //   MESSAGE("list_directory");
01046   std::vector<std::string> dirList ;
01047   dirList.resize(0);
01048 
01049   CosNaming::BindingList_var binding_list;
01050   CosNaming::BindingIterator_var binding_iterator;
01051   CosNaming::Binding_var binding ;
01052 
01053   unsigned long nb = 0 ; // --- only for the BindingIterator use,
01054                          //     to access the bindings
01055 
01056   CosNaming::NamingContext_var ref_context = _current_context;
01057 
01058   _current_context->list(nb, binding_list, binding_iterator);
01059 
01060   if (binding_iterator->_is_nil())
01061     return dirList;
01062 
01063   while (binding_iterator->next_one(binding))
01064     {
01065       CosNaming::Name bindingName = binding->binding_name;
01066 
01067       if (binding->binding_type == CosNaming::nobject)
01068         {
01069           // remove memory leak
01070           // dirList.push_back(CORBA::string_dup(bindingName[0].id));
01071           dirList.push_back(std::string(bindingName[0].id));
01072         }
01073     }
01074 
01075 //   for (unsigned int ind = 0; ind < dirList.size(); ind++)
01076 //     MESSAGE("list_directory : Object : " << dirList[ind]);
01077 
01078   binding_iterator->destroy();
01079 
01080   return dirList;
01081 }
01082 
01083 
01084 // ============================================================================
01094 // ============================================================================
01095 
01096 std::vector<std::string> SALOME_NamingService::list_subdirs()
01097 throw(ServiceUnreachable)
01098 {
01099   MESSAGE("list_subdirs");
01100   std::vector<std::string> dirList ;
01101   dirList.resize(0);
01102 
01103   CosNaming::BindingList_var binding_list;
01104   CosNaming::BindingIterator_var binding_iterator;
01105   CosNaming::Binding_var binding ;
01106 
01107   unsigned long nb = 0 ; // --- only for the BindingIterator use,
01108                          //     to access the bindings
01109 
01110   CosNaming::NamingContext_var ref_context = _current_context;
01111 
01112   _current_context->list(nb, binding_list, binding_iterator) ;
01113 
01114   if (binding_iterator->_is_nil())
01115     return dirList;
01116 
01117   while (binding_iterator->next_one(binding))
01118     {
01119       CosNaming::Name bindingName = binding->binding_name;
01120 
01121       if (binding->binding_type == CosNaming::ncontext)
01122         {
01123           dirList.push_back(bindingName[0].id.in());
01124         }
01125     }
01126 
01127   for (unsigned int ind = 0; ind < dirList.size(); ind++)
01128     MESSAGE("list_directory : Object : " << dirList[ind]);
01129 
01130   binding_iterator->destroy();
01131 
01132   return dirList;
01133 }
01134 
01135 // ============================================================================
01144 // ============================================================================
01145 
01146 std::vector<std::string> SALOME_NamingService::list_directory_recurs()
01147 throw(ServiceUnreachable)
01148 {
01149   MESSAGE("list_directory_recurs");
01150 
01151   Utils_Locker lock (&_myMutex);
01152 
01153   std::vector<std::string> dirList ;
01154 
01155   char* currentDir = Current_Directory();
01156 
01157   _list_directory_recurs(dirList, "", currentDir);
01158 
01159   free(currentDir);
01160 
01161   return dirList;
01162 }
01163 
01164 // ============================================================================
01171 // ============================================================================
01172 
01173 void SALOME_NamingService::Destroy_Name(const char* Path)
01174 throw(ServiceUnreachable)
01175 {
01176   MESSAGE("BEGIN OF Destroy_Name " << Path);
01177 
01178   Utils_Locker lock (&_myMutex);
01179 
01180   std::string path(Path);
01181 
01182   // --- if path empty, nothing to do
01183 
01184   if (path.empty())
01185     return;
01186 
01187   // --- if path = '/' not applicable, nothing to do
01188 
01189   if (path == "/")
01190     return;
01191 
01192   // --- if path begins with '/', set current directory to root context
01193 
01194   if (path[0] == '/')
01195     _current_context = _root_context;
01196 
01197   // --- context of the directory containing the object
01198 
01199   CosNaming::Name context_name;
01200   std::vector<std::string> splitPath;
01201   int dimension_resultat = _createContextNameDir(path.c_str(),
01202                                                  context_name,
01203                                                  splitPath,
01204                                                  true);
01205 
01206   bool exist = false;
01207 
01208   if (dimension_resultat > 0)
01209     {
01210       // --- path contains a directory, not only an object name
01211       //     switch to the new directory (or return if directory not found)
01212 
01213       try
01214         {
01215           CORBA::Object_var obj = _current_context->resolve(context_name);
01216           _current_context = CosNaming::NamingContext::_narrow(obj);
01217           exist = true;
01218         }
01219 
01220       catch (CosNaming::NamingContext::NotFound &ex)
01221         {
01222           // --- failed to resolve
01223           exist = false;
01224 
01225           CosNaming::Name n = ex.rest_of_name;
01226 
01227           if (ex.why == CosNaming::NamingContext::missing_node)
01228             INFOS( "Destroy_Name(): " << (char *) n[0].id
01229                    << " (" << (char *) n[0].kind << ") not found" );
01230           if (ex.why == CosNaming::NamingContext::not_context)
01231             INFOS( "Destroy_Name() : " << (char *) n[0].id
01232                    << " (" << (char *) n[0].kind
01233                    << ") is not a context" );
01234           if (ex.why == CosNaming::NamingContext::not_object)
01235             INFOS( "Destroy_Name() : " << (char *) n[0].id
01236                    << " (" << (char *) n[0].kind
01237                    << ") is not an object" );
01238         }
01239 
01240       catch (CosNaming::NamingContext::InvalidName &)
01241         {
01242           INFOS("Destroy_Name: CosNaming::NamingContext::InvalidName");
01243         }
01244 
01245       catch (CosNaming::NamingContext::CannotProceed &)
01246         {
01247           INFOS("Destroy_Name: CosNaming::NamingContext::CannotProceed");
01248         }
01249 
01250       catch (CORBA::SystemException&)
01251         {
01252           INFOS("Destroy_Name : CORBA::SystemException: "
01253                 << "unable to contact the naming service");
01254           throw ServiceUnreachable();
01255         }
01256 
01257       if (! exist) return;
01258     }
01259 
01260   ASSERT(!CORBA::is_nil(_current_context));
01261 
01262   // --- The current directory is now the directory where the object should
01263   //     be destroyed
01264 
01265   int sizePath = splitPath.size();
01266   if (sizePath > dimension_resultat)
01267     {
01268       ASSERT(sizePath == dimension_resultat+1);
01269       context_name.length(1);
01270 
01271       try
01272         {
01273           // --- the last element is an object and not a directory
01274 
01275           context_name[0].id =
01276             CORBA::string_dup(splitPath[dimension_resultat].c_str());
01277           context_name[0].kind = CORBA::string_dup("object");
01278           SCRUTE(context_name[0].id);
01279  
01280           _current_context->unbind(context_name);
01281           MESSAGE("The object " << context_name[0].id << " has been deleted");
01282         }
01283 
01284       catch (CosNaming::NamingContext::NotFound& ex)
01285         {
01286           CosNaming::Name n = ex.rest_of_name;
01287 
01288           if (ex.why == CosNaming::NamingContext::missing_node)
01289             INFOS( "Destroy_Name() : " << (char *) n[0].id
01290                    << " (" << (char *) n[0].kind << ") not found" );
01291           if (ex.why == CosNaming::NamingContext::not_context)
01292             INFOS( "Destroy_Name() : " << (char *) n[0].id
01293                    << " (" << (char *) n[0].kind
01294                    << ") is not a context" );
01295           if (ex.why == CosNaming::NamingContext::not_object)
01296             INFOS( "Destroy_Name() : " << (char *) n[0].id
01297                    << " (" << (char *) n[0].kind
01298                    << ") is not an object" );
01299           }
01300 
01301       catch (CosNaming::NamingContext::CannotProceed&)
01302         {
01303           INFOS( "Destroy_Name(): CosNaming::NamingContext::CannotProceed");
01304         }
01305 
01306       catch (CosNaming::NamingContext::InvalidName&)
01307         {
01308           INFOS( "Destroy_Name(): CosNaming::NamingContext::InvalidName");
01309         }
01310 
01311       catch (CORBA::SystemException&)
01312         {
01313           INFOS( "Destroy_Name(): CORBA::SystemException: unable to contact"
01314                  << " the naming service");
01315           throw ServiceUnreachable();
01316         }
01317     }
01318 }
01319 
01320 // ============================================================================
01327 // ============================================================================
01328 
01329 void SALOME_NamingService::Destroy_Directory(const char* Path)
01330 throw(ServiceUnreachable)
01331 {
01332   MESSAGE("BEGIN OF Destroy_Directory " << Path);
01333 
01334   Utils_Locker lock (&_myMutex);
01335 
01336   std::string path(Path);
01337 
01338   // --- if path empty, nothing to do
01339 
01340   if (path.empty())
01341     return;
01342 
01343   // --- if path begins with '/', set current directory to root context
01344 
01345   if (path[0] == '/')
01346     _current_context = _root_context;
01347 
01348   CosNaming::NamingContext_var ref_context = _current_context;
01349 
01350   // --- path must ends with '/' for a directory
01351 
01352   if (path[path.size() -1] != '/')
01353     path += '/';
01354 
01355   // --- context of the directory
01356 
01357   CosNaming::Name context_name;
01358   std::vector<std::string> splitPath;
01359   int dimension_resultat = _createContextNameDir(path.c_str(),
01360                                                  context_name,
01361                                                  splitPath,
01362                                                  true);
01363   bool exist = false;
01364 
01365   if (dimension_resultat > 0)
01366     {
01367       // --- path contains a directory, not only an object name
01368       //     switch to the new directory (or return if directory not found)
01369 
01370       try
01371         {
01372           CORBA::Object_var obj = _current_context->resolve(context_name);
01373           _current_context = CosNaming::NamingContext::_narrow(obj);
01374           exist = true;
01375         }
01376 
01377       catch (CosNaming::NamingContext::NotFound &ex)
01378         {
01379           // --- failed to resolve
01380           exist = false;
01381 
01382           CosNaming::Name n = ex.rest_of_name;
01383 
01384           if (ex.why == CosNaming::NamingContext::missing_node)
01385             INFOS( "Destroy_Directory(): " << (char *) n[0].id
01386                    << " (" << (char *) n[0].kind << ") not found" );
01387           if (ex.why == CosNaming::NamingContext::not_context)
01388             INFOS( "Destroy_Directory() : " << (char *) n[0].id
01389                    << " (" << (char *) n[0].kind
01390                    << ") is not a context" );
01391           if (ex.why == CosNaming::NamingContext::not_object)
01392             INFOS( "Destroy_Directory() : " << (char *) n[0].id
01393                    << " (" << (char *) n[0].kind
01394                    << ") is not an object" );
01395         }
01396 
01397       catch (CosNaming::NamingContext::InvalidName &)
01398         {
01399           INFOS("Destroy_Directory: CosNaming::NamingContext::InvalidName");
01400         }
01401 
01402       catch (CosNaming::NamingContext::CannotProceed &)
01403         {
01404           INFOS("Destroy_Directory: CosNaming::NamingContext::CannotProceed");
01405         }
01406 
01407       catch (CORBA::SystemException&)
01408         {
01409           INFOS("Destroy_Directory : CORBA::SystemException: "
01410                 << "unable to contact the naming service");
01411           throw ServiceUnreachable();
01412         }
01413 
01414       if (! exist) return;
01415     }
01416 
01417   ASSERT(!CORBA::is_nil(_current_context));
01418 
01419   // --- Context Destruction
01420 
01421   bool isContextDestroyed = false;
01422   try
01423     {
01424       _current_context->destroy();
01425       MESSAGE( "The context " << path << " has been deleted" );
01426       isContextDestroyed = true;
01427     }
01428 
01429   catch (CosNaming::NamingContext::NotEmpty&)
01430     {
01431       INFOS( "Destroy_Directory(): CosNaming::NamingContext::NoEmpty "
01432              << path << " is not empty" );
01433     }
01434 
01435   catch (CORBA::SystemException&)
01436     {
01437       INFOS( "Destroy_Directory():CORBA::SystemException : "
01438              << "unable to contact the naming service");
01439       throw ServiceUnreachable();
01440     }
01441 
01442   // --- go to the reference directory
01443 
01444   _current_context = ref_context ;
01445 
01446   ASSERT(!CORBA::is_nil(_current_context));
01447 
01448   if (isContextDestroyed)
01449     {
01450       try
01451         {
01452           _current_context->unbind(context_name);
01453           MESSAGE( "The bind to the context "
01454                    << context_name[0].id
01455                    << " has been deleted" );
01456         }
01457 
01458       catch (CosNaming::NamingContext::NotFound& ex)
01459         {
01460           CosNaming::Name n = ex.rest_of_name;
01461 
01462           if (ex.why == CosNaming::NamingContext::missing_node)
01463             INFOS( "Destroy_Directory() : " << (char *) n[0].id
01464                    << " (" << (char *) n[0].kind << ") not found" );
01465           if (ex.why == CosNaming::NamingContext::not_context)
01466             INFOS( "Destroy_Directory() : " << (char *) n[0].id
01467                    << " (" << (char *) n[0].kind
01468                    << ") is not a context" );
01469           if (ex.why == CosNaming::NamingContext::not_object)
01470             INFOS( "Destroy_Directory() : " << (char *) n[0].id
01471                    << " (" << (char *) n[0].kind
01472                    << ") is not an object" );
01473         }
01474 
01475       catch (CosNaming::NamingContext::CannotProceed&)
01476         {
01477           INFOS("Destroy_Directory: CosNaming::NamingContext::CannotProceed");
01478         }
01479 
01480       catch (CosNaming::NamingContext::InvalidName&)
01481         {
01482           INFOS("Destroy_Directory: CosNaming::NamingContext::InvalidName");
01483             }
01484 
01485       catch (CORBA::SystemException&)
01486         {
01487           INFOS("Destroy_Directory:CORBA::SystemException : unable to contact"
01488                  << " the naming service");
01489           throw ServiceUnreachable();
01490         }
01491     }
01492 }
01493 
01494 // ============================================================================
01502 // ============================================================================
01503 
01504 void SALOME_NamingService::Destroy_FullDirectory(const char* Path)
01505 throw(ServiceUnreachable)
01506 {
01507   MESSAGE("begin of Destroy_FullDirectory " << Path);
01508   if( Change_Directory(Path) )
01509     {
01510       std::vector<std::string> contList = list_directory();
01511 
01512       for (unsigned int ind = 0; ind < contList.size(); ind++)
01513         Destroy_Name(contList[ind].c_str());
01514       
01515       Destroy_Directory(Path);
01516     }
01517 }
01518 
01519 // ============================================================================
01525 // ============================================================================
01526 
01527 void SALOME_NamingService::_initialize_root_context()
01528 {
01529   //MESSAGE("Get the root context");
01530 
01531   try
01532     {
01533       CORBA::Object_var obj = _orb->resolve_initial_references("NameService");
01534       _root_context = CosNaming::NamingContext::_narrow(obj);
01535       _current_context = _root_context ;
01536       ASSERT(!CORBA::is_nil(_root_context));
01537     }
01538 
01539   catch (CORBA::SystemException&)
01540     {
01541       INFOS("CORBA::SystemException: unable to contact the naming service");
01542       throw ServiceUnreachable();
01543     }
01544 
01545   catch (...)
01546     {
01547       INFOS("Unknown Exception: unable to contact the naming service");
01548       throw ServiceUnreachable();
01549     }
01550 }
01551 
01552 // ============================================================================
01568 // ============================================================================
01569 
01570 int
01571 SALOME_NamingService::_createContextNameDir(std::string path,
01572                                             CosNaming::Name& context_name,
01573                                             std::vector<std::string>& splitPath,
01574                                             bool onlyDir)
01575 {
01576   if (path.empty())
01577     return 0;
01578 
01579   std::string::size_type begIdx, endIdx;
01580   const std::string delims("/");
01581   splitPath.resize(0);
01582   bool endWithDelim = false;
01583 
01584   begIdx = path.find_first_not_of(delims);
01585   while (begIdx != std::string::npos)
01586     {
01587       endIdx = path.find_first_of(delims, begIdx);
01588       if (endIdx == path.length()-1)
01589         endWithDelim = true;
01590       if (endIdx == std::string::npos)
01591         endIdx = path.length();
01592       int lsub = endIdx - begIdx;
01593       if (lsub >= 1)
01594         splitPath.push_back(path.substr(begIdx, lsub));
01595       begIdx = path.find_first_not_of(delims, endIdx);
01596     }
01597 
01598   int dim;
01599   if (onlyDir)                  // only directory part
01600     {
01601       dim = splitPath.size()-1; // omit final object
01602       if (endWithDelim)         // unless the path ends with a delimiter 
01603         dim++;
01604       endWithDelim = true;
01605     }
01606   else
01607     dim = splitPath.size();     // directories and final object
01608 
01609   context_name.length(dim);
01610   for (int i=0; i<dim; i++)
01611     {
01612 //       SCRUTE(splitPath[i]);
01613       context_name[i].id = CORBA::string_dup(splitPath[i].c_str());
01614       if (!endWithDelim && (i == dim-1)) // here, the last string is an object
01615         {
01616           context_name[i].kind = CORBA::string_dup("object");
01617 //        MESSAGE("--- " <<splitPath[i] <<".object");
01618         }
01619       else
01620         {
01621           context_name[i].kind = CORBA::string_dup("dir");
01622 //        MESSAGE("--- " <<splitPath[i] <<".dir");
01623         }
01624     }
01625   return dim;
01626 }
01627 
01628 // ============================================================================
01639 // ============================================================================
01640 
01641 void SALOME_NamingService::_Find(const char* name,
01642                                  CORBA::Long& occurence_number)
01643 {
01644   MESSAGE("BEGIN OF _Find "<<  occurence_number << " " << name);
01645 
01646   CosNaming::BindingList_var binding_list;
01647   CosNaming::BindingIterator_var binding_iterator;
01648   CosNaming::Binding_var binding;
01649 
01650   unsigned long nb = 0 ; // --- only for the use of the BindingIterator,
01651                          //     to access the bindings
01652 
01653   CosNaming::NamingContext_var ref_context = _current_context;
01654   CosNaming::NamingContext_var found_context = _current_context;
01655 
01656   _current_context->list(nb, binding_list, binding_iterator) ;
01657 
01658   if (! CORBA::is_nil(binding_iterator))
01659     {
01660       while (binding_iterator->next_one(binding))
01661         {
01662           CosNaming::Name bindingName = binding->binding_name;
01663           
01664           if (binding->binding_type == CosNaming::ncontext)
01665             {
01666               // --- We work on a directory,
01667               //     the search should be done in this directory
01668               
01669               Change_Directory(bindingName[0].id);
01670               _Find(name, occurence_number);
01671               
01672               // --- We'll go back to the initial context
01673               
01674               _current_context = ref_context ;
01675             }
01676           
01677           else if (binding->binding_type == CosNaming::nobject)
01678             {
01679               // --- We work on an object...
01680               
01681               if (!strcmp( bindingName[0].id, name))
01682                 {
01683                   //MESSAGE("One occurence was found");
01684                   occurence_number++;
01685                   
01686                   // --- We keep in memory the directory where
01687                   //     one occurence was found
01688                   
01689                   found_context = _current_context ;
01690                 }
01691             }
01692         }
01693       
01694       binding_iterator->destroy();
01695     }
01696   // --- We go to the last directory where an occurence was found
01697 
01698   _current_context = found_context;
01699 
01700   SCRUTE(occurence_number);
01701 }
01702 
01703 // ============================================================================
01713 // ============================================================================
01714 
01715 void
01716 SALOME_NamingService::
01717 _current_directory(std::vector<std::string>& splitPath,
01718                    int& lengthResult,
01719                    CosNaming::NamingContext_var contextToFind,
01720                    bool& notFound)
01721 {
01722   MESSAGE("BEGIN OF _current_Directory");
01723 
01724   CosNaming::BindingList_var binding_list;
01725   CosNaming::BindingIterator_var binding_iterator;
01726   CosNaming::Binding_var binding;
01727 
01728   unsigned long nb = 0 ; // --- only for the BindingIterator use,
01729                          //     to access the bindings
01730 
01731   CosNaming::NamingContext_var ref_context = _current_context;
01732   CosNaming::NamingContext_var temp_context = _current_context;
01733 
01734   _current_context->list(nb, binding_list, binding_iterator);
01735 
01736   if ( !binding_iterator->_is_nil() )
01737     {
01738       while ((binding_iterator->next_one(binding)) && notFound)
01739         {
01740           CosNaming::Name bindingName = binding->binding_name;
01741 
01742           if (binding->binding_type == CosNaming::ncontext)
01743             {
01744               // --- directory, search in it
01745 
01746               const char* bindingNameid=bindingName[0].id;
01747               splitPath.push_back(bindingNameid);
01748               lengthResult++;
01749 
01750               CORBA::Object_var obj = _current_context->resolve(bindingName);
01751               temp_context = CosNaming::NamingContext::_narrow(obj);
01752 
01753               if (temp_context->_is_equivalent(contextToFind))
01754                 {
01755                   MESSAGE("The context is found, we stop the search");
01756                   notFound = false;
01757                   SCRUTE(notFound);
01758                 }
01759 
01760               if (notFound)
01761                 {
01762                   SCRUTE(bindingName[0].id);
01763                   Change_Directory(bindingName[0].id);
01764                   _current_directory(splitPath,
01765                                      lengthResult,
01766                                      contextToFind,
01767                                      notFound);
01768 
01769                   if (notFound)
01770                     {
01771                       // --- go back to the initial context
01772 
01773                       _current_context = ref_context;
01774 
01775                       MESSAGE("Just before the delete of "
01776                               << splitPath[lengthResult-1]);
01777                       splitPath.pop_back();
01778                       lengthResult--;
01779                     }
01780                 }
01781             }
01782         }
01783 
01784       binding_iterator->destroy();
01785     }
01786 
01787   // --- return to the last directory where an occurence was found
01788 
01789   _current_context = ref_context ;
01790 }
01791 
01792 
01793 // ============================================================================
01806 // ============================================================================
01807 
01808 void SALOME_NamingService::_list_directory_recurs(std::vector<std::string>& myList,
01809                                                   std::string relativeSubDir,
01810                                                   std::string absCurDirectory)
01811 {
01812   CosNaming::BindingList_var binding_list;
01813   CosNaming::BindingIterator_var binding_iterator;
01814   CosNaming::Binding_var binding ;
01815 
01816   unsigned long nb = 0 ; // --- only for thethe use of BindingIterator
01817                          //     to access the bindings
01818 
01819   std::string absDir;
01820 
01821   CosNaming::NamingContext_var ref_context = _current_context;
01822 
01823   if (! relativeSubDir.empty())
01824     {
01825       Change_Directory(relativeSubDir.c_str());
01826       absDir = absCurDirectory + "/" + relativeSubDir;
01827     }
01828 
01829   else
01830     absDir = absCurDirectory;
01831 
01832   SCRUTE(absDir);
01833   _current_context->list(nb, binding_list, binding_iterator) ;
01834 
01835   if (! CORBA::is_nil(binding_iterator))
01836     {
01837       while (binding_iterator->next_one(binding))
01838         {
01839           CosNaming::Name bindingName = binding->binding_name;
01840 
01841           if (binding->binding_type == CosNaming::ncontext)
01842             {
01843               std::string relativeSdir(bindingName[0].id);
01844               _list_directory_recurs(myList, relativeSdir, absDir);
01845             }
01846 
01847           else if (binding->binding_type == CosNaming::nobject)
01848             {
01849               std::string objName(bindingName[0].id);
01850               std::string elt = absDir + "/" + objName;
01851               SCRUTE(elt);
01852               myList.push_back(elt);
01853             }
01854         }
01855 
01856       binding_iterator->destroy();
01857     }
01858   if (! relativeSubDir.empty())
01859     {
01860       _current_context = ref_context;
01861     }
01862 }
01863 
01864 // ============================================================================
01869 // ============================================================================
01870 
01871 char * SALOME_NamingService::getIORaddr()
01872 {
01873   return _orb->object_to_string(_root_context);
01874 }
01875 
01880 CORBA::ORB_ptr SALOME_NamingService::orb()
01881 {
01882   return _orb;
01883 }
01884