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