Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/kernel.git] / src / LifeCycleCORBA_SWIG / libSALOME_LifeCycleCORBA.i
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20
21
22 %module libSALOME_LifeCycleCORBA
23
24 %{
25 #include "utilities.h"
26 #include "SALOME_LifeCycleCORBA.hxx"
27 #include "SALOME_FileTransferCORBA.hxx"
28 #include "SALOME_NamingService.hxx"
29 #include "ServiceUnreachable.hxx"
30
31   using namespace std;
32
33 //--- from omniORBpy.h (not present on Debian Sarge packages)
34
35 struct omniORBpyAPI {
36
37   PyObject* (*cxxObjRefToPyObjRef)(const CORBA::Object_ptr cxx_obj,
38                                    CORBA::Boolean hold_lock);
39   // Convert a C++ object reference to a Python object reference.
40   // If <hold_lock> is true, caller holds the Python interpreter lock.
41
42   CORBA::Object_ptr (*pyObjRefToCxxObjRef)(PyObject* py_obj,
43                                            CORBA::Boolean hold_lock);
44   // Convert a Python object reference to a C++ object reference.
45   // Raises BAD_PARAM if the Python object is not an object reference.
46   // If <hold_lock> is true, caller holds the Python interpreter lock.
47
48
49   omniORBpyAPI();
50   // Constructor for the singleton. Sets up the function pointers.
51 };
52
53   omniORBpyAPI* api;
54
55 %}
56
57
58 %init
59 %{
60   // init section
61
62   PyObject* omnipy = PyImport_ImportModule((char*)"_omnipy");
63   if (!omnipy)
64   {
65     PyErr_SetString(PyExc_ImportError,
66                     (char*)"Cannot import _omnipy");
67     return;
68   }
69   PyObject* pyapi = PyObject_GetAttrString(omnipy, (char*)"API");
70   api = (omniORBpyAPI*)PyCObject_AsVoidPtr(pyapi);
71   Py_DECREF(pyapi);
72 %}
73
74
75 %exception {
76     try {
77       $action
78     }
79     catch (ServiceUnreachable) {
80       PyErr_SetString(PyExc_RuntimeError,"Naming Service Unreacheable");
81       return NULL;
82     }
83     catch (...) {
84       PyErr_SetString(PyExc_RuntimeError, "unknown exception");
85       return NULL;
86     }
87 }
88
89
90 %typemap(python,out) Engines::Container_ptr, Engines::Component_ptr, Engines::fileRef_ptr
91 {
92   MESSAGE("typemap out on CORBA object ptr");
93   SCRUTE($1);
94   $result = api->cxxObjRefToPyObjRef($1, 1);
95   SCRUTE($result);
96 }
97
98 %typemap(python,out) std::string, 
99                     string
100 {
101   MESSAGE("typemap out on std::string");
102   SCRUTE($1);
103   $result = PyString_FromString($1.c_str());
104 }
105
106 %typemap(typecheck) const Engines::MachineParameters &,
107                     Engines::MachineParameters const &
108 {
109   $1 = PyDict_Check($input);
110 }
111
112 %typemap(typecheck) std::string, 
113                     string
114 {
115   $1 = PyString_Check($input);
116 }
117
118 %typemap(python,in) std::string, 
119                     string
120 {
121   MESSAGE("typemap in on std::string");
122   std::string str;
123   if (PyString_Check($input) == 1)
124     {
125       char* value = PyString_AsString($input);
126       str = value;
127       $1 = str;
128     }
129   else 
130     {
131        MESSAGE("Not a string");
132        PyErr_SetString(PyExc_TypeError,"Must Be a Python string");
133        return NULL;
134     }
135 }
136
137
138 %typemap(python,in) const Engines::MachineParameters &
139 {
140   //printf("typemap in on Engines::MachineParameters\n");
141   MESSAGE("typemap in on Engines::MachineParameters");
142   if (PyDict_Check($input) == 1)
143     {
144       Engines::MachineParameters *param = new Engines::MachineParameters ;
145       param->container_name = CORBA::string_dup("");
146       param->hostname = CORBA::string_dup("");
147       param->OS = CORBA::string_dup("");
148       param->mem_mb = 0;
149       param->cpu_clock = 0;
150       param->nb_proc_per_node = 0;
151       param->nb_node = 0;
152       param->isMPI = false;
153       PyObject *key, *value;
154       int pos = 0;
155       while (PyDict_Next($input, &pos, &key, &value))
156         {
157           char* keystr = PyString_AsString(key);
158           printf("key: %s\n", keystr);
159           if (strcmp(keystr,"container_name")==0)
160             {
161               param->container_name = CORBA::string_dup(PyString_AsString(value));
162             }
163           else if (strcmp(keystr,"hostname")==0)
164             {
165               param->hostname = CORBA::string_dup(PyString_AsString(value));
166             }
167           else if (strcmp(keystr,"OS")==0)
168             {
169               param->OS = CORBA::string_dup(PyString_AsString(value));
170             }
171           else if (strcmp(keystr,"mem_mb")==0)
172             {
173               param->mem_mb = PyLong_AsLong(value);
174             }
175           else if (strcmp(keystr,"cpu_clock")==0)
176             {
177               param->cpu_clock = PyLong_AsLong(value);
178             }
179           else if (strcmp(keystr,"nb_proc_per_node")==0)
180             {
181               param->nb_proc_per_node = PyLong_AsLong(value);
182             }
183           else if (strcmp(keystr,"nb_node")==0)
184             {
185               param->nb_node = PyLong_AsLong(value);
186             }
187           else if (strcmp(keystr,"isMPI")==0)
188             {
189               param->isMPI = PyLong_AsLong(value);
190             }
191         }
192       $1 = param;
193     }
194   else 
195     {
196        MESSAGE("Not a dictionnary");
197        PyErr_SetString(PyExc_TypeError,"Must Be a Python Dictionnary");
198        return NULL;
199     }
200 }
201
202
203 %typemap(python,freearg) const Engines::MachineParameters &
204 {
205   MESSAGE("delete $1");
206   delete $1;
207 }
208
209 %include "SALOME_LifeCycleCORBA.hxx"
210 %include "SALOME_FileTransferCORBA.hxx"