Salome HOME
Porting to Python 2.6 - add coding page specification for Python scripts
[modules/kernel.git] / src / NamingService / SALOME_NamingService.cxx
index 965982293b32d97fd5e03564deb4631bb21248c4..70d337008f190dc5fe79c3599db7a518e6c35ba4 100644 (file)
@@ -1,6 +1,6 @@
-//  SALOME NamingService : wrapping NamingService services
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  Copyright (C) 2003-2007  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
 //  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+//  SALOME NamingService : wrapping NamingService services
 //  File   : SALOME_NamingService.cxx
 //  Author : Estelle Deville
 //  Module : SALOME
 //  $Header$
-
+//
 #include "SALOME_NamingService.hxx"
 #include "ServiceUnreachable.hxx"
 
 
 using namespace std;
 
+/*! \class SALOME_NamingService
+    \brief A class to manage the SALOME naming service
+
+*/
+
 // ============================================================================
 /*! \brief Default Constructor without ORB reference.
  *
@@ -63,7 +67,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();
 }
 
@@ -86,6 +90,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
  */ 
 // ============================================================================
@@ -95,7 +100,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();
 }
@@ -339,7 +350,7 @@ CORBA::Object_ptr SALOME_NamingService::Resolve(const char* Path)
 
   CosNaming::Name context_name;
   vector<string> splitPath;
-  int dimension_resultat = _createContextNameDir(Path,
+  _createContextNameDir(Path,
                                                 context_name,
                                                 splitPath,
                                                 false);
@@ -514,7 +525,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();
 
@@ -538,6 +550,8 @@ SALOME_NamingService::ResolveComponent(const char* hostname,
 
              if ( !CORBA::is_nil(obj) )
                return obj;
+              else
+                Change_Directory(basename.c_str());
            }
        }
 
@@ -803,7 +817,7 @@ throw(ServiceUnreachable)
 //   SCRUTE(path);
   CosNaming::Name context_name;
   vector<string> splitPath;
-  int dimension_resultat = _createContextNameDir(path.c_str(),
+  _createContextNameDir(path.c_str(),
                                                 context_name,
                                                 splitPath,
                                                 true);
@@ -1818,3 +1832,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;
+}
+