]> SALOME platform Git repositories - modules/kernel.git/blob - src/DSC/DSC_Python/calcium.i
Salome HOME
To avoid compilation pb on RedHat 8.0.
[modules/kernel.git] / src / DSC / DSC_Python / calcium.i
1 %define DOCSTRING
2 "CALCIUM python wrapping : Superv_Component class
3 "
4 %enddef
5
6 %module(docstring=DOCSTRING) calcium
7
8 %feature("autodoc", "0");
9
10 %{
11 //C++ Includes 
12 #include <Calcium.hxx>
13 #include <calcium.h>
14 #include <Superv_Component_i.hxx>
15 #include <omniORB4/CORBA.h>
16
17 //--- from omniORBpy.h (not present on Debian Sarge packages)
18
19 struct omniORBpyAPI {
20
21   PyObject* (*cxxObjRefToPyObjRef)(const CORBA::Object_ptr cxx_obj,
22            CORBA::Boolean hold_lock);
23   // Convert a C++ object reference to a Python object reference.
24   // If <hold_lock> is true, caller holds the Python interpreter lock.
25
26   CORBA::Object_ptr (*pyObjRefToCxxObjRef)(PyObject* py_obj,
27              CORBA::Boolean hold_lock);
28   // Convert a Python object reference to a C++ object reference.
29   // Raises BAD_PARAM if the Python object is not an object reference.
30   // If <hold_lock> is true, caller holds the Python interpreter lock.
31
32
33   omniORBpyAPI();
34   // Constructor for the singleton. Sets up the function pointers.
35 };
36
37   omniORBpyAPI* api;
38
39 %}
40
41 %init
42 %{
43   // init section
44
45   PyObject* omnipy = PyImport_ImportModule((char*)"_omnipy");
46   if (!omnipy)
47   {
48     PyErr_SetString(PyExc_ImportError,
49         (char*)"Cannot import _omnipy");
50     return;
51   }
52   PyObject* pyapi = PyObject_GetAttrString(omnipy, (char*)"API");
53   api = (omniORBpyAPI*)PyCObject_AsVoidPtr(pyapi);
54   Py_DECREF(pyapi);
55 %}
56
57 %include "carrays.i" 
58 %include "cpointer.i"
59
60 /* Wrap a class interface around an "int *" */
61 %pointer_class(int, intp);
62 /* Wrap a class interface around an "float *" */
63 %pointer_class(float, floatp);
64 /* Wrap a class interface around an "double *" */
65 %pointer_class(double, doublep);
66
67 %array_class(int, intArray);
68 %array_class(float, floatArray);
69 %array_class(double, doubleArray);
70
71 %typemap(python,in) CORBA::Boolean
72 {
73   $1=(CORBA::Boolean)PyInt_AsLong($input);
74 }
75
76 %typemap(python,in) CORBA::ORB_ptr 
77 {
78   try {
79      CORBA::Object_ptr obj = api->pyObjRefToCxxObjRef($input,1);
80      $1 = CORBA::ORB::_narrow(obj);
81   }
82   catch (...) {
83      PyErr_SetString(PyExc_RuntimeError, "not a valid CORBA object ptr");
84   }
85 }
86 %typemap(python,in) PortableServer::POA_ptr
87 {
88   try {
89      CORBA::Object_ptr obj = api->pyObjRefToCxxObjRef($input,1);
90      $1 = PortableServer::POA::_narrow(obj);
91   }
92   catch (...) {
93      PyErr_SetString(PyExc_RuntimeError, "not a valid CORBA object ptr");
94   }
95 }
96
97 %typemap(python,in) Engines::Container_ptr
98 {
99   try {
100      CORBA::Object_ptr obj = api->pyObjRefToCxxObjRef($input,1);
101      $1 = Engines::Container::_narrow(obj);
102   }
103   catch (...) {
104      PyErr_SetString(PyExc_RuntimeError, "not a valid CORBA object ptr");
105   }
106 }
107 %typemap(python,in) Ports::Port_ptr
108 {
109   try {
110      CORBA::Object_ptr obj = api->pyObjRefToCxxObjRef($input,1);
111      $1 = Ports::Port::_narrow(obj);
112   }
113   catch (...) {
114      PyErr_SetString(PyExc_RuntimeError, "not a valid CORBA object ptr");
115   }
116 }
117
118 %typemap(python,out) Ports::Port_ptr , Ports::PortProperties_ptr
119 {
120   $result = api->cxxObjRefToPyObjRef($1, 1);
121 }
122
123 /*
124  * Exception section
125  */
126 // a general exception handler
127 %exception {
128    try {
129       $action
130    } catch(Engines::DSC::PortNotDefined& _e) {
131       PyErr_SetString(PyExc_ValueError,"Port not defined");
132       return NULL;
133    } catch(Engines::DSC::PortNotConnected& _e) {
134       PyErr_SetString(PyExc_ValueError,"Port not connected");
135       return NULL;
136    } catch(Engines::DSC::BadPortType& _e) {
137       PyErr_SetString(PyExc_ValueError,"Bad port type");
138       return NULL;
139    } catch(...) {
140       PyErr_SetString(PyExc_ValueError,"Unknown exception");
141       return NULL;
142    }
143 }
144
145 /*
146  * End of Exception section
147  */
148 namespace Engines
149 {
150 class DSC
151 {
152   public:
153     enum Message { AddingConnection, RemovingConnection, ApplicationError };
154 };
155 }
156
157 class PySupervCompo:public Superv_Component_i
158 {
159   public:
160
161     PySupervCompo(CORBA::ORB_ptr orb,
162          PortableServer::POA_ptr poa,
163          Engines::Container_ptr contai,
164          const char *instanceName,
165          const char *interfaceName);
166
167     virtual ~PySupervCompo();
168     CORBA::Boolean init_service(const char * service_name){return true;};
169     virtual provides_port * create_provides_data_port(const char* port_fab_type)
170         throw (BadFabType);
171     virtual uses_port * create_uses_data_port(const char* port_fab_type)
172         throw (BadFabType);
173     virtual void add_port(const char * port_fab_type,
174         const char * port_type,
175         const char * port_name)
176         throw (PortAlreadyDefined, BadFabType, BadType, BadProperty);
177     template < typename SpecificPortType >
178     SpecificPortType * add_port(const char * port_fab_type,
179             const char * port_type,
180             const char * port_name)
181           throw (PortAlreadyDefined, BadFabType, BadType, BadCast, BadProperty);
182     virtual void add_port(provides_port * port,
183           const char* provides_port_name)
184           throw (PortAlreadyDefined, NilPort, BadProperty);
185     virtual void add_port(uses_port * port,
186           const char* uses_port_name)
187           throw (PortAlreadyDefined, NilPort, BadProperty);
188     template <typename SpecificPortType >
189     SpecificPortType * get_port( const char * port_name)
190           throw (PortNotDefined, PortNotConnected, BadCast, UnexpectedState);
191     virtual Ports::Port_ptr get_provides_port(const char* provides_port_name,
192               const CORBA::Boolean connection_error)
193               throw (Engines::DSC::PortNotDefined,
194                      Engines::DSC::PortNotConnected,
195                      Engines::DSC::BadPortType);
196     virtual void connect_uses_port(const char* uses_port_name,
197                          Ports::Port_ptr provides_port_ref)
198               throw (Engines::DSC::PortNotDefined,
199                      Engines::DSC::BadPortType,
200                      Engines::DSC::NilPort);
201     virtual void connect_provides_port(const char* provides_port_name)
202               throw (Engines::DSC::PortNotDefined);
203     virtual void disconnect_provides_port(const char* provides_port_name,
204               const Engines::DSC::Message message)
205               throw (Engines::DSC::PortNotDefined,
206                      Engines::DSC::PortNotConnected);
207
208     virtual void disconnect_uses_port(const char* uses_port_name,
209                   Ports::Port_ptr provides_port_ref,
210                   const Engines::DSC::Message message)
211               throw (Engines::DSC::PortNotDefined,
212                      Engines::DSC::PortNotConnected,
213                      Engines::DSC::BadPortReference);
214
215     virtual Ports::PortProperties_ptr get_port_properties(const char* port_name);
216
217     %extend
218       {
219        //To get the address of the component
220         long ptr()
221         {
222           return (long)self;
223         }
224       }
225 };
226
227 extern "C" void create_calcium_port(Superv_Component_i* compo,char* name,char* type,char *mode,char* depend);
228
229 #define   CP_TEMPS    40
230 #define   CP_ITERATION    41
231 #define   CP_SEQUENTIEL   42
232 #define   CP_CONT    20
233 #define   CP_ARRET   21
234
235 int cp_een(void *component,int dep,float t,int n,char *nom,int nval,int *val);
236 int cp_edb(void *component,int dep,double t,int n,char *nom,int nval,double *val);
237
238 int cp_len(void *component,int dep,float *INOUT,float *INPUT,int *INOUT,char *nom,int nmax,int *OUTPUT,int *val);
239 int cp_ldb(void *component,int dep,double *INOUT,double *INPUT,int *INOUT,char *nom,int nmax,int *OUTPUT,double *val);
240 int cp_fin(void *component,int cp_end);
241