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