Salome HOME
Merge from V6_main 01/04/2013
[modules/yacs.git] / src / runtime / RuntimeSALOME.hxx
1 // Copyright (C) 2006-2013  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 std::string getVersion() const;
94
95       virtual void init(long flags);
96       virtual void fini();
97
98       virtual InputPort* createInputPort(const std::string& name,
99                                          const std::string& impl,
100                                          Node * node,
101                                          TypeCode * type);
102
103       virtual OutputPort* createOutputPort(const std::string& name,
104                                            const std::string& impl,
105                                            Node * node,
106                                            TypeCode * type);
107       virtual InputDataStreamPort* createInputDataStreamPort(const std::string& name,
108                                                              Node *node,TypeCode *type);
109
110       virtual OutputDataStreamPort* createOutputDataStreamPort(const std::string& name,
111                                                                Node *node,TypeCode *type);
112
113       virtual DataNode* createInDataNode(const std::string& kind,const std::string& name);
114       virtual DataNode* createOutDataNode(const std::string& kind,const std::string& name);
115       virtual InlineFuncNode* createFuncNode(const std::string& kind,const std::string& name);
116       virtual InlineNode* createScriptNode(const std::string& kind,const std::string& name);
117
118       virtual ServiceNode* createRefNode(const std::string& kind,const std::string& name);
119       virtual ServiceNode* createCompoNode(const std::string& kind,const std::string& name);
120       virtual ServiceInlineNode *createSInlineNode(const std::string& kind, const std::string& name);
121       virtual ComponentInstance* createComponentInstance(const std::string& name,
122                                                          const std::string& kind="");
123       virtual Container *createContainer(const std::string& kind="");
124       virtual WhileLoop* createWhileLoop(const std::string& name);
125       virtual ForLoop* createForLoop(const std::string& name);
126       virtual OptimizerLoop* createOptimizerLoop(const std::string& name,const std::string& algLib,
127                                                  const std::string& factoryName,bool algInitOnFile,
128                                                  const std::string& kind="", Proc * procForTypes = NULL);
129       virtual Bloc* createBloc(const std::string& name);
130       virtual Proc* createProc(const std::string& name);
131
132       virtual TypeCode * createInterfaceTc(const std::string& id, const std::string& name,
133                                             std::list<TypeCodeObjref *> ltc);
134       virtual TypeCode * createSequenceTc(const std::string& id, const std::string& name, TypeCode *content);
135       virtual TypeCodeStruct * createStructTc(const std::string& id, const std::string& name);
136
137       virtual InputPort* adapt(InputPort* source,
138                                const std::string& impl,
139                                TypeCode * type,bool init=false) throw (ConversionException);
140
141       virtual InputPort* adapt(InPropertyPort* source,
142                                const std::string& impl,
143                                TypeCode * type,bool init=false) throw (ConversionException);
144
145       virtual InputPort* adaptNeutral(InputPort* source,
146                                       const std::string& impl,
147                                       TypeCode * type,bool init) throw (ConversionException);
148
149       virtual InputPort* adapt(InputCorbaPort* source,
150                                const std::string& impl,
151                                TypeCode * type,bool init) throw (ConversionException);
152
153       virtual InputPort* adaptCorbaToCorba(InputCorbaPort* source,
154                                            TypeCode * type) throw (ConversionException);
155   
156       virtual InputPort* adaptCorbaToNeutral(InputCorbaPort* source,
157                                              TypeCode * type) throw (ConversionException);
158
159       virtual InputPort* adaptCorbaToPython(InputCorbaPort* source,
160                                             TypeCode * type) throw (ConversionException);
161
162       virtual InputPort* adaptCorbaToCpp(InputCorbaPort* source,
163                                          TypeCode * type) throw (ConversionException);
164
165       virtual InputPort* adaptCorbaToXml(InputCorbaPort* source,
166                                          TypeCode * type) throw (ConversionException);
167
168       virtual InputPort* adapt(InputPyPort* source,
169                                const std::string& impl,
170                                TypeCode * type,bool init) throw (ConversionException);
171
172       virtual InputPort* adaptPythonToCorba(InputPyPort* source,
173                                             TypeCode * type) throw (ConversionException);
174       
175       virtual InputPort* adaptPythonToNeutral(InputPyPort* source,
176                                               TypeCode * type) throw (ConversionException);
177
178       virtual InputPort* adaptPythonToPython(InputPyPort* source,
179                                              TypeCode * type,bool init) throw (ConversionException);
180       
181       virtual InputPort* adaptPythonToXml(InputPyPort* source,
182                                           TypeCode * type) throw (ConversionException);
183
184       virtual InputPort* adaptPythonToCpp(InputPyPort* source,
185                                           TypeCode * type) throw (ConversionException);
186
187       virtual InputPort* adapt(InputCppPort* source,
188                                const std::string& impl,
189                                TypeCode * type,bool init) throw (ConversionException);
190                                
191       virtual InputPort* adaptCppToCorba(InputCppPort* source,
192                                             TypeCode * type) throw (ConversionException);
193       
194       virtual InputPort* adaptCppToNeutral(InputCppPort* source,
195                                               TypeCode * type) throw (ConversionException);
196
197       virtual InputPort* adaptCppToPython(InputCppPort* source,
198                                              TypeCode * type) throw (ConversionException);
199       
200       virtual InputPort* adaptCppToXml(InputCppPort* source,
201                                           TypeCode * type) throw (ConversionException);
202
203       virtual InputPort* adaptCppToCpp(InputCppPort* source,
204                                           TypeCode * type) throw (ConversionException);
205
206       virtual InputPort* adapt(InputXmlPort* source,
207                                const std::string& impl,
208                                TypeCode * type,bool init) throw (ConversionException);
209
210       virtual InputPort* adaptXmlToCorba(InputXmlPort* source,
211                                          TypeCode * type) throw (ConversionException);
212
213       virtual InputPort* adaptXmlToPython(InputXmlPort* inport,
214                                           TypeCode * type) throw (ConversionException);
215
216       virtual InputPort* adaptXmlToCpp(InputXmlPort* inport,
217                                           TypeCode * type) throw (ConversionException);
218
219       virtual InputPort* adaptXmlToNeutral(InputXmlPort* inport,
220                                           TypeCode * type) throw (ConversionException);
221       virtual InputPort* adaptXmlToXml(InputXmlPort* inport,
222                                 TypeCode * type,bool init) throw (ConversionException);
223
224
225       virtual InputPort* adaptNeutralToXml(InputPort* inport,
226                                            TypeCode * type) throw (ConversionException);
227
228       virtual InputPort* adaptNeutralToPython(InputPort* inport,
229                                               TypeCode * type) throw (ConversionException);
230
231       virtual InputPort* adaptNeutralToCorba(InputPort* inport,
232                                              TypeCode * type) throw (ConversionException);
233
234       virtual InputPort* adaptNeutralToCpp(InputPort* inport,
235                                              TypeCode * type) throw (ConversionException);
236
237       virtual void* convertNeutral(TypeCode * type, Any *data);
238       virtual std::string convertNeutralAsString(TypeCode * type, Any *data);
239       virtual std::string convertPyObjectToString(PyObject* ob);
240       virtual PyObject* convertStringToPyObject(const std::string& s);
241
242       virtual ~RuntimeSALOME(); 
243
244       CORBA::ORB_ptr getOrb();
245       PyObject * getPyOrb();
246       PyObject * getBuiltins();
247       DynamicAny::DynAnyFactory_ptr getDynFactory();
248       omniORBpyAPI* getApi();
249       PyObject * get_omnipy();
250
251     protected:
252       RuntimeSALOME();  // singleton
253       RuntimeSALOME(long flags);  // singleton
254       void initBuiltins();
255       CORBA::ORB_var _orb;
256       PyObject * _pyorb;
257       PyObject * _bltins;
258       DynamicAny::DynAnyFactory_var _dynFactory;
259       omniORBpyAPI* _api;
260       PyObject* _omnipy;
261       long _flags;
262       bool _usePython, _useCorba, _useCpp, _useXml;
263
264     };
265   }
266 }
267
268 #endif