Salome HOME
dba4753571490f3445df170f8ce343e39f21bd5b
[modules/superv.git] / src / GraphExecutor / DataFlowExecutor_DynInvoke.cxx
1 //  SUPERV GraphExecutor : contains classes that permit execution of graphs and particularly the execution automaton
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : DataFlowBase_DynInvoke.cxx
25 //  Author : Marc Tajchman, CEA
26 //  Module : SUPERV
27 //  $Header:
28
29 using namespace std;
30 #include <stdarg.h>
31 #include <map>
32
33 #include "DataFlowExecutor_InNode.hxx"
34
35 using namespace CORBA ;
36
37
38
39 void GraphExecutor::InNode::DynInvoke(Engines::Component_ptr objComponent ,
40                                       const char *method , 
41                                       ServicesAnyData * inParams , int nInParams ,
42                                       ServicesAnyData * outParams , int nOutParams ) {
43   Request_var req = objComponent->_request( method ) ;
44   const char *ArgName ;
45   int Type ;
46
47   NVList_ptr arguments = req->arguments() ;
48
49   int i ;
50
51   int n_in  = nInParams ;
52   int n_out = nOutParams ;
53
54   char * aComponent = ObjectToString( objComponent ) ;
55   MESSAGE( aComponent << "->" << method ) ;
56   for ( i = 0 ; i < n_in ; i++ ) {
57     CORBA::Any & data = inParams[i].Value ;
58     ArgName           = inParams[i].Name.c_str() ;
59     Type              = data.type()->kind() ;
60     arguments->add_value( ArgName , data , CORBA::ARG_IN ) ;
61 //#if 0
62     switch ( Type ) {
63     case CORBA::tk_string : {
64       char * t ;
65       data >>= t ;
66       MESSAGE( "ArgIn" << i << " : " << ArgName << " Value " << t << " (string)" ) ;
67       break ;
68     }
69     case CORBA::tk_boolean : {
70       bool b ;
71       data >>= (CORBA::Any::to_boolean ) b ;
72       MESSAGE( "ArgIn" << i << " : " << ArgName << " Value " << b << " (boolean)" ) ;
73       break ;
74     }
75     case CORBA::tk_char : {
76       unsigned char c ;
77       data >>= (CORBA::Any::to_char ) c ;
78       MESSAGE( "ArgIn" << i << " : " << ArgName << " Value " << (int ) c << " (char)" ) ;
79       break ;
80     }
81     case CORBA::tk_short : {
82       short s ;
83       data >>= s ;
84       MESSAGE( "ArgIn" << i << " : " << ArgName << " Value " << s << " (short)" ) ;
85       break ;
86     }
87     case CORBA::tk_long : {
88       long l ;
89       data >>= l ;
90       MESSAGE( "ArgIn" << i << " : " << ArgName << " Value " << l << " (long)" ) ;
91       break ;
92     }
93     case CORBA::tk_float : {
94       float f ;
95       data >>= f ;
96       MESSAGE( "ArgIn" << i << " : " << ArgName << " Value " << f << " (float)" ) ;
97       break ;
98     }
99     case CORBA::tk_double : {
100       double d ;
101       data >>= d ;
102       MESSAGE( "ArgIn" << i << " : " << ArgName << " Value " << d << " (double)" ) ;
103       break ;
104     }
105     case CORBA::tk_objref : {
106       CORBA::Object_ptr obj ;
107       char * retstr = "Catched ERROR";
108       try {
109         data >>= obj ;
110         retstr = ObjectToString( obj ) ;
111       }
112       catch( ... ) {
113       }
114       MESSAGE( "ArgIn" << i << " : " << ArgName << " Value " << retstr << "(object reference)" ) ;
115       break ;
116     }
117     default : {
118       MESSAGE( "ArgIn" << i << " : " << ArgName << " Value " << "(other ERROR) kind " << Type ) ;
119     }
120     }
121     MESSAGE("") ;
122 //#endif
123   }
124
125   for ( i = 0 ; i < n_out ; i++ ) {
126     CORBA::Any & data = outParams[i].Value ;
127     ArgName           = outParams[i].Name.c_str() ;
128     Type              = data.type()->kind() ;
129     arguments->add_value( ArgName , data , CORBA::ARG_OUT ) ;
130 //#if 0
131     switch ( Type ) {
132     case CORBA::tk_string : {
133       char * t ;
134       data >>= t ;
135       MESSAGE( "ArgOut" << i << " : " << ArgName << " Value " << t << " (string)" ) ;
136       break ;
137     }
138     case CORBA::tk_boolean : {
139       bool b ;
140       data >>= (CORBA::Any::to_boolean ) b ;
141       MESSAGE( "ArgOut" << i << " : " << ArgName << " Value " << b << " (boolean)" ) ;
142       break ;
143     }
144     case CORBA::tk_char : {
145       unsigned char c ;
146       data >>= (CORBA::Any::to_char ) c ;
147       MESSAGE( "ArgOut" << i << " : " << ArgName << " Value " << (int ) c << " (char)" ) ;
148       break ;
149     }
150     case CORBA::tk_short : {
151       short s ;
152       data >>= s ;
153       MESSAGE( "ArgOut" << i << " : " << ArgName << " Value " << s << " (short)" ) ;
154       break ;
155     }
156     case CORBA::tk_long : {
157       long l ;
158       data >>= l ;
159       MESSAGE( "ArgOut" << i << " : " << ArgName << " Value " << l << " (long)" ) ;
160       break ;
161     }
162     case CORBA::tk_float : {
163       float f ;
164       data >>= f ;
165       MESSAGE( "ArgOut" << i << " : " << ArgName << " Value " << f << " (float)" ) ;
166       break ;
167     }
168     case CORBA::tk_double : {
169       double d ;
170       data >>= d ;
171       MESSAGE( "ArgOut" << i << " : " << ArgName << " Value " << d << " (double)" ) ;
172       break ;
173     }
174     case CORBA::tk_objref : {
175       CORBA::Object_ptr obj ;
176       char * retstr = "Catched ERROR";
177       try {
178         data >>= obj ;
179         retstr = ObjectToString( obj ) ;
180       }
181       catch( ... ) {
182       }
183       MESSAGE( "ArgOut" << i << " : " << ArgName << " Value " << retstr << "(object reference)" ) ;
184       break ;
185     }
186     default : {
187       MESSAGE( "ArgOut" << i << " : " << ArgName << " Value " << "(other ERROR) kind " << Type ) ;
188     }
189     }
190     MESSAGE("") ;
191 //#endif
192   }
193
194   req->invoke();
195
196   if( req->env()->exception() ) {
197     req->env()->exception()->_raise() ;
198     return ; // pas utile ?
199   }
200
201   for ( i = 0 ; i < n_out ; i++ ) {
202
203       outParams[i].Value = *( arguments->item( i + n_in )->value() ) ;
204   }
205
206   return;
207
208 }
209
210 void GraphExecutor::InNode::DynInvoke( Engines::Component_ptr obj ,
211                                        const char *method , 
212                                        const char * aGraphName ,
213                                        const char * aNodeName ) {
214   Request_var req = obj->_request( method ) ;
215
216   NVList_ptr arguments =req->arguments() ;
217
218   CORBA::Any graph ;
219   graph <<= aGraphName ;
220   arguments->add_value( "aGraphName" , graph , CORBA::ARG_IN ) ;
221   CORBA::Any node ;
222   node <<= aNodeName ;
223   arguments->add_value( "aNodeName" , node , CORBA::ARG_IN ) ;
224
225   req->invoke() ;
226
227   if( req->env()->exception() ) {
228     req->env()->exception()->_raise();
229   }
230   return;
231
232 }