Salome HOME
Copyright update 2020
[modules/yacs.git] / src / runtime / RuntimeSALOME.hxx
1 // Copyright (C) 2006-2020  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 #include <Python.h>
23
24 #include "YACSRuntimeSALOMEExport.hxx"
25
26 // rnv: avoid compilation warning on Linux : "_POSIX_C_SOURCE" and "_XOPEN_SOURCE" are redefined
27 #ifdef _POSIX_C_SOURCE
28 #undef _POSIX_C_SOURCE
29 #endif
30
31 #ifdef _XOPEN_SOURCE
32 #undef _XOPEN_SOURCE
33 #endif
34
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       virtual std::vector< std::pair<std::string,int> > getCatalogOfComputeNodes() const;
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 #ifndef SWIG
108       virtual Container *createContainer(const std::string& kind="");
109 #endif
110       virtual WhileLoop* createWhileLoop(const std::string& name);
111       virtual ForLoop* createForLoop(const std::string& name);
112       virtual OptimizerLoop* createOptimizerLoop(const std::string& name,const std::string& algLib,
113                                                  const std::string& factoryName,bool algInitOnFile,
114                                                  const std::string& kind="", Proc * procForTypes = NULL);
115       virtual Bloc* createBloc(const std::string& name);
116       virtual Proc* createProc(const std::string& name);
117
118       virtual TypeCode * createInterfaceTc(const std::string& id, const std::string& name,
119                                             std::list<TypeCodeObjref *> ltc);
120       virtual TypeCode * createSequenceTc(const std::string& id, const std::string& name, TypeCode *content);
121       virtual TypeCodeStruct * createStructTc(const std::string& id, const std::string& name);
122
123       virtual InputPort* adapt(InputPort* source,
124                                const std::string& impl,
125                                TypeCode * type,bool init=false) throw (ConversionException);
126
127       virtual InputPort* adapt(InPropertyPort* source,
128                                const std::string& impl,
129                                TypeCode * type,bool init=false) throw (ConversionException);
130
131       virtual InputPort* adaptNeutral(InputPort* source,
132                                       const std::string& impl,
133                                       TypeCode * type,bool init) throw (ConversionException);
134
135       virtual InputPort* adapt(InputCorbaPort* source,
136                                const std::string& impl,
137                                TypeCode * type,bool init) throw (ConversionException);
138
139       virtual InputPort* adaptCorbaToCorba(InputCorbaPort* source,
140                                            TypeCode * type) throw (ConversionException);
141   
142       virtual InputPort* adaptCorbaToNeutral(InputCorbaPort* source,
143                                              TypeCode * type) throw (ConversionException);
144
145       virtual InputPort* adaptCorbaToPython(InputCorbaPort* source,
146                                             TypeCode * type) throw (ConversionException);
147
148       virtual InputPort* adaptCorbaToCpp(InputCorbaPort* source,
149                                          TypeCode * type) throw (ConversionException);
150
151       virtual InputPort* adaptCorbaToXml(InputCorbaPort* source,
152                                          TypeCode * type) throw (ConversionException);
153
154       virtual InputPort* adapt(InputPyPort* source,
155                                const std::string& impl,
156                                TypeCode * type,bool init) throw (ConversionException);
157
158       virtual InputPort* adaptPythonToCorba(InputPyPort* source,
159                                             TypeCode * type) throw (ConversionException);
160       
161       virtual InputPort* adaptPythonToNeutral(InputPyPort* source,
162                                               TypeCode * type) throw (ConversionException);
163
164       virtual InputPort* adaptPythonToPython(InputPyPort* source,
165                                              TypeCode * type,bool init) throw (ConversionException);
166       
167       virtual InputPort* adaptPythonToXml(InputPyPort* source,
168                                           TypeCode * type) throw (ConversionException);
169
170       virtual InputPort* adaptPythonToCpp(InputPyPort* source,
171                                           TypeCode * type) throw (ConversionException);
172
173       virtual InputPort* adapt(InputCppPort* source,
174                                const std::string& impl,
175                                TypeCode * type,bool init) throw (ConversionException);
176                                
177       virtual InputPort* adaptCppToCorba(InputCppPort* source,
178                                             TypeCode * type) throw (ConversionException);
179       
180       virtual InputPort* adaptCppToNeutral(InputCppPort* source,
181                                               TypeCode * type) throw (ConversionException);
182
183       virtual InputPort* adaptCppToPython(InputCppPort* source,
184                                              TypeCode * type) throw (ConversionException);
185       
186       virtual InputPort* adaptCppToXml(InputCppPort* source,
187                                           TypeCode * type) throw (ConversionException);
188
189       virtual InputPort* adaptCppToCpp(InputCppPort* source,
190                                           TypeCode * type) throw (ConversionException);
191
192       virtual InputPort* adapt(InputXmlPort* source,
193                                const std::string& impl,
194                                TypeCode * type,bool init) throw (ConversionException);
195
196       virtual InputPort* adaptXmlToCorba(InputXmlPort* source,
197                                          TypeCode * type) throw (ConversionException);
198
199       virtual InputPort* adaptXmlToPython(InputXmlPort* inport,
200                                           TypeCode * type) throw (ConversionException);
201
202       virtual InputPort* adaptXmlToCpp(InputXmlPort* inport,
203                                           TypeCode * type) throw (ConversionException);
204
205       virtual InputPort* adaptXmlToNeutral(InputXmlPort* inport,
206                                           TypeCode * type) throw (ConversionException);
207       virtual InputPort* adaptXmlToXml(InputXmlPort* inport,
208                                 TypeCode * type,bool init) throw (ConversionException);
209
210
211       virtual InputPort* adaptNeutralToXml(InputPort* inport,
212                                            TypeCode * type) throw (ConversionException);
213
214       virtual InputPort* adaptNeutralToPython(InputPort* inport,
215                                               TypeCode * type) throw (ConversionException);
216
217       virtual InputPort* adaptNeutralToCorba(InputPort* inport,
218                                              TypeCode * type) throw (ConversionException);
219
220       virtual InputPort* adaptNeutralToCpp(InputPort* inport,
221                                              TypeCode * type) throw (ConversionException);
222
223       virtual void* convertNeutral(TypeCode * type, Any *data);
224       virtual std::string convertNeutralAsString(TypeCode * type, Any *data);
225       virtual std::string convertPyObjectToString(PyObject* ob);
226       virtual PyObject* convertStringToPyObject(const std::string& s);
227
228       virtual ~RuntimeSALOME(); 
229
230       CORBA::ORB_ptr getOrb() const;
231       PyObject * getPyOrb() const;
232       PyObject * getBuiltins() const;
233       DynamicAny::DynAnyFactory_ptr getDynFactory() const;
234       omniORBpyAPI* getApi();
235       PyObject * get_omnipy();
236
237     protected:
238       RuntimeSALOME();  // singleton
239       RuntimeSALOME(long flags, int argc, char* argv[]);  // singleton
240       void initBuiltins();
241       CORBA::ORB_var _orb;
242       PyObject * _pyorb;
243       PyObject * _bltins;
244       DynamicAny::DynAnyFactory_var _dynFactory;
245       omniORBpyAPI* _api;
246       PyObject* _omnipy;
247       long _flags;
248       bool _usePython, _useCorba, _useCpp, _useXml;
249
250     };
251   }
252 }
253
254 #endif