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