Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/yacs.git] / src / runtime / RuntimeSALOME.hxx
1 // Copyright (C) 2006-2012  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef _RUNTIMESALOME_HXX_
21 #define _RUNTIMESALOME_HXX_
22
23 #include "YACSRuntimeSALOMEExport.hxx"
24
25 // rnv: avoid compilation warning on Linux : "_POSIX_C_SOURCE" and "_XOPEN_SOURCE" are redefined
26 #ifdef _POSIX_C_SOURCE
27 #undef _POSIX_C_SOURCE
28 #endif
29
30 #ifdef _XOPEN_SOURCE
31 #undef _XOPEN_SOURCE
32 #endif
33
34 #include <Python.h>
35 #include <omniORB4/CORBA.h>
36 #include "Runtime.hxx"
37
38 #include<string>
39 #include<set>
40
41 //--- from omniORBpy.h (not present on Debian Sarge packages)
42 struct omniORBpyAPI
43 {
44       PyObject* (*cxxObjRefToPyObjRef)(const CORBA::Object_ptr cxx_obj,
45                                        CORBA::Boolean hold_lock);
46       // Convert a C++ object reference to a Python object reference.
47       // If <hold_lock> is true, caller holds the Python interpreter lock.
48
49       CORBA::Object_ptr (*pyObjRefToCxxObjRef)(PyObject* py_obj,
50                                                CORBA::Boolean hold_lock);
51       // Convert a Python object reference to a C++ object reference.
52       // Raises BAD_PARAM if the Python object is not an object reference.
53       // If <hold_lock> is true, caller holds the Python interpreter lock.
54
55       PyObject* (*handleCxxSystemException)(const CORBA::SystemException& ex);
56       // Sets the Python exception state to reflect the given C++ system
57       // exception. Always returns NULL. The caller must hold the Python
58       // interpreter lock.
59 };
60 //--- end of from omniORBpy.h (not present on Debian Sarge packages)
61       
62 namespace YACS
63 {
64   namespace ENGINE
65   {
66
67     class RuntimeSALOME;
68     YACSRUNTIMESALOME_EXPORT RuntimeSALOME* getSALOMERuntime();
69
70     class InputCorbaPort;
71     class InputPyPort;
72     class InputXmlPort;
73     class InputCppPort;
74
75     class YACSRUNTIMESALOME_EXPORT RuntimeSALOME: public Runtime
76     {
77     public:
78       
79       enum 
80       {
81         IsPyExt = 1,
82         UsePython = 2,
83         UseCorba = 4,
84         UseXml = 8,
85         UseCpp = 16,
86         UseSalome = 32
87       } FLAGS;
88
89       static void setRuntime(long flags = UsePython+UseCorba+UseXml+UseCpp+UseSalome); // singleton creation
90       
91       friend RuntimeSALOME* getSALOMERuntime();
92
93       virtual void init(long flags);
94       virtual void fini();
95
96       virtual InputPort* createInputPort(const std::string& name,
97                                          const std::string& impl,
98                                          Node * node,
99                                          TypeCode * type);
100
101       virtual OutputPort* createOutputPort(const std::string& name,
102                                            const std::string& impl,
103                                            Node * node,
104                                            TypeCode * type);
105       virtual InputDataStreamPort* createInputDataStreamPort(const std::string& name,
106                                                              Node *node,TypeCode *type);
107
108       virtual OutputDataStreamPort* createOutputDataStreamPort(const std::string& name,
109                                                                Node *node,TypeCode *type);
110
111       virtual DataNode* createInDataNode(const std::string& kind,const std::string& name);
112       virtual DataNode* createOutDataNode(const std::string& kind,const std::string& name);
113       virtual InlineFuncNode* createFuncNode(const std::string& kind,const std::string& name);
114       virtual InlineNode* createScriptNode(const std::string& kind,const std::string& name);
115
116       virtual ServiceNode* createRefNode(const std::string& kind,const std::string& name);
117       virtual ServiceNode* createCompoNode(const std::string& kind,const std::string& name);
118       virtual ServiceInlineNode *createSInlineNode(const std::string& kind, const std::string& name);
119       virtual ComponentInstance* createComponentInstance(const std::string& name,
120                                                          const std::string& kind="");
121       virtual Container *createContainer(const std::string& kind="");
122       virtual WhileLoop* createWhileLoop(const std::string& name);
123       virtual ForLoop* createForLoop(const std::string& name);
124       virtual OptimizerLoop* createOptimizerLoop(const std::string& name,const std::string& algLib,
125                                                  const std::string& factoryName,bool algInitOnFile,
126                                                  const std::string& kind="", Proc * procForTypes = NULL);
127       virtual Bloc* createBloc(const std::string& name);
128       virtual Proc* createProc(const std::string& name);
129
130       virtual TypeCode * createInterfaceTc(const std::string& id, const std::string& name,
131                                             std::list<TypeCodeObjref *> ltc);
132       virtual TypeCode * createSequenceTc(const std::string& id, const std::string& name, TypeCode *content);
133       virtual TypeCodeStruct * createStructTc(const std::string& id, const std::string& name);
134
135       virtual InputPort* adapt(InputPort* source,
136                                const std::string& impl,
137                                TypeCode * type,bool init=false) throw (ConversionException);
138
139       virtual InputPort* adapt(InPropertyPort* source,
140                                const std::string& impl,
141                                TypeCode * type,bool init=false) throw (ConversionException);
142
143       virtual InputPort* adaptNeutral(InputPort* source,
144                                       const std::string& impl,
145                                       TypeCode * type,bool init) throw (ConversionException);
146
147       virtual InputPort* adapt(InputCorbaPort* source,
148                                const std::string& impl,
149                                TypeCode * type,bool init) throw (ConversionException);
150
151       virtual InputPort* adaptCorbaToCorba(InputCorbaPort* source,
152                                            TypeCode * type) throw (ConversionException);
153   
154       virtual InputPort* adaptCorbaToNeutral(InputCorbaPort* source,
155                                              TypeCode * type) throw (ConversionException);
156
157       virtual InputPort* adaptCorbaToPython(InputCorbaPort* source,
158                                             TypeCode * type) throw (ConversionException);
159
160       virtual InputPort* adaptCorbaToCpp(InputCorbaPort* source,
161                                          TypeCode * type) throw (ConversionException);
162
163       virtual InputPort* adaptCorbaToXml(InputCorbaPort* source,
164                                          TypeCode * type) throw (ConversionException);
165
166       virtual InputPort* adapt(InputPyPort* source,
167                                const std::string& impl,
168                                TypeCode * type,bool init) throw (ConversionException);
169
170       virtual InputPort* adaptPythonToCorba(InputPyPort* source,
171                                             TypeCode * type) throw (ConversionException);
172       
173       virtual InputPort* adaptPythonToNeutral(InputPyPort* source,
174                                               TypeCode * type) throw (ConversionException);
175
176       virtual InputPort* adaptPythonToPython(InputPyPort* source,
177                                              TypeCode * type,bool init) throw (ConversionException);
178       
179       virtual InputPort* adaptPythonToXml(InputPyPort* source,
180                                           TypeCode * type) throw (ConversionException);
181
182       virtual InputPort* adaptPythonToCpp(InputPyPort* source,
183                                           TypeCode * type) throw (ConversionException);
184
185       virtual InputPort* adapt(InputCppPort* source,
186                                const std::string& impl,
187                                TypeCode * type,bool init) throw (ConversionException);
188                                
189       virtual InputPort* adaptCppToCorba(InputCppPort* source,
190                                             TypeCode * type) throw (ConversionException);
191       
192       virtual InputPort* adaptCppToNeutral(InputCppPort* source,
193                                               TypeCode * type) throw (ConversionException);
194
195       virtual InputPort* adaptCppToPython(InputCppPort* source,
196                                              TypeCode * type) throw (ConversionException);
197       
198       virtual InputPort* adaptCppToXml(InputCppPort* source,
199                                           TypeCode * type) throw (ConversionException);
200
201       virtual InputPort* adaptCppToCpp(InputCppPort* source,
202                                           TypeCode * type) throw (ConversionException);
203
204       virtual InputPort* adapt(InputXmlPort* source,
205                                const std::string& impl,
206                                TypeCode * type,bool init) throw (ConversionException);
207
208       virtual InputPort* adaptXmlToCorba(InputXmlPort* source,
209                                          TypeCode * type) throw (ConversionException);
210
211       virtual InputPort* adaptXmlToPython(InputXmlPort* inport,
212                                           TypeCode * type) throw (ConversionException);
213
214       virtual InputPort* adaptXmlToCpp(InputXmlPort* inport,
215                                           TypeCode * type) throw (ConversionException);
216
217       virtual InputPort* adaptXmlToNeutral(InputXmlPort* inport,
218                                           TypeCode * type) throw (ConversionException);
219       virtual InputPort* adaptXmlToXml(InputXmlPort* inport,
220                                 TypeCode * type,bool init) throw (ConversionException);
221
222
223       virtual InputPort* adaptNeutralToXml(InputPort* inport,
224                                            TypeCode * type) throw (ConversionException);
225
226       virtual InputPort* adaptNeutralToPython(InputPort* inport,
227                                               TypeCode * type) throw (ConversionException);
228
229       virtual InputPort* adaptNeutralToCorba(InputPort* inport,
230                                              TypeCode * type) throw (ConversionException);
231
232       virtual InputPort* adaptNeutralToCpp(InputPort* inport,
233                                              TypeCode * type) throw (ConversionException);
234
235       virtual void* convertNeutral(TypeCode * type, Any *data);
236       virtual std::string convertNeutralAsString(TypeCode * type, Any *data);
237       virtual std::string convertPyObjectToString(PyObject* ob);
238       virtual PyObject* convertStringToPyObject(const std::string& s);
239
240       virtual ~RuntimeSALOME(); 
241
242       CORBA::ORB_ptr getOrb();
243       PyObject * getPyOrb();
244       PyObject * getBuiltins();
245       DynamicAny::DynAnyFactory_ptr getDynFactory();
246       omniORBpyAPI* getApi();
247       PyObject * get_omnipy();
248
249     protected:
250       RuntimeSALOME();  // singleton
251       RuntimeSALOME(long flags);  // singleton
252       void initBuiltins();
253       CORBA::ORB_var _orb;
254       PyObject * _pyorb;
255       PyObject * _bltins;
256       DynamicAny::DynAnyFactory_var _dynFactory;
257       omniORBpyAPI* _api;
258       PyObject* _omnipy;
259       long _flags;
260       bool _usePython, _useCorba, _useCpp, _useXml;
261
262     };
263   }
264 }
265
266 #endif