Salome HOME
PR: Swig LifeCycleCORBA
authorprascle <prascle>
Mon, 30 May 2005 12:14:43 +0000 (12:14 +0000)
committerprascle <prascle>
Mon, 30 May 2005 12:14:43 +0000 (12:14 +0000)
src/LifeCycleCORBA/Makefile.in
src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx
src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx
src/LifeCycleCORBA_SWIG/LifeCycleCORBA.py [new file with mode: 0644]
src/LifeCycleCORBA_SWIG/Makefile.in [new file with mode: 0644]
src/LifeCycleCORBA_SWIG/TestLifeCycleCORBA.py [new file with mode: 0644]
src/LifeCycleCORBA_SWIG/libSALOME_LifeCycleCORBA.i [new file with mode: 0644]
src/Makefile.in

index 3b825582f7d785653852de912d71719af4d8c3d5..b23e0d50ac11b8fcfb29b5c98c1525923a6ecc61 100644 (file)
@@ -36,7 +36,7 @@ VPATH=.:@srcdir@:@top_srcdir@/idl
 
 EXPORT_HEADERS = SALOME_LifeCycleCORBA.hxx
 
-EXPORT_PYSCRIPTS = LifeCycleCORBA.py Launchers.py
+EXPORT_PYSCRIPTS = Launchers.py
 
 # Libraries targets
 
index d6c18ede93c3514aba76fdd552e143a5e46639a3..f8b2463f778fb096cfa632762fec98d7d86d1f8f 100644 (file)
@@ -52,7 +52,15 @@ using namespace std;
 
 SALOME_LifeCycleCORBA::SALOME_LifeCycleCORBA(SALOME_NamingService *ns)
 {
-  _NS = ns;
+  if (!ns)
+    {
+      int argc = 0;
+      char *xargv = "";
+      char **argv = &xargv;
+      CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
+      _NS = new SALOME_NamingService(orb);
+    }
+  else _NS = ns;
   //add try catch
   _NS->Change_Directory("/"); // mpv 250105: current directory may be not root 
                               // (in SALOMEDS for an example)
@@ -188,7 +196,9 @@ SALOME_LifeCycleCORBA::LoadComponent(const Engines::MachineParameters& params,
 //=============================================================================
 /*! Public - 
  *  Find and aready existing and registered component instance or load a new
- *  component instance on a container defined by machine parameters
+ *  component instance on a container defined by machine parameters.
+ *  Renamed (Else / Or) to avoid problems with Python (Swig) version and keep
+ *  compatiblity with existing Python method FindOrLoadComponent
  *  \param params         machine parameters like type or name...
  *  \param componentName  the name of component class
  *  \param studyId        default = 0  : multistudy instance
@@ -198,9 +208,9 @@ SALOME_LifeCycleCORBA::LoadComponent(const Engines::MachineParameters& params,
 
 Engines::Component_ptr
 SALOME_LifeCycleCORBA::
-FindOrLoad_Component(const Engines::MachineParameters& params,
-                    const char *componentName,
-                    int studyId)
+FindElseLoadComponent(const Engines::MachineParameters& params,
+                     const char *componentName,
+                     int studyId)
 {
   if (! isKnownComponentClass(componentName))
     return Engines::Component::_nil();
@@ -275,7 +285,7 @@ SALOME_LifeCycleCORBA::FindOrLoad_Component(const char *containerName,
       params->hostname=CORBA::string_dup(stContainer);
       params->OS=CORBA::string_dup("LINUX");
       free(stContainer);
-      return FindOrLoad_Component(params,componentName);
+      return FindElseLoadComponent(params,componentName);
     }
 }
 
index d86a7a471d5f9dee08f1abced5dc0567650109b6..d419c3596cee490fed6b910a88af2cc410d49119 100644 (file)
@@ -42,7 +42,7 @@ class SALOME_NamingService;
 class SALOME_LifeCycleCORBA
 {
 public:
-  SALOME_LifeCycleCORBA(SALOME_NamingService *ns);
+  SALOME_LifeCycleCORBA(SALOME_NamingService *ns = 0);
   virtual ~SALOME_LifeCycleCORBA();
 
   Engines::Container_ptr 
@@ -60,9 +60,9 @@ public:
                int studyId=0);
 
   Engines::Component_ptr 
-  FindOrLoad_Component(const Engines::MachineParameters& params,
-                      const char *componentName,
-                      int studyId=0);
+  FindElseLoadComponent(const Engines::MachineParameters& params,
+                       const char *componentName,
+                       int studyId=0);
 
   Engines::Component_ptr
   FindOrLoad_Component(const char *containerName,
diff --git a/src/LifeCycleCORBA_SWIG/LifeCycleCORBA.py b/src/LifeCycleCORBA_SWIG/LifeCycleCORBA.py
new file mode 100644 (file)
index 0000000..f88ef87
--- /dev/null
@@ -0,0 +1,41 @@
+#  SALOME LifeCycleCORBA : implementation of containers and engines life cycle both in Python and C++
+#
+#  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   : LifeCycleCORBA.py
+#  Author : Paul RASCLE, EDF
+#  Module : SALOME
+#  $Header$
+
+
+import Engines
+from libSALOME_LifeCycleCORBA import *
+
+class LifeCycleCORBA (SALOME_LifeCycleCORBA):
+
+    def __init__(self, orb = None):
+        SALOME_LifeCycleCORBA.__init__(self)
+
+    def FindOrLoadComponent(self, containerName, componentName):
+        return SALOME_LifeCycleCORBA.FindOrLoad_Component(self,
+                                                          containerName,
+                                                          componentName)
diff --git a/src/LifeCycleCORBA_SWIG/Makefile.in b/src/LifeCycleCORBA_SWIG/Makefile.in
new file mode 100644 (file)
index 0000000..c4c55c8
--- /dev/null
@@ -0,0 +1,52 @@
+#  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@
+
+# Libraries targets
+
+LIB = libSALOME_LifeCycleCORBAcmodule.la
+LIB_SRC = 
+
+LIB_CLIENT_IDL = SALOME_Component.idl SALOME_ContainerManager.idl
+
+SWIG_DEF = libSALOME_LifeCycleCORBA.i
+
+EXPORT_PYSCRIPTS = libSALOME_LifeCycleCORBA.py LifeCycleCORBA.py TestLifeCycleCORBA.py
+
+CPPFLAGS+= $(PYTHON_INCLUDES)
+
+LIBS+= $(PYTHON_LIBS) -lSalomeLifeCycleCORBA
+
+LDFLAGS+=
+
+@CONCLUDE@
diff --git a/src/LifeCycleCORBA_SWIG/TestLifeCycleCORBA.py b/src/LifeCycleCORBA_SWIG/TestLifeCycleCORBA.py
new file mode 100644 (file)
index 0000000..c824108
--- /dev/null
@@ -0,0 +1,10 @@
+
+import Engines
+import LifeCycleCORBA
+
+lcc = LifeCycleCORBA.LifeCycleCORBA()
+
+obj=lcc.FindOrLoad_Component("FactoryServer","SalomeTestComponent")
+comp=obj._narrow(Engines.TestComponent)
+comp.Coucou(1)
+
diff --git a/src/LifeCycleCORBA_SWIG/libSALOME_LifeCycleCORBA.i b/src/LifeCycleCORBA_SWIG/libSALOME_LifeCycleCORBA.i
new file mode 100644 (file)
index 0000000..07034b2
--- /dev/null
@@ -0,0 +1,91 @@
+
+
+%module libSALOME_LifeCycleCORBA
+
+%{
+#include "utilities.h"
+#include "SALOME_LifeCycleCORBA.hxx"
+
+  using namespace std;
+%}
+
+%typemap(python,out) Engines::Container_ptr, Engines::Component_ptr
+{
+  MESSAGE("typemap out on CORBA object ptr");
+  SCRUTE($1);
+
+  // --- Get the Python orb
+
+  PyObject* pdict = PyDict_New();
+  PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
+  PyRun_String("import CORBA", Py_single_input, pdict, pdict);
+  PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input,
+                   pdict, pdict);
+  PyObject* orb = PyDict_GetItemString(pdict, "o");
+
+  // --- Get the C++ orb
+
+  int argc = 0;
+  char *xargv = "";
+  char **argv = &xargv;
+  CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv);
+  string s =  ORB->object_to_string($1);
+  SCRUTE(s);
+  PyObject * tmp = PyString_FromString(s.c_str());
+  SCRUTE(tmp);
+  $result = PyObject_CallMethod(orb, "string_to_object", "O", tmp);
+  SCRUTE($result);
+}
+
+%typemap(python,in) const Engines::MachineParameters &
+{
+  MESSAGE("typemap in on Engines::MachineParameters");
+  ASSERT (PyDict_Check($input))
+    {
+      Engines::MachineParameters *param = new Engines::MachineParameters ;
+      PyObject *key, *value;
+      int pos = 0;
+      while (PyDict_Next($input, &pos, &key, &value))
+       {
+         char* keystr = PyString_AsString(key);
+         MESSAGE("key: " << keystr);
+         if (strcmp(keystr,"container_name")==0)
+           {
+             param->container_name = CORBA::string_dup(PyString_AsString(value));
+           }
+         else if (strcmp(keystr,"hostname")==0)
+           {
+             param->hostname = CORBA::string_dup(PyString_AsString(value));
+           }
+         else if (strcmp(keystr,"OS")==0)
+           {
+             param->OS = CORBA::string_dup(PyString_AsString(value));
+           }
+         else if (strcmp(keystr,"mem_mb")==0)
+           {
+             param->mem_mb = PyLong_AsLong(value);
+           }
+         else if (strcmp(keystr,"cpu_clock")==0)
+           {
+             param->cpu_clock = PyLong_AsLong(value);
+           }
+         else if (strcmp(keystr,"nb_proc_per_node")==0)
+           {
+             param->nb_proc_per_node = PyLong_AsLong(value);
+           }
+         else if (strcmp(keystr,"nb_node")==0)
+           {
+             param->nb_node = PyLong_AsLong(value);
+           }
+       }
+      $1 = param;
+    }
+}
+
+%typemap(python,freearg) const Engines::MachineParameters &
+{
+  MESSAGE("delete $1");
+  delete $1;
+}
+
+%include "SALOME_LifeCycleCORBA.hxx"
index d0daa6ea2ccadc113dbad80d8cfa27adc50801cd..9912d266b97a04b66742f8df0d6f8e2718a54f35 100644 (file)
@@ -37,7 +37,7 @@ SUBDIRS = MSG2QM SALOMELocalTrace SALOMETraceCollector Logger Utils CASCatch Pat
           GenericObj MEDWrapper NamingService Registry \
          ModuleCatalog DataTypeCatalog RessourcesCatalog \
           ResourcesManager Notification  NOTIFICATION_SWIG \
-         Container TestContainer LifeCycleCORBA HDFPersist Prs \
+         Container TestContainer LifeCycleCORBA LifeCycleCORBA_SWIG HDFPersist Prs \
          VTKFilter OBJECT \
           TOOLSDS SALOMEDS Event \
           SALOMEGUI TOOLSGUI Plot2d VTKViewer OCCViewer \