Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / runtime / RuntimeSALOME.hxx
1 //  Copyright (C) 2006-2008  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.
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 #ifndef _RUNTIMESALOME_HXX_
20 #define _RUNTIMESALOME_HXX_
21
22 #include <Python.h>
23 #include <omniORB4/CORBA.h>
24 #include "Runtime.hxx"
25
26 #include<string>
27 #include<set>
28
29 //--- from omniORBpy.h (not present on Debian Sarge packages)
30 struct omniORBpyAPI
31 {
32       PyObject* (*cxxObjRefToPyObjRef)(const CORBA::Object_ptr cxx_obj,
33                                        CORBA::Boolean hold_lock);
34       // Convert a C++ object reference to a Python object reference.
35       // If <hold_lock> is true, caller holds the Python interpreter lock.
36
37       CORBA::Object_ptr (*pyObjRefToCxxObjRef)(PyObject* py_obj,
38                                                CORBA::Boolean hold_lock);
39       // Convert a Python object reference to a C++ object reference.
40       // Raises BAD_PARAM if the Python object is not an object reference.
41       // If <hold_lock> is true, caller holds the Python interpreter lock.
42
43       PyObject* (*handleCxxSystemException)(const CORBA::SystemException& ex);
44       // Sets the Python exception state to reflect the given C++ system
45       // exception. Always returns NULL. The caller must hold the Python
46       // interpreter lock.
47 };
48 //--- end of from omniORBpy.h (not present on Debian Sarge packages)
49       
50 namespace YACS
51 {
52   namespace ENGINE
53   {
54
55     class RuntimeSALOME;
56     RuntimeSALOME* getSALOMERuntime();
57
58     class InputCorbaPort;
59     class InputPyPort;
60     class InputXmlPort;
61     class InputCppPort;
62
63     class RuntimeSALOME: public Runtime
64     {
65     public:
66       
67       enum 
68       {
69               IsPyExt = 1,
70         UsePython = 2,
71               UseCorba = 4,
72               UseXml = 8,
73               UseCpp = 16,
74               UseSalome = 32
75       } FLAGS;
76
77       static void setRuntime(long flags = UsePython+UseCorba+UseXml+UseCpp+UseSalome); // singleton creation
78       
79       friend RuntimeSALOME* getSALOMERuntime();
80
81       virtual void init(long flags);
82       virtual void fini();
83
84       virtual InputPort* createInputPort(const std::string& name,
85                                          const std::string& impl,
86                                          Node * node,
87                                          TypeCode * type);
88
89       virtual OutputPort* createOutputPort(const std::string& name,
90                                            const std::string& impl,
91                                            Node * node,
92                                            TypeCode * type);
93       virtual InputDataStreamPort* createInputDataStreamPort(const std::string& name,
94                                                              Node *node,TypeCode *type);
95
96       virtual OutputDataStreamPort* createOutputDataStreamPort(const std::string& name,
97                                                                Node *node,TypeCode *type);
98
99       virtual DataNode* createInDataNode(const std::string& kind,const std::string& name);
100       virtual DataNode* createOutDataNode(const std::string& kind,const std::string& name);
101       virtual InlineFuncNode* createFuncNode(const std::string& kind,const std::string& name);
102       virtual InlineNode* createScriptNode(const std::string& kind,const std::string& name);
103
104       virtual ServiceNode* createRefNode(const std::string& kind,const std::string& name);
105       virtual ServiceNode* createCompoNode(const std::string& kind,const std::string& name);
106       virtual ServiceInlineNode *createSInlineNode(const std::string& kind, const std::string& name);
107       virtual ComponentInstance* createComponentInstance(const std::string& name,
108                                                          const std::string& kind="");
109       virtual Container *createContainer(const std::string& kind="");
110       virtual WhileLoop* createWhileLoop(const std::string& name);
111       virtual ForLoop* createForLoop(const std::string& name);
112       virtual Bloc* createBloc(const std::string& name);
113       virtual Proc* createProc(const std::string& name);
114
115       virtual InputPort* adapt(InputPort* source,
116                                const std::string& impl,
117                                TypeCode * type,bool init=false) throw (ConversionException);
118
119       virtual InputPort* adaptNeutral(InputPort* source,
120                                       const std::string& impl,
121                                       TypeCode * type,bool init) throw (ConversionException);
122
123       virtual InputPort* adapt(InputCorbaPort* source,
124                                const std::string& impl,
125                                TypeCode * type,bool init) throw (ConversionException);
126
127       virtual InputPort* adaptCorbaToCorba(InputCorbaPort* source,
128                                            TypeCode * type) throw (ConversionException);
129   
130       virtual InputPort* adaptCorbaToNeutral(InputCorbaPort* source,
131                                              TypeCode * type) throw (ConversionException);
132
133       virtual InputPort* adaptCorbaToPython(InputCorbaPort* source,
134                                             TypeCode * type) throw (ConversionException);
135
136       virtual InputPort* adaptCorbaToCpp(InputCorbaPort* source,
137                                          TypeCode * type) throw (ConversionException);
138
139       virtual InputPort* adaptCorbaToXml(InputCorbaPort* source,
140                                          TypeCode * type) throw (ConversionException);
141
142       virtual InputPort* adapt(InputPyPort* source,
143                                const std::string& impl,
144                                TypeCode * type,bool init) throw (ConversionException);
145
146       virtual InputPort* adaptPythonToCorba(InputPyPort* source,
147                                             TypeCode * type) throw (ConversionException);
148       
149       virtual InputPort* adaptPythonToNeutral(InputPyPort* source,
150                                               TypeCode * type) throw (ConversionException);
151
152       virtual InputPort* adaptPythonToPython(InputPyPort* source,
153                                              TypeCode * type,bool init) throw (ConversionException);
154       
155       virtual InputPort* adaptPythonToXml(InputPyPort* source,
156                                           TypeCode * type) throw (ConversionException);
157
158       virtual InputPort* adaptPythonToCpp(InputPyPort* source,
159                                           TypeCode * type) throw (ConversionException);
160
161       virtual InputPort* adapt(InputCppPort* source,
162                                const std::string& impl,
163                                TypeCode * type,bool init) throw (ConversionException);
164                                
165       virtual InputPort* adaptCppToCorba(InputCppPort* source,
166                                             TypeCode * type) throw (ConversionException);
167       
168       virtual InputPort* adaptCppToNeutral(InputCppPort* source,
169                                               TypeCode * type) throw (ConversionException);
170
171       virtual InputPort* adaptCppToPython(InputCppPort* source,
172                                              TypeCode * type) throw (ConversionException);
173       
174       virtual InputPort* adaptCppToXml(InputCppPort* source,
175                                           TypeCode * type) throw (ConversionException);
176
177       virtual InputPort* adaptCppToCpp(InputCppPort* source,
178                                           TypeCode * type) throw (ConversionException);
179
180       virtual InputPort* adapt(InputXmlPort* source,
181                                const std::string& impl,
182                                TypeCode * type,bool init) throw (ConversionException);
183
184       virtual InputPort* adaptXmlToCorba(InputXmlPort* source,
185                                          TypeCode * type) throw (ConversionException);
186
187       virtual InputPort* adaptXmlToPython(InputXmlPort* inport,
188                                           TypeCode * type) throw (ConversionException);
189
190       virtual InputPort* adaptXmlToCpp(InputXmlPort* inport,
191                                           TypeCode * type) throw (ConversionException);
192
193       virtual InputPort* adaptXmlToNeutral(InputXmlPort* inport,
194                                           TypeCode * type) throw (ConversionException);
195
196       virtual InputPort* adaptNeutralToXml(InputPort* inport,
197                                            TypeCode * type) throw (ConversionException);
198
199       virtual InputPort* adaptNeutralToPython(InputPort* inport,
200                                               TypeCode * type) throw (ConversionException);
201
202       virtual InputPort* adaptNeutralToCorba(InputPort* inport,
203                                              TypeCode * type) throw (ConversionException);
204
205       virtual InputPort* adaptNeutralToCpp(InputPort* inport,
206                                              TypeCode * type) throw (ConversionException);
207
208       virtual void* convertNeutral(TypeCode * type, Any *data);
209       virtual std::string convertNeutralAsString(TypeCode * type, Any *data);
210       virtual std::string convertPyObjectToString(PyObject* ob);
211       virtual PyObject* convertStringToPyObject(const std::string& s);
212
213       virtual ~RuntimeSALOME(); 
214
215       CORBA::ORB_ptr getOrb();
216       PyObject * getPyOrb();
217       PyObject * getBuiltins();
218       DynamicAny::DynAnyFactory_ptr getDynFactory();
219       omniORBpyAPI* getApi();
220       PyObject * get_omnipy();
221
222     protected:
223       RuntimeSALOME();  // singleton
224       RuntimeSALOME(long flags);  // singleton
225       void initBuiltins();
226       CORBA::ORB_var _orb;
227       PyObject * _pyorb;
228       PyObject * _bltins;
229       DynamicAny::DynAnyFactory_var _dynFactory;
230       omniORBpyAPI* _api;
231       PyObject* _omnipy;
232       long _flags;
233       bool _usePython, _useCorba, _useCpp, _useXml;
234
235     };
236   }
237 }
238
239 #endif