Salome HOME
Merge from V5_1_3_BR 07/12/2009
[modules/kernel.git] / src / NamingService / SALOME_NamingService.cxx
index ab6eece0aa5780cfea2f62180988a9cbe604a345..ece4ca55a46f4f2b419a0f5ef4aaaa190325d8c3 100644 (file)
@@ -33,6 +33,7 @@
 #include <iostream>
 #include <cstring>
 #include <string>
+#include <cstdio>
 
 using namespace std;
 
@@ -67,7 +68,7 @@ SALOME_NamingService::SALOME_NamingService()
 SALOME_NamingService::SALOME_NamingService(CORBA::ORB_ptr orb)
 {
   MESSAGE("SALOME_NamingService creation");
-  _orb = orb ;
+  _orb = CORBA::ORB::_duplicate(orb);
   _initialize_root_context();
 }
 
@@ -90,6 +91,7 @@ SALOME_NamingService::~SALOME_NamingService()
  * 
  *  Initializes ORB reference and naming service root context.
  *  For use after default constructor.
+ *  If param orb is null, the orb is initialized
  *  \param orb CORBA::ORB_ptr arguments
  */ 
 // ============================================================================
@@ -99,7 +101,13 @@ void SALOME_NamingService::init_orb(CORBA::ORB_ptr orb)
   MESSAGE("SALOME_NamingService initialisation");
 
   Utils_Locker lock (&_myMutex);
-  _orb = orb;
+  if(orb)
+    _orb = CORBA::ORB::_duplicate(orb);
+  else
+    {
+      int argc=0;
+      _orb = CORBA::ORB_init(argc, 0); // Here we make the assumption that the orb has already been initialized
+    }
 
   _initialize_root_context();
 }
@@ -518,7 +526,8 @@ SALOME_NamingService::ResolveComponent(const char* hostname,
   else
     {
       SCRUTE(name);
-      if (Change_Directory(name.c_str()))
+      string basename = name;
+      if (Change_Directory(basename.c_str()))
        {
          vector<string> contList = list_subdirs();
 
@@ -542,6 +551,8 @@ SALOME_NamingService::ResolveComponent(const char* hostname,
 
              if ( !CORBA::is_nil(obj) )
                return obj;
+              else
+                Change_Directory(basename.c_str());
            }
        }
 
@@ -1822,3 +1833,12 @@ char * SALOME_NamingService::getIORaddr()
   return _orb->object_to_string(_root_context);
 }
 
+/*! \brief get the orb used by the naming service
+ *
+ *  \return the orb
+ */
+CORBA::ORB_ptr SALOME_NamingService::orb()
+{
+  return _orb;
+}
+