Salome HOME
Merge from BR_V5_DEV 17Feb09
[samples/component.git] / src / TestFunctions / DynInvoke.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  SUPERV GraphExecutor : contains classes that permit execution of graphs and particularly the execution automaton
23 //  File   : DataFlowBase_DynInvoke.cxx
24 //  Author : Marc Tajchman, CEA
25 //  Module : SUPERV
26 //  $Header:
27 //
28 #include <iostream>
29 #include <unistd.h>
30 #include <iostream>
31 #include <fstream>
32 #include <sstream>
33 #include <iomanip>
34 #include <string>
35 #include <map>
36
37 #include <SALOMEconfig.h>
38 #include CORBA_CLIENT_HEADER(SALOME_Component)
39
40 #include "DynInvoke.hxx"
41
42 #include <stdarg.h>
43
44 using namespace std;
45 using namespace CORBA ;
46
47 void DynInvoke( Engines::Component_ptr objComponent ,
48                 const char *method , 
49                 ServicesAnyData * inParams , int nInParams ,
50                 ServicesAnyData * outParams , int nOutParams ) {
51   Request_var req = objComponent->_request( method ) ;
52   const char *ArgName ;
53   int Type ;
54
55   NVList_ptr arguments = req->arguments() ;
56
57   int i ;
58
59   int n_in  = nInParams ;
60   int n_out = nOutParams ;
61
62 //  char * aComponent = ObjectToString( objComponent ) ;
63 //  MESSAGE( aComponent << "->" << method ) ;
64   for ( i = 0 ; i < n_in ; i++ ) {
65     CORBA::Any & data = inParams[i].Value ;
66     ArgName           = inParams[i].Name.c_str() ;
67     Type              = data.type()->kind() ;
68     arguments->add_value( ArgName , data , CORBA::ARG_IN ) ;
69 #if 0
70     switch ( Type ) {
71     case CORBA::tk_string : {
72       char * t ;
73       data >>= t ;
74       MESSAGE( "ArgIn" << i << " : " << ArgName << " Value " << t << " (string)" ) ;
75       break ;
76     }
77     case CORBA::tk_boolean : {
78       bool b ;
79       data >>= (CORBA::Any::to_boolean ) b ;
80       MESSAGE( "ArgIn" << i << " : " << ArgName << " Value " << b << " (boolean)" ) ;
81       break ;
82     }
83     case CORBA::tk_char : {
84       unsigned char c ;
85       data >>= (CORBA::Any::to_char ) c ;
86       MESSAGE( "ArgIn" << i << " : " << ArgName << " Value " << (int ) c << " (char)" ) ;
87       break ;
88     }
89     case CORBA::tk_short : {
90       short s ;
91       data >>= s ;
92       MESSAGE( "ArgIn" << i << " : " << ArgName << " Value " << s << " (short)" ) ;
93       break ;
94     }
95     case CORBA::tk_long : {
96       long l ;
97       data >>= l ;
98       MESSAGE( "ArgIn" << i << " : " << ArgName << " Value " << l << " (long)" ) ;
99       break ;
100     }
101     case CORBA::tk_float : {
102       float f ;
103       data >>= f ;
104       MESSAGE( "ArgIn" << i << " : " << ArgName << " Value " << f << " (float)" ) ;
105       break ;
106     }
107     case CORBA::tk_double : {
108       double d ;
109       data >>= d ;
110       MESSAGE( "ArgIn" << i << " : " << ArgName << " Value " << d << " (double)" ) ;
111       break ;
112     }
113     case CORBA::tk_objref : {
114       CORBA::Object_ptr obj ;
115       char * retstr = "Catched ERROR";
116       try {
117         data >>= obj ;
118         retstr = ObjectToString( obj ) ;
119       }
120       catch( ... ) {
121       }
122       MESSAGE( "ArgIn" << i << " : " << ArgName << " Value " << retstr << "(object reference)" ) ;
123       break ;
124     }
125     default : {
126       MESSAGE( "ArgIn" << i << " : " << ArgName << " Value " << "(other ERROR) kind " << Type ) ;
127     }
128     }
129     MESSAGE("") ;
130 #endif
131   }
132
133   for ( i = 0 ; i < n_out ; i++ ) {
134     CORBA::Any & data = outParams[i].Value ;
135     ArgName           = outParams[i].Name.c_str() ;
136     Type              = data.type()->kind() ;
137     arguments->add_value( ArgName , data , CORBA::ARG_OUT ) ;
138 #if 0
139     switch ( Type ) {
140     case CORBA::tk_string : {
141       char * t ;
142       data >>= t ;
143       MESSAGE( "ArgOut" << i << " : " << ArgName << " Value " << t << " (string)" ) ;
144       break ;
145     }
146     case CORBA::tk_boolean : {
147       bool b ;
148       data >>= (CORBA::Any::to_boolean ) b ;
149       MESSAGE( "ArgOut" << i << " : " << ArgName << " Value " << b << " (boolean)" ) ;
150       break ;
151     }
152     case CORBA::tk_char : {
153       unsigned char c ;
154       data >>= (CORBA::Any::to_char ) c ;
155       MESSAGE( "ArgOut" << i << " : " << ArgName << " Value " << (int ) c << " (char)" ) ;
156       break ;
157     }
158     case CORBA::tk_short : {
159       short s ;
160       data >>= s ;
161       MESSAGE( "ArgOut" << i << " : " << ArgName << " Value " << s << " (short)" ) ;
162       break ;
163     }
164     case CORBA::tk_long : {
165       long l ;
166       data >>= l ;
167       MESSAGE( "ArgOut" << i << " : " << ArgName << " Value " << l << " (long)" ) ;
168       break ;
169     }
170     case CORBA::tk_float : {
171       float f ;
172       data >>= f ;
173       MESSAGE( "ArgOut" << i << " : " << ArgName << " Value " << f << " (float)" ) ;
174       break ;
175     }
176     case CORBA::tk_double : {
177       double d ;
178       data >>= d ;
179       MESSAGE( "ArgOut" << i << " : " << ArgName << " Value " << d << " (double)" ) ;
180       break ;
181     }
182     case CORBA::tk_objref : {
183       CORBA::Object_ptr obj ;
184       char * retstr = "Catched ERROR";
185       try {
186         data >>= obj ;
187         retstr = ObjectToString( obj ) ;
188       }
189       catch( ... ) {
190       }
191       MESSAGE( "ArgOut" << i << " : " << ArgName << " Value " << retstr << "(object reference)" ) ;
192       break ;
193     }
194     default : {
195       MESSAGE( "ArgOut" << i << " : " << ArgName << " Value " << "(other ERROR) kind " << Type ) ;
196     }
197     }
198     MESSAGE("") ;
199 #endif
200   }
201
202   req->invoke();
203
204   if( req->env()->exception() ) {
205     req->env()->exception()->_raise() ;
206     return ; // pas utile ?
207   }
208
209   for ( i = 0 ; i < n_out ; i++ ) {
210
211       outParams[i].Value = *( arguments->item( i + n_in )->value() ) ;
212   }
213
214   return;
215
216 }
217