X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FLifeCycleCORBA_SWIG%2FlibSALOME_LifeCycleCORBA.i;h=b931551a7bfa753f8d650110525b1896b84b26f5;hb=d8edd4804d9e6513a17c497c1a30326d4ba0d677;hp=d2d5fe26866fac3e40e762b5bf3724032d206e1f;hpb=7d2fe213bdf5bf962ce11e253020c9d3e0bc1cce;p=modules%2Fkernel.git diff --git a/src/LifeCycleCORBA_SWIG/libSALOME_LifeCycleCORBA.i b/src/LifeCycleCORBA_SWIG/libSALOME_LifeCycleCORBA.i index d2d5fe268..b931551a7 100644 --- a/src/LifeCycleCORBA_SWIG/libSALOME_LifeCycleCORBA.i +++ b/src/LifeCycleCORBA_SWIG/libSALOME_LifeCycleCORBA.i @@ -1,24 +1,25 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// 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 +// 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. +// 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. +// 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 +// 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 +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // ---------------------------------------------------------------------------- // %module libSALOME_LifeCycleCORBA @@ -26,6 +27,7 @@ %feature("autodoc", "1"); %include +%include "std_string.i" // ---------------------------------------------------------------------------- @@ -43,29 +45,9 @@ typedef int Py_ssize_t; #define PY_SSIZE_T_MIN INT_MIN #endif - using namespace std; - -//--- from omniORBpy.h (not present on Debian Sarge packages) - -struct omniORBpyAPI { - - PyObject* (*cxxObjRefToPyObjRef)(const CORBA::Object_ptr cxx_obj, - CORBA::Boolean hold_lock); - // Convert a C++ object reference to a Python object reference. - // If is true, caller holds the Python interpreter lock. - - CORBA::Object_ptr (*pyObjRefToCxxObjRef)(PyObject* py_obj, - CORBA::Boolean hold_lock); - // Convert a Python object reference to a C++ object reference. - // Raises BAD_PARAM if the Python object is not an object reference. - // If is true, caller holds the Python interpreter lock. - - - omniORBpyAPI(); - // Constructor for the singleton. Sets up the function pointers. -}; - - omniORBpyAPI* api; +#include +#include +omniORBpyAPI* api=0; %} @@ -80,12 +62,11 @@ struct omniORBpyAPI { PyObject* omnipy = PyImport_ImportModule((char*)"_omnipy"); if (!omnipy) { - PyErr_SetString(PyExc_ImportError, - (char*)"Cannot import _omnipy"); - return; + PyErr_SetString(PyExc_ImportError, (char*)"Cannot import _omnipy"); + return NULL; } PyObject* pyapi = PyObject_GetAttrString(omnipy, (char*)"API"); - api = (omniORBpyAPI*)PyCObject_AsVoidPtr(pyapi); + api = (omniORBpyAPI*)PyCapsule_GetPointer(pyapi,"_omnipy.API"); Py_DECREF(pyapi); %} @@ -93,7 +74,8 @@ struct omniORBpyAPI { // ---------------------------------------------------------------------------- -%typemap(python,out) Engines::Container_ptr, Engines::Component_ptr, Engines::fileRef_ptr +%typemap(out) Engines::Container_ptr, Engines::EngineComponent_ptr, Engines::fileRef_ptr, + Engines::ContainerManager_ptr, Engines::ResourcesManager_ptr { MESSAGE("typemap out on CORBA object ptr"); SCRUTE($1); @@ -101,7 +83,12 @@ struct omniORBpyAPI { SCRUTE($result); } -%typemap(python,in) Engines::fileRef_ptr aFileRef +%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) Engines::fileRef_ptr +{ + $1=PyObject_HasAttrString($input, "__omni_obj"); +} + +%typemap(in) Engines::fileRef_ptr aFileRef { MESSAGE("typemap in on CORBA object ptr"); try { @@ -114,126 +101,87 @@ struct omniORBpyAPI { } } - -%typemap(python,out) std::string, - string -{ - MESSAGE("typemap out on std::string"); - SCRUTE($1); - $result = PyString_FromString($1.c_str()); -} - -%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) Engines::MachineParameters const & -{ - $1 = PyDict_Check($input)? 1 : 0; -} -%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) const Engines::MachineParameters & +// We use a dictionary to represent ContainerParameters structure instead of the CORBA +// structure itself because it would require a transformation from the Python +// ContainerParameters structure, generated by omniOrbPy, to a C++ ContainerParameters +// structure, generated by omniOrb, and this would be quite complex. +%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) const Engines::ContainerParameters & { $1 = PyDict_Check($input)? 1 : 0; } -%typemap(typecheck) std::string, - string -{ - $1 = PyString_Check($input); -} - -%typemap(python,in) std::string, - string +%typemap(in) const Engines::ContainerParameters & { - MESSAGE("typemap in on std::string"); - std::string str; - if (PyString_Check($input) == 1) - { - char* value = PyString_AsString($input); - str = value; - $1 = str; - } - else - { - MESSAGE("Not a string"); - PyErr_SetString(PyExc_TypeError,"Must Be a Python string"); - return NULL; - } -} - - -%typemap(python,in) const Engines::MachineParameters & -{ - //printf("typemap in on Engines::MachineParameters\n"); - MESSAGE("typemap in on Engines::MachineParameters"); + MESSAGE("typemap in on Engines::ContainerParameters"); if (PyDict_Check($input) == 1) { - Engines::MachineParameters *param = new Engines::MachineParameters ; - param->container_name = CORBA::string_dup(""); - param->hostname = CORBA::string_dup(""); - param->OS = CORBA::string_dup(""); - param->mem_mb = 0; - param->cpu_clock = 0; - param->nb_proc_per_node = 0; - param->nb_node = 0; - param->isMPI = false; - param->parallelLib = CORBA::string_dup(""); - param->nb_component_nodes = 0; + Engines::ContainerParameters *param = new Engines::ContainerParameters ; + SALOME_LifeCycleCORBA::preSet(*param); + PyObject *key, *value; Py_ssize_t pos = 0; while (PyDict_Next($input, &pos, &key, &value)) - { - char* keystr = PyString_AsString(key); - printf("key: %s\n", 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); - } - else if (strcmp(keystr,"isMPI")==0) - { - param->isMPI = PyLong_AsLong(value); - } - else if (strcmp(keystr,"parallelLib")==0) - { - param->parallelLib = CORBA::string_dup(PyString_AsString(value)); - } - else if (strcmp(keystr,"nb_component_nodes")==0) - { - param->nb_component_nodes = PyLong_AsLong(value); - } - } + { + char* keystr = PyString_AsString(key); + if (strcmp(keystr,"container_name")==0) + { + param->container_name = CORBA::string_dup(PyString_AsString(value)); + } + else if (strcmp(keystr,"resource_name")==0) + { + param->resource_params.name = CORBA::string_dup(PyString_AsString(value)); + } + else if (strcmp(keystr,"hostname")==0) + { + param->resource_params.hostname = CORBA::string_dup(PyString_AsString(value)); + } + else if (strcmp(keystr,"OS")==0) + { + param->resource_params.OS = CORBA::string_dup(PyString_AsString(value)); + } + else if (strcmp(keystr,"mem_mb")==0) + { + param->resource_params.mem_mb = PyLong_AsLong(value); + } + else if (strcmp(keystr,"cpu_clock")==0) + { + param->resource_params.cpu_clock = PyLong_AsLong(value); + } + else if (strcmp(keystr,"nb_proc_per_node")==0) + { + param->resource_params.nb_proc_per_node = PyLong_AsLong(value); + } + else if (strcmp(keystr,"nb_node")==0) + { + param->resource_params.nb_node = PyLong_AsLong(value); + } + else if (strcmp(keystr,"isMPI")==0) + { + param->isMPI = PyLong_AsLong(value); + } + else if (strcmp(keystr,"workingdir")==0) + param->workingdir = CORBA::string_dup(PyString_AsString(value)); + else if (strcmp(keystr,"mode")==0) + param->mode = CORBA::string_dup(PyString_AsString(value)); + else if (strcmp(keystr,"policy")==0) + param->resource_params.policy = CORBA::string_dup(PyString_AsString(value)); + else if (strcmp(keystr,"parallelLib")==0) + { + param->parallelLib = CORBA::string_dup(PyString_AsString(value)); + } + } $1 = param; } else { - MESSAGE("Not a dictionnary"); - PyErr_SetString(PyExc_TypeError,"Must Be a Python Dictionnary"); + MESSAGE("Not a ContainerParameters struct"); + PyErr_SetString(PyExc_TypeError,"Must Be a Python ContainerParameters object"); return NULL; } } -%typemap(python,freearg) const Engines::MachineParameters & +%typemap(freearg) const Engines::ContainerParameters & { MESSAGE("delete $1"); delete $1; @@ -248,7 +196,7 @@ struct omniORBpyAPI { try { $action } - catch (ServiceUnreachable) { + catch (ServiceUnreachable&) { Py_BLOCK_THREADS PyErr_SetString(PyExc_RuntimeError,"Naming Service Unreacheable"); return NULL; @@ -274,4 +222,3 @@ struct omniORBpyAPI { %include %include -