]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
On donne acces en python a SALOME_Fake_NamingService C++ avec le module python Naming...
authorAnthony Geay <anthony.geay@edf.fr>
Tue, 20 Apr 2021 06:39:45 +0000 (08:39 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Tue, 20 Apr 2021 06:39:45 +0000 (08:39 +0200)
src/NamingService/CMakeLists.txt
src/NamingService/NamingService.i [new file with mode: 0644]
src/NamingService/SALOME_Fake_NamingService.cxx
src/NamingService/SALOME_Fake_NamingService.hxx
src/NamingService/SALOME_NamingService.cxx
src/NamingService/SALOME_NamingService.hxx
src/NamingService/SALOME_NamingService.i [deleted file]
src/NamingService/SALOME_NamingService_Abstract.hxx

index 1de6ae9fc62db5cd426cbf1340ca5a0790f8a5d9..051bfb4bba39dcede1c46c397695374977a28f0a 100644 (file)
@@ -17,6 +17,8 @@
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
+include(${SWIG_USE_FILE})
+
 INCLUDE_DIRECTORIES(
   ${OMNIORB_INCLUDE_DIR}
   ${PTHREAD_INCLUDE_DIR}
@@ -28,6 +30,7 @@ INCLUDE_DIRECTORIES(
   ${CMAKE_CURRENT_SOURCE_DIR}/../LifeCycleCORBA
   ${CMAKE_CURRENT_SOURCE_DIR}
   ${PROJECT_BINARY_DIR}/idl
+  ${PYTHON_INCLUDE_DIRS}
   )
 
 SET(SalomeNS_SOURCES
@@ -54,3 +57,19 @@ SALOME_INSTALL_SCRIPTS(SALOME_Embedded_NamingService_ClientPy.py ${SALOME_INSTAL
 
 FILE(GLOB COMMON_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx")
 INSTALL(FILES ${COMMON_HEADERS_HXX} DESTINATION ${SALOME_INSTALL_HEADERS})
+
+SET(NamingService_HEADERS NamingService.i)
+SET(NamingService_SOURCES ${NamingService_HEADERS})
+SET_SOURCE_FILES_PROPERTIES(NamingService.i PROPERTIES CPLUSPLUS ON)
+SET_SOURCE_FILES_PROPERTIES(NamingService.i PROPERTIES SWIG_FLAGS "-py3")
+SET_SOURCE_FILES_PROPERTIES(NamingService_wrap.cpp PROPERTIES COMPILE_FLAGS "-DHAVE_CONFIG_H")
+SET(_swig_SCRIPTS ${CMAKE_CURRENT_BINARY_DIR}/NamingService.py )
+IF(${CMAKE_VERSION} VERSION_LESS "3.8.0") 
+  SWIG_ADD_MODULE(NamingService python ${NamingService_SOURCES})
+ELSE()
+  SWIG_ADD_LIBRARY(NamingService LANGUAGE python SOURCES ${NamingService_SOURCES})
+ENDIF()
+SWIG_LINK_LIBRARIES(NamingService ${PYTHON_LIBRARIES} ${PLATFORM_LIBS} SalomeNS)
+install(TARGETS _NamingService DESTINATION ${SALOME_INSTALL_LIBS})
+install(FILES ${NamingService_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS})
+SALOME_INSTALL_SCRIPTS("${_swig_SCRIPTS}"  ${SALOME_INSTALL_BINS} EXTRA_DPYS "${SWIG_MODULE_NamingService_REAL_NAME}")
diff --git a/src/NamingService/NamingService.i b/src/NamingService/NamingService.i
new file mode 100644 (file)
index 0000000..a477d61
--- /dev/null
@@ -0,0 +1,68 @@
+// Copyright (C) 2021  CEA/DEN, EDF R&D
+//
+// 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, or (at your option) any later version.
+//
+// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+%module NamingService
+
+%{
+#include "SALOME_Fake_NamingService.hxx"
+#include "SALOME_KernelORB.hxx"
+%}
+
+%include "std_string.i"
+%include "std_vector.i"
+
+%rename(NamingService) SALOME_Fake_NamingService ;
+
+%template(svec) std::vector<std::string>;
+
+class SALOME_Fake_NamingService
+{
+public:
+  SALOME_Fake_NamingService();
+  std::vector< std::string > repr();
+  %extend {
+    std::string _ResolveInternal(const char *Path)
+    {
+      CORBA::Object_var obj = self->Resolve(Path);
+      CORBA::ORB_ptr orb = KERNEL::getORB();
+      CORBA::String_var ior = orb->object_to_string(obj);
+      return std::string(ior);
+    }
+    void _RegisterInternal(const char *ior, const char* Path)
+    {
+      CORBA::ORB_ptr orb = KERNEL::getORB();
+      CORBA::Object_var obj = orb->string_to_object(ior);
+      self->Register(obj,Path);
+    }
+  }
+};
+
+%pythoncode %{
+def NamingService_Resolve(self,Path):
+  ret = self._ResolveInternal(Path)
+  import CORBA
+  orb=CORBA.ORB_init([''])
+  return orb.string_to_object(ret)
+def NamingService_Register(self,obj,Path):
+  import CORBA
+  orb=CORBA.ORB_init([''])
+  self._RegisterInternal( orb.object_to_string(obj) , Path)
+NamingService.Resolve = NamingService_Resolve
+NamingService.Register = NamingService_Register
+%}
index 15d378aaa072f10b5f6d18ba157c8769d7b42356..9dd24c20f0071ec3f30d5a39022c01d5c4c04b22 100644 (file)
@@ -29,15 +29,15 @@ SALOME_Fake_NamingService::SALOME_Fake_NamingService(CORBA::ORB_ptr orb)
 {
 }
 
-std::string SALOME_Fake_NamingService::repr()
+std::vector< std::string > SALOME_Fake_NamingService::repr()
 {
   std::lock_guard<std::mutex> g(_mutex);
-  std::ostringstream oss;
+  std::vector< std::string > ret;
   for(auto it : _map)
   {
-    oss << it.first << std::endl;
+    ret.push_back( it.first );
   }
-  return oss.str();
+  return ret;
 }
 
 void SALOME_Fake_NamingService::init_orb(CORBA::ORB_ptr orb)
index 64a107937f615ae821e0d78944dd4b513e0a370b..1288aed749a07fd82a2efecbf8a8acd40deb61f7 100644 (file)
@@ -32,7 +32,7 @@ class NAMINGSERVICE_EXPORT SALOME_Fake_NamingService : public SALOME_NamingServi
 public:
     SALOME_Fake_NamingService(CORBA::ORB_ptr orb);
     SALOME_Fake_NamingService() = default;
-    std::string repr() override;
+    std::vector< std::string > repr() override;
     void init_orb(CORBA::ORB_ptr orb=0) override;
     void Register(CORBA::Object_ptr ObjRef, const char* Path) override;
     CORBA::Object_ptr Resolve(const char* Path) override;
index d3f62fddd823431e69f06a48f7f4ea29aea5aa1a..898a83c163bd2dcd6055ca2d028f6ec1061c9242 100644 (file)
@@ -92,9 +92,9 @@ SALOME_NamingService::~SALOME_NamingService()
   //MESSAGE("SALOME_NamingService destruction");
 }
 
-std::string SALOME_NamingService::repr()
+std::vector< std::string > SALOME_NamingService::repr()
 {
-  return std::string();
+  return std::vector< std::string >();
 }
 
 // ============================================================================
index 78a62fc446224906b198fe2d3c5f4f872352cb14..ec19bb7b7a89f55667d0a73ca9bd4572d6ed3f65 100644 (file)
@@ -51,7 +51,7 @@ public:
   SALOME_NamingService(CORBA::ORB_ptr orb);
 
   virtual ~SALOME_NamingService();
-  std::string repr() override;
+  std::vector< std::string > repr() override;
   void init_orb(CORBA::ORB_ptr orb=0) override;
   void Register(CORBA::Object_ptr ObjRef, const char* Path) override;
   CORBA::Object_ptr Resolve(const char* Path) override; 
diff --git a/src/NamingService/SALOME_NamingService.i b/src/NamingService/SALOME_NamingService.i
deleted file mode 100644 (file)
index 9369d02..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-// Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// 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
-// 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, or (at your option) any later version.
-//
-// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-
-//  SALOME NamingService : wrapping NamingService services
-//  File   : SALOME_NamingService.i
-//  Author : Paul RASCLE, EDF
-//  Module : SALOME
-//  $Header$
-//
-%{
-#include "SALOME_NamingService.hxx"
-//#include <omniORB4/CORBA.h>
-#include <omniORB3/CORBA.h>
-#include "ServiceUnreachable.hxx"
-%}
-
-%except(python)
-{
-  try 
-    {
-      $function
-    }
-  catch (ServiceUnreachable)
-    {
-      PyErr_SetString(PyExc_IndexError,"Naming Service Unreacheable");
-      return NULL;
-    }
-}
-
-class SALOME_NamingService
-{
-public:
-
-  //! standard constructor
-  SALOME_NamingService();
-
-  //! 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)
-    throw(ServiceUnreachable);
-
-  //! method to get the ObjRef of a symbolic name
-  CORBA::Object_ptr Resolve(const char* Path)
-    throw( ServiceUnreachable);
-
-  //! method to research a name from the naming service's current directory
-  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 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);
-};
-
index dc86047e3af401ed9b5e45156ae70287cd5e3b43..fdd6ae0d4775879511021845cca60d04b451a5a9 100644 (file)
@@ -45,7 +45,7 @@ class NAMINGSERVICE_EXPORT SALOME_NamingService_Abstract : public SALOME_NamingS
 {
 public:
   SALOME_NamingService_Abstract *cloneCoVar();
-  virtual std::string repr() = 0;
+  virtual std::vector< std::string > repr() = 0;
   virtual void Destroy_Directory(const char* Path) = 0;
   virtual bool Change_Directory(const char* Path) = 0;
   virtual std::vector<std::string> list_subdirs() = 0;