Salome HOME
Retrieve state of ForEachLoop node even in case of failure.
[modules/yacs.git] / src / engine_swig / pilot.i
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 %define DOCSTRING
21 "All is needed to create and execute a calculation schema."
22 %enddef
23
24 %module(docstring=DOCSTRING) pilot
25
26 #ifndef SWIGIMPORTED
27 //work around SWIG bug #1863647
28 #if SWIG_VERSION >= 0x010336
29 #define SwigPyIterator pilot_PySwigIterator
30 #else
31 #define PySwigIterator pilot_PySwigIterator
32 #endif
33 #endif
34
35 %feature("autodoc", "1");
36
37 %include "engtypemaps.i"
38
39 #ifdef DOXYGEN_IS_OK
40 %include docengine.i
41 #endif
42
43 %{
44 #include "Any.hxx"
45 #include "TypeCode.hxx"
46 #include "ComponentDefinition.hxx"
47 #include "Visitor.hxx"
48 #include "VisitorSaveSchema.hxx"
49 #include "VisitorSaveState.hxx"
50 #include "LinkInfo.hxx"
51 #include "Catalog.hxx"
52 #include "Executor.hxx"
53 #include "ExecutorSwig.hxx"
54 #include "Dispatcher.hxx"
55 #include "Container.hxx"
56 #include "HomogeneousPoolContainer.hxx"
57 #include "Logger.hxx"
58 #include "DeploymentTree.hxx"
59 #include "ComponentInstance.hxx"
60 #include "DataNode.hxx"
61
62 using namespace YACS::ENGINE;
63
64 %}
65
66 %init
67 %{
68   // init section
69 #ifdef OMNIORB
70   PyObject* omnipy = PyImport_ImportModule((char*)"_omnipy");
71   if (!omnipy)
72   {
73     PyErr_SetString(PyExc_ImportError,(char*)"Cannot import _omnipy");
74     return;
75   }
76   PyObject* pyapi = PyObject_GetAttrString(omnipy, (char*)"API");
77   api = (omniORBPYAPI*)PyCObject_AsVoidPtr(pyapi);
78   Py_DECREF(pyapi);
79 #endif
80 %}
81
82 %ignore YACS::ENGINE::Any::operator[];
83 %ignore YACS::ENGINE::TypeCode::operator=;
84 %ignore YACS::ENGINE::DeploymentTree::operator=;
85 %ignore operator<<;
86 %ignore YACS::ENGINE::Runtime::_tc_double;
87 %ignore YACS::ENGINE::Runtime::_tc_int;
88 %ignore YACS::ENGINE::Runtime::_tc_bool;
89 %ignore YACS::ENGINE::Runtime::_tc_string;
90 %ignore YACS::ENGINE::Runtime::_tc_file;
91 %rename(StateLoader) YACS::ENGINE::StateLoader; // to suppress a 503 warning
92 %rename(NbDoneLoader) YACS::ENGINE::NbDoneLoader; // to suppress a 503 warning
93 %rename(getRuntime) YACS::ENGINE::getRuntime; // to suppress a 503 warning
94 %rename(_from) YACS::ENGINE::DataLinkInfo::from ; // to suppress a 314 warning
95 %rename(_from) YACS::ENGINE::StreamLinkInfo::from ; // to suppress a 314 warning
96
97 /*
98  * Template section
99  */
100 %template()              std::pair<std::string, YACS::ENGINE::TypeCode *>;
101 %template()              std::pair<std::string, YACS::ENGINE::Node *>;
102 %template()              std::pair<std::string, YACS::ENGINE::InlineNode *>;
103 %template()              std::pair<std::string, YACS::ENGINE::ServiceNode *>;
104 %template()              std::pair<std::string, YACS::ENGINE::Container *>;
105 %template()              std::pair<YACS::ENGINE::OutPort *,YACS::ENGINE::InPort *>;
106 %template()              std::pair<YACS::ENGINE::InPort *,YACS::ENGINE::OutPort *>;
107 //%template(TCmap)         std::map<std::string, YACS::ENGINE::TypeCode *>;
108 REFCOUNT_TEMPLATE(TCmap,YACS::ENGINE::TypeCode)
109 %template(NODEmap)       std::map<std::string, YACS::ENGINE::Node *>;
110 %template(INODEmap)      std::map<std::string, YACS::ENGINE::InlineNode *>;
111 %template(SNODEmap)      std::map<std::string, YACS::ENGINE::ServiceNode *>;
112 //%template(CONTAINmap)    std::map<std::string, YACS::ENGINE::Container *>;
113 REFCOUNT_TEMPLATE(CONTAINmap,YACS::ENGINE::Container)
114 %template(strvec)        std::vector<std::string>;
115 %template(linksvec)      std::vector< std::pair<YACS::ENGINE::OutPort *,YACS::ENGINE::InPort *> >;
116 %template(linkvec)       std::vector< std::pair<YACS::ENGINE::InPort *,YACS::ENGINE::OutPort *> >;
117 %template(instreamlist)  std::list<YACS::ENGINE::InputDataStreamPort *>;
118 %template(outstreamlist) std::list<YACS::ENGINE::OutputDataStreamPort *>;
119
120 %template()              std::pair<std::string, YACS::ENGINE::CatalogLoader *>;
121 %template(loadermap)     std::map<std::string,YACS::ENGINE::CatalogLoader *>;
122 %template()              std::pair<std::string, YACS::ENGINE::ComposedNode *>;
123 %template(composedmap)   std::map<std::string,YACS::ENGINE::ComposedNode *>;
124 %template()              std::pair<std::string, YACS::ENGINE::ComponentDefinition *>;
125 %template(compomap)      std::map<std::string, YACS::ENGINE::ComponentDefinition *>;
126 %template()              std::pair<std::string, std::string>;
127 %template(propmap)       std::map<std::string, std::string>;
128
129 REFCOUNT_TEMPLATE(CompoInstmap,YACS::ENGINE::ComponentInstance)
130
131 /*
132  * End of Template section
133  */
134
135 %typemap(out) Container *
136 {
137   $result=convertContainer($1,$owner);
138 }
139
140 %typemap(out) YACS::ENGINE::Container *
141 {
142   $result=convertContainer($1,$owner);
143 }
144
145 /*
146  * Ownership section
147  */
148 //Take ownership : it is not the default (constructor) as it is a factory
149 %newobject *::createProc;
150 %newobject *::createScriptNode;
151 %newobject *::createFuncNode;
152 %newobject *::createRefNode;
153 %newobject *::createCompoNode;
154 %newobject *::createSInlineNode;
155 %newobject *::createInDataNode;
156 %newobject *::createOutDataNode;
157 %newobject *::createBloc;
158 %newobject *::createForLoop;
159 %newobject *::createForEachLoop;
160 %newobject *::createWhileLoop;
161 %newobject *::createSwitch;
162 %newobject *::loadCatalog;
163 %newobject *::createComponentInstance;
164 %newobject *::createContainer;
165
166
167 %newobject *::createInputPort;
168 %newobject *::createOutputPort;
169 %newobject *::createInputDataStreamPort;
170 %newobject *::createOutputDataStreamPort;
171 %newobject *::clone;
172 %newobject *::cloneAlways;
173 %newobject *::cloneWithoutCompAndContDeepCpy;
174 %newobject *::New;
175
176 //Take ownership : transfer it from C++ (has to be completed)
177 %newobject YACS::ENGINE::Loop::edRemoveNode;
178 %newobject YACS::ENGINE::Switch::edReleaseDefaultNode;
179 %newobject YACS::ENGINE::Switch::edReleaseCase;
180 %newobject YACS::ENGINE::DynParaLoop::edRemoveNode;
181 %newobject YACS::ENGINE::DynParaLoop::edRemoveInitNode;
182 //No other way to do ??
183 %feature("pythonappend") YACS::ENGINE::Bloc::edRemoveChild(Node *node)%{
184         args[1].thisown=1
185 %}
186
187 %newobject *::createSequenceTc;
188 %newobject *::createInterfaceTc;
189 %newobject *::createStructTc;
190 %newobject *::createType;
191
192 %newobject YACS::ENGINE::SequenceAny::removeUnsetItemsFromThis;
193
194 %newobject YACS::ENGINE::TypeCode::interfaceTc;
195 %newobject YACS::ENGINE::TypeCode::sequenceTc;
196 %newobject YACS::ENGINE::TypeCode::structTc;
197
198 /*
199  * End of ownership section
200  */
201
202
203 %include <define.hxx>
204 %include <YACSBasesExport.hxx>
205 %include <Exception.hxx>
206 %include <YACSlibEngineExport.hxx>
207 %include <ConversionException.hxx>
208 %include <Runtime.hxx>
209 %include <PropertyInterface.hxx>
210
211 PYEXCEPTION(YACS::ENGINE::Executor::RunW)
212 PYEXCEPTION(YACS::ENGINE::Executor::RunB)
213 PYEXCEPTION(YACS::ENGINE::Executor::setExecMode)
214 PYEXCEPTION(YACS::ENGINE::Executor::resumeCurrentBreakPoint)
215 PYEXCEPTION(YACS::ENGINE::Executor::stopExecution)
216 PYEXCEPTION(YACS::ENGINE::Executor::waitPause)
217 PYEXCEPTION(YACS::ENGINE::ComponentInstance::load)
218
219 %include <Executor.hxx>
220
221 EXCEPTION(YACS::ENGINE::ExecutorSwig::RunPy)
222 EXCEPTION(YACS::ENGINE::ExecutorSwig::waitPause)
223 %include <ExecutorSwig.hxx>
224
225 %include <RefCounter.hxx>
226
227 %include <Any.hxx>
228
229 %ignore YACS::ENGINE::TypeCode::getOrBuildAnyFromZippedData;
230 %include <TypeCode.hxx>
231
232 %include <Scheduler.hxx>
233 %include <Task.hxx>
234 %include <Dispatcher.hxx>
235 %include <DeploymentTree.hxx>
236 %include <Port.hxx>
237 %extend YACS::ENGINE::Port
238 {
239   int __cmp__(Port* other)
240     {
241       if(self==other)
242         return 0;
243       else 
244         return 1;
245     }
246   long ptr()
247     {
248       return (long)self;
249     }
250 }
251 %include <DataPort.hxx>
252 %include <InPort.hxx>
253 %include <OutPort.hxx>
254 %include <InGate.hxx>
255 %include <OutGate.hxx>
256 %include <DataFlowPort.hxx>
257 %include <DataStreamPort.hxx>
258
259 %include <LinkInfo.hxx>
260 %include <Logger.hxx>
261
262 %include <ComponentInstance.hxx>
263 %include <Container.hxx>
264 %include <HomogeneousPoolContainer.hxx>
265 %include <InputPort.hxx>
266 %extend YACS::ENGINE::InputPort
267 {
268   void edInitXML(const char * s)
269     {
270       self->edInit("XML",s);
271     }
272   void edInitPy(PyObject* ob)
273     {
274       self->edInit("Python",ob);
275     }
276 }
277 %include <InPropertyPort.hxx>
278 %extend YACS::ENGINE::InPropertyPort
279 {
280   void edInitXML(const char * s)
281     {
282       self->edInit("XML",s);
283     }
284   void edInitPy(PyObject* ob)
285     {
286       self->edInit("Python",ob);
287     }
288 }
289
290 %template(edInitInt)       YACS::ENGINE::InputPort::edInit<int>;
291 %template(edInitBool)      YACS::ENGINE::InputPort::edInit<bool>;
292 %template(edInitString)    YACS::ENGINE::InputPort::edInit<std::string>;
293 %template(edInitDbl)       YACS::ENGINE::InputPort::edInit<double>;
294
295 %include <AnyInputPort.hxx>
296 %include <ConditionInputPort.hxx>
297 %include <OutputPort.hxx>
298 %include <AnyOutputPort.hxx>
299 %include <InputDataStreamPort.hxx>
300 %include <OutputDataStreamPort.hxx>
301 %include <DataPort.hxx>
302
303 %include <Node.hxx>
304 %extend YACS::ENGINE::Node 
305 {
306   int __cmp__(Node* other)
307     {
308       if(self==other)
309         return 0;
310       else 
311         return 1;
312     }
313   long ptr()
314     {
315           return (long)self;
316     }
317 }
318
319 %include <ElementaryNode.hxx>
320 %include <InlineNode.hxx>
321 %include <ServiceNode.hxx>
322 %include <ServiceInlineNode.hxx>
323 %include <ServerNode.hxx>
324 %include <DataNode.hxx>
325
326 %include <ComposedNode.hxx>
327 %include <StaticDefinedComposedNode.hxx>
328 %include <Bloc.hxx>
329 %include <Proc.hxx>
330
331 %include <Loop.hxx>
332 %include <ForLoop.hxx>
333 %include <DynParaLoop.hxx>
334 %include <WhileLoop.hxx>
335 %include <ForEachLoop.hxx>
336 %include <OptimizerLoop.hxx>
337 %include <Switch.hxx>
338 %include <Visitor.hxx>
339 %include <VisitorSaveSchema.hxx>
340 %include <ComponentDefinition.hxx>
341 %include <Catalog.hxx>
342 %include <Pool.hxx>
343
344 %include <AlternateThread.hxx>
345 %include <AlternateThreadPT.hxx>
346
347 // Ignore class OptimizerAlgASync to avoid confusion with class
348 // OptimizerAlgASync in module SALOMERuntime
349 %ignore YACS::ENGINE::OptimizerAlgASync;
350 %include <OptimizerAlg.hxx>
351
352 %extend YACS::ENGINE::ConditionInputPort
353 {
354   bool getPyObj()
355   {
356     return self->getValue();
357   }
358 }
359
360 %extend YACS::ENGINE::AnyInputPort
361 {
362   PyObject * getPyObj()
363   {
364     return (PyObject *)getRuntime()->convertNeutral(self->edGetType(),self->getValue());
365   }
366 }
367
368 %extend YACS::ENGINE::AnyOutputPort
369 {
370   PyObject * getPyObj()
371   {
372     return (PyObject *)getRuntime()->convertNeutral(self->edGetType(),self->getValue());
373   }
374 }
375
376 %extend YACS::ENGINE::Any
377 {
378   PyObject *getPyObj()
379   {
380     return (PyObject *)getRuntime()->convertNeutral(const_cast<YACS::ENGINE::TypeCode *>(self->getType()),self);
381   }
382 }
383
384 %newobject YACS::ENGINE::SequenceAny::__getitem__;
385 %extend YACS::ENGINE::SequenceAny
386 {
387   Any* __getitem__(int i)
388   {
389     if (i < self->size())
390       {
391         AnyPtr a=(*self)[i];
392         a->incrRef();
393         return a;
394       }
395     else
396       throw std::length_error("index too large");
397   }
398 }
399
400 %newobject YACS::ENGINE::StructAny::__getitem__;
401 %extend YACS::ENGINE::StructAny
402 {
403   Any* __getitem__(const char * key)
404   {
405     AnyPtr a=(*self)[key];
406     a->incrRef();
407     return a;
408   }
409 }
410
411 %extend YACS::ENGINE::ForEachLoop
412 {
413   PyObject *getPassedResults(Executor *execut) const
414   {
415     std::vector<SequenceAny *> ret1;
416     std::vector<std::string> ret2;
417     std::vector<unsigned int> ret0(self->getPassedResults(execut,ret1,ret2));
418     PyObject *ret(PyTuple_New(3));
419     // param 0
420     PyObject *ret0Py(PyList_New(ret0.size()));
421     for(std::size_t i=0;i<ret0.size();i++)
422       PyList_SetItem(ret0Py,i,PyInt_FromLong(ret0[i]));
423     PyTuple_SetItem(ret,0,ret0Py);
424     // param 1
425     PyObject *ret1Py(PyList_New(ret1.size()));
426     for(std::size_t i=0;i<ret1.size();i++)
427       PyList_SetItem(ret1Py,i,SWIG_NewPointerObj(SWIG_as_voidptr(ret1[i]),SWIGTYPE_p_YACS__ENGINE__SequenceAny, SWIG_POINTER_OWN | 0 ));
428     PyTuple_SetItem(ret,1,ret1Py);
429     // param 2
430     PyObject *ret2Py(PyList_New(ret2.size()));
431     for(std::size_t i=0;i<ret2.size();i++)
432       PyList_SetItem(ret2Py,i,PyString_FromString(ret2[i].c_str()));
433     PyTuple_SetItem(ret,2,ret2Py);
434     return ret;
435   }
436 }