]> SALOME platform Git repositories - modules/yacs.git/blob - src/runtime/SALOMERuntime.i
Salome HOME
copy tag mergefrom_BR_V0_1_CC_Salome_04oct07
[modules/yacs.git] / src / runtime / SALOMERuntime.i
1 // ----------------------------------------------------------------------------
2 %define SALOMEDOCSTRING
3 "SALOMERuntime docstring
4 Implementation of nodes for SALOME platform."
5 %enddef
6
7 %module(docstring=SALOMEDOCSTRING) SALOMERuntime
8
9 %feature("autodoc", "0");
10 %include std_string.i
11
12 // ----------------------------------------------------------------------------
13
14 %{
15 #include "RuntimeSALOME.hxx"
16 #include "SALOMEDispatcher.hxx"
17   
18 #include <iostream>
19 #include <string>
20 #include <sstream>
21 #include <cassert>
22 #include <stdexcept>
23 #include "utilities.h"
24
25 using namespace std;
26 using namespace YACS::ENGINE;
27
28 //--- from omniORBpy.h (not present on Debian Sarge packages)
29 //    (rename omniORBpyAPI in omniORBpy_API)
30 struct omniORBpy_API
31 {
32
33   PyObject* (*cxxObjRefToPyObjRef)(const CORBA::Object_ptr cxx_obj,
34                                    CORBA::Boolean hold_lock);
35   // Convert a C++ object reference to a Python object reference.
36   // If <hold_lock> is true, caller holds the Python interpreter lock.
37
38   CORBA::Object_ptr (*pyObjRefToCxxObjRef)(PyObject* py_obj,
39                                            CORBA::Boolean hold_lock);
40   // Convert a Python object reference to a C++ object reference.
41   // Raises BAD_PARAM if the Python object is not an object reference.
42   // If <hold_lock> is true, caller holds the Python interpreter lock.
43
44
45   omniORBpy_API();
46   // Constructor for the singleton. Sets up the function pointers.
47 };
48
49   omniORBpy_API* api;
50
51 %}
52
53
54 // ----------------------------------------------------------------------------
55
56
57 %init
58 %{
59   // init section
60
61   PyObject* omnipy = PyImport_ImportModule((char*)"_omnipy");
62   if (!omnipy)
63   {
64     PyErr_SetString(PyExc_ImportError,
65                     (char*)"Cannot import _omnipy");
66     return;
67   }
68   PyObject* pyapi = PyObject_GetAttrString(omnipy, (char*)"API");
69   api = (omniORBpy_API*)PyCObject_AsVoidPtr(pyapi);
70   Py_DECREF(pyapi);
71 %}
72
73 // ----------------------------------------------------------------------------
74
75 %typemap(python,out) YACSGui_ORB::Observer_ptr
76 {
77   MESSAGE("typemap out on CORBA object ptr");
78   SCRUTE($1);
79   $result = api->cxxObjRefToPyObjRef($1, 1);
80   SCRUTE($result);
81 }
82
83 %typemap(python,in) YACSGui_ORB::Observer_ptr
84 {
85   MESSAGE("typemap in on CORBA object ptr");
86   try
87   {
88      CORBA::Object_ptr obj = api->pyObjRefToCxxObjRef($input,1);
89      $1 = YACSGui_ORB::Observer::_narrow(obj);
90      SCRUTE($1);
91   }
92   catch (...)
93   {
94      PyErr_SetString(PyExc_RuntimeError, "not a valid CORBA object ptr");
95   }
96 }
97
98 // ----------------------------------------------------------------------------
99
100 namespace YACS
101 {
102   namespace ENGINE
103   {
104     class RuntimeSALOME: public Runtime
105     {
106     public:
107       static void setRuntime(bool ispyext=false); // singleton creation
108       virtual ~RuntimeSALOME(); 
109     protected:
110       RuntimeSALOME();  // singleton
111       RuntimeSALOME(bool ispyext);  // singleton
112     };
113
114     class SALOMEDispatcher: public Dispatcher
115     {
116     public:
117       void addObserver(YACSGui_ORB::Observer_ptr observer,int numid, std::string event);
118       static void setSALOMEDispatcher();
119       static SALOMEDispatcher* getSALOMEDispatcher();
120     };
121
122   }
123 }