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