2 "CALCIUM python wrapping : Superv_Component class
6 %module(docstring=DOCSTRING) calcium
8 %feature("autodoc", "0");
12 #include <Calcium.hxx>
14 #include <Superv_Component_i.hxx>
15 #include <omniORB4/CORBA.h>
17 //--- from omniORBpy.h (not present on Debian Sarge packages)
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.
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.
34 // Constructor for the singleton. Sets up the function pointers.
45 PyObject* omnipy = PyImport_ImportModule((char*)"_omnipy");
48 PyErr_SetString(PyExc_ImportError,
49 (char*)"Cannot import _omnipy");
52 PyObject* pyapi = PyObject_GetAttrString(omnipy, (char*)"API");
53 api = (omniORBpyAPI*)PyCObject_AsVoidPtr(pyapi);
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);
67 %array_class(int, intArray);
68 %array_class(float, floatArray);
69 %array_class(double, doubleArray);
71 %typemap(python,in) CORBA::Boolean
73 $1=(CORBA::Boolean)PyInt_AsLong($input);
76 %typemap(python,in) CORBA::ORB_ptr
79 CORBA::Object_ptr obj = api->pyObjRefToCxxObjRef($input,1);
80 $1 = CORBA::ORB::_narrow(obj);
83 PyErr_SetString(PyExc_RuntimeError, "not a valid CORBA object ptr");
86 %typemap(python,in) PortableServer::POA_ptr
89 CORBA::Object_ptr obj = api->pyObjRefToCxxObjRef($input,1);
90 $1 = PortableServer::POA::_narrow(obj);
93 PyErr_SetString(PyExc_RuntimeError, "not a valid CORBA object ptr");
97 %typemap(python,in) Engines::Container_ptr
100 CORBA::Object_ptr obj = api->pyObjRefToCxxObjRef($input,1);
101 $1 = Engines::Container::_narrow(obj);
104 PyErr_SetString(PyExc_RuntimeError, "not a valid CORBA object ptr");
107 %typemap(python,in) Ports::Port_ptr
110 CORBA::Object_ptr obj = api->pyObjRefToCxxObjRef($input,1);
111 $1 = Ports::Port::_narrow(obj);
114 PyErr_SetString(PyExc_RuntimeError, "not a valid CORBA object ptr");
118 %typemap(python,out) Ports::Port_ptr , Ports::PortProperties_ptr
120 $result = api->cxxObjRefToPyObjRef($1, 1);
126 // a general exception handler
130 } catch(Engines::DSC::PortNotDefined& _e) {
131 PyErr_SetString(PyExc_ValueError,"Port not defined");
133 } catch(Engines::DSC::PortNotConnected& _e) {
134 PyErr_SetString(PyExc_ValueError,"Port not connected");
136 } catch(Engines::DSC::BadPortType& _e) {
137 PyErr_SetString(PyExc_ValueError,"Bad port type");
140 PyErr_SetString(PyExc_ValueError,"Unknown exception");
146 * End of Exception section
153 enum Message { AddingConnection, RemovingConnection, ApplicationError };
157 class PySupervCompo:public Superv_Component_i
161 PySupervCompo(CORBA::ORB_ptr orb,
162 PortableServer::POA_ptr poa,
163 Engines::Container_ptr contai,
164 const char *instanceName,
165 const char *interfaceName);
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)
171 virtual uses_port * create_uses_data_port(const char* port_fab_type)
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);
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);
215 virtual Ports::PortProperties_ptr get_port_properties(const char* port_name);
219 //To get the address of the component
227 extern "C" void create_calcium_port(Superv_Component_i* compo,char* name,char* type,char *mode,char* depend);
230 #define CP_ITERATION 41
231 #define CP_SEQUENTIEL 42
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);
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);