Salome HOME
Python 3 porting
[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 <omniORBpy.h>
37 #include "Runtime.hxx"
38
39 #include<string>
40 #include<set>
41       
42 namespace YACS
43 {
44   namespace ENGINE
45   {
46
47     class RuntimeSALOME;
48     YACSRUNTIMESALOME_EXPORT RuntimeSALOME* getSALOMERuntime();
49
50     class InputCorbaPort;
51     class InputPyPort;
52     class InputXmlPort;
53     class InputCppPort;
54
55     class YACSRUNTIMESALOME_EXPORT RuntimeSALOME: public Runtime
56     {
57       static Runtime* getSingleton() { return Runtime::_singleton; }
58
59     public:
60       
61       enum 
62       {
63         IsPyExt = 1,
64         UsePython = 2,
65         UseCorba = 4,
66         UseXml = 8,
67         UseCpp = 16,
68         UseSalome = 32
69       } FLAGS;
70
71       // singleton creation
72       static void setRuntime(long flags = UsePython+UseCorba+UseXml+UseCpp+UseSalome,
73                              int argc = 0, char* argv[] = NULL);
74       
75       friend RuntimeSALOME* getSALOMERuntime();
76       
77       virtual std::string getVersion() const;
78
79       virtual void init(long flags, int argc, char* argv[]);
80       virtual void fini();
81
82       virtual InputPort* createInputPort(const std::string& name,
83                                          const std::string& impl,
84                                          Node * node,
85                                          TypeCode * type);
86
87       virtual OutputPort* createOutputPort(const std::string& name,
88                                            const std::string& impl,
89                                            Node * node,
90                                            TypeCode * type);
91       virtual InputDataStreamPort* createInputDataStreamPort(const std::string& name,
92                                                              Node *node,TypeCode *type);
93
94       virtual OutputDataStreamPort* createOutputDataStreamPort(const std::string& name,
95                                                                Node *node,TypeCode *type);
96
97       virtual DataNode* createInDataNode(const std::string& kind,const std::string& name);
98       virtual DataNode* createOutDataNode(const std::string& kind,const std::string& name);
99       virtual InlineFuncNode* createFuncNode(const std::string& kind,const std::string& name);
100       virtual InlineNode* createScriptNode(const std::string& kind,const std::string& name);
101
102       virtual ServiceNode* createRefNode(const std::string& kind,const std::string& name);
103       virtual ServiceNode* createCompoNode(const std::string& kind,const std::string& name);
104       virtual ServiceInlineNode *createSInlineNode(const std::string& kind, const std::string& name);
105       virtual ComponentInstance* createComponentInstance(const std::string& name,
106                                                          const std::string& kind="");
107       virtual Container *createContainer(const std::string& kind="");
108       virtual WhileLoop* createWhileLoop(const std::string& name);
109       virtual ForLoop* createForLoop(const std::string& name);
110       virtual OptimizerLoop* createOptimizerLoop(const std::string& name,const std::string& algLib,
111                                                  const std::string& factoryName,bool algInitOnFile,
112                                                  const std::string& kind="", Proc * procForTypes = NULL);
113       virtual Bloc* createBloc(const std::string& name);
114       virtual Proc* createProc(const std::string& name);
115
116       virtual TypeCode * createInterfaceTc(const std::string& id, const std::string& name,
117                                             std::list<TypeCodeObjref *> ltc);
118       virtual TypeCode * createSequenceTc(const std::string& id, const std::string& name, TypeCode *content);
119       virtual TypeCodeStruct * createStructTc(const std::string& id, const std::string& name);
120
121       virtual InputPort* adapt(InputPort* source,
122                                const std::string& impl,
123                                TypeCode * type,bool init=false) throw (ConversionException);
124
125       virtual InputPort* adapt(InPropertyPort* source,
126                                const std::string& impl,
127                                TypeCode * type,bool init=false) throw (ConversionException);
128
129       virtual InputPort* adaptNeutral(InputPort* source,
130                                       const std::string& impl,
131                                       TypeCode * type,bool init) throw (ConversionException);
132
133       virtual InputPort* adapt(InputCorbaPort* source,
134                                const std::string& impl,
135                                TypeCode * type,bool init) throw (ConversionException);
136
137       virtual InputPort* adaptCorbaToCorba(InputCorbaPort* source,
138                                            TypeCode * type) throw (ConversionException);
139   
140       virtual InputPort* adaptCorbaToNeutral(InputCorbaPort* source,
141                                              TypeCode * type) throw (ConversionException);
142
143       virtual InputPort* adaptCorbaToPython(InputCorbaPort* source,
144                                             TypeCode * type) throw (ConversionException);
145
146       virtual InputPort* adaptCorbaToCpp(InputCorbaPort* source,
147                                          TypeCode * type) throw (ConversionException);
148
149       virtual InputPort* adaptCorbaToXml(InputCorbaPort* source,
150                                          TypeCode * type) throw (ConversionException);
151
152       virtual InputPort* adapt(InputPyPort* source,
153                                const std::string& impl,
154                                TypeCode * type,bool init) throw (ConversionException);
155
156       virtual InputPort* adaptPythonToCorba(InputPyPort* source,
157                                             TypeCode * type) throw (ConversionException);
158       
159       virtual InputPort* adaptPythonToNeutral(InputPyPort* source,
160                                               TypeCode * type) throw (ConversionException);
161
162       virtual InputPort* adaptPythonToPython(InputPyPort* source,
163                                              TypeCode * type,bool init) throw (ConversionException);
164       
165       virtual InputPort* adaptPythonToXml(InputPyPort* source,
166                                           TypeCode * type) throw (ConversionException);
167
168       virtual InputPort* adaptPythonToCpp(InputPyPort* source,
169                                           TypeCode * type) throw (ConversionException);
170
171       virtual InputPort* adapt(InputCppPort* source,
172                                const std::string& impl,
173                                TypeCode * type,bool init) throw (ConversionException);
174                                
175       virtual InputPort* adaptCppToCorba(InputCppPort* source,
176                                             TypeCode * type) throw (ConversionException);
177       
178       virtual InputPort* adaptCppToNeutral(InputCppPort* source,
179                                               TypeCode * type) throw (ConversionException);
180
181       virtual InputPort* adaptCppToPython(InputCppPort* source,
182                                              TypeCode * type) throw (ConversionException);
183       
184       virtual InputPort* adaptCppToXml(InputCppPort* source,
185                                           TypeCode * type) throw (ConversionException);
186
187       virtual InputPort* adaptCppToCpp(InputCppPort* source,
188                                           TypeCode * type) throw (ConversionException);
189
190       virtual InputPort* adapt(InputXmlPort* source,
191                                const std::string& impl,
192                                TypeCode * type,bool init) throw (ConversionException);
193
194       virtual InputPort* adaptXmlToCorba(InputXmlPort* source,
195                                          TypeCode * type) throw (ConversionException);
196
197       virtual InputPort* adaptXmlToPython(InputXmlPort* inport,
198                                           TypeCode * type) throw (ConversionException);
199
200       virtual InputPort* adaptXmlToCpp(InputXmlPort* inport,
201                                           TypeCode * type) throw (ConversionException);
202
203       virtual InputPort* adaptXmlToNeutral(InputXmlPort* inport,
204                                           TypeCode * type) throw (ConversionException);
205       virtual InputPort* adaptXmlToXml(InputXmlPort* inport,
206                                 TypeCode * type,bool init) throw (ConversionException);
207
208
209       virtual InputPort* adaptNeutralToXml(InputPort* inport,
210                                            TypeCode * type) throw (ConversionException);
211
212       virtual InputPort* adaptNeutralToPython(InputPort* inport,
213                                               TypeCode * type) throw (ConversionException);
214
215       virtual InputPort* adaptNeutralToCorba(InputPort* inport,
216                                              TypeCode * type) throw (ConversionException);
217
218       virtual InputPort* adaptNeutralToCpp(InputPort* inport,
219                                              TypeCode * type) throw (ConversionException);
220
221       virtual void* convertNeutral(TypeCode * type, Any *data);
222       virtual std::string convertNeutralAsString(TypeCode * type, Any *data);
223       virtual std::string convertPyObjectToString(PyObject* ob);
224       virtual PyObject* convertStringToPyObject(const std::string& s);
225
226       virtual ~RuntimeSALOME(); 
227
228       CORBA::ORB_ptr getOrb();
229       PyObject * getPyOrb();
230       PyObject * getBuiltins();
231       DynamicAny::DynAnyFactory_ptr getDynFactory();
232       omniORBpyAPI* getApi();
233       PyObject * get_omnipy();
234
235     protected:
236       RuntimeSALOME();  // singleton
237       RuntimeSALOME(long flags, int argc, char* argv[]);  // singleton
238       void initBuiltins();
239       CORBA::ORB_var _orb;
240       PyObject * _pyorb;
241       PyObject * _bltins;
242       DynamicAny::DynAnyFactory_var _dynFactory;
243       omniORBpyAPI* _api;
244       PyObject* _omnipy;
245       long _flags;
246       bool _usePython, _useCorba, _useCpp, _useXml;
247
248     };
249   }
250 }
251
252 #endif