Salome HOME
Merge from BR_V5_DEV 17Feb09
[samples/component.git] / src / TestFunctions / TestFunctions.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 //  SuperVisionTest TestFunctions : example of component that adds two numbers
23 //  File   : TestFunctions.cxx
24 //  Module : SuperVisionTest
25 //
26 #include <iostream>
27 #include <fstream>
28 #include <unistd.h>
29
30 #include <SALOMEconfig.h>
31 #include CORBA_CLIENT_HEADER(AddComponent)
32 #include CORBA_CLIENT_HEADER(SALOME_Component)
33
34 #include "utilities.h"
35 #include "SALOME_NamingService.hxx"
36 #include "SALOME_LifeCycleCORBA.hxx"
37 #include <OpUtil.hxx>
38
39 #include "DynInvoke.hxx"
40
41 using namespace std;
42
43 int main(int argc, char **argv) {
44   CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
45   CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
46   PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
47   SALOME_NamingService _NS(orb) ;
48   SALOME_LifeCycleCORBA _LCC(&_NS) ;
49
50   Engines::Component_var AddComponent = _LCC.FindOrLoad_Component( "FactoryServer" ,
51                                                                    "AddComponent");
52   SuperVisionTest::AddComponent_var AddInterface ;
53   AddInterface = SuperVisionTest::AddComponent::_narrow( AddComponent );
54
55 // Direct call to AdditionObjRef1
56   SuperVisionTest::Adder_var Adder1 ;
57   bool sts1 = AddInterface->AdditionObjRef1( Adder1 ) ;
58   double Func1 , z1 ;
59   Func1 = Adder1->Add( 1. , 2. , z1 ) ;
60   cout << "TestFunctions sts1 " << sts1 << " Func1 " << Func1 << " z1 " << z1 << endl ;
61
62 // Call to AdditionObjRef1 via dynamic invocation
63   int ninParams = 0 ;
64   ServicesAnyData * inParams = NULL ;
65   int noutParams = 2 ;
66   ServicesAnyData * outParams = new ServicesAnyData[noutParams] ;
67   bool b = 0 ;
68   outParams[ 0 ].Value <<= (CORBA::Any::from_boolean ) b ;
69   outParams[ 1 ].Value <<= CORBA::Object::_nil()  ;
70   DynInvoke( AddInterface , "AdditionObjRef1" , inParams , ninParams ,
71                                                 outParams , noutParams ) ;
72   outParams[ 0 ].Value >>= sts1 ;
73   CORBA::Object_ptr objptr ;
74   outParams[ 1 ].Value >>= objptr ;
75   Adder1 = SuperVisionTest::Adder::_narrow( objptr ) ;
76   Func1 = Adder1->Add( 1. , 2. , z1 ) ;
77   cout << "TestFunctions DynInvoke sts1 " << sts1 << " Func1 " << Func1 << " z1 " << z1
78        << endl ;
79
80 // Direct call to AdditionObjRef2
81   SuperVisionTest::Adder_var Adder2 ;
82   bool sts2 ;
83   AddInterface->AdditionObjRef2( sts2 , Adder2 ) ;
84   double Func2 , z2 ;
85   Func2 = Adder2->Add( 1. , 2. , z2 ) ;
86   cout << "TestFunctions sts2 " << sts2 << " Func2 " << Func2 << " z2 " << z2 << endl ;
87
88 // Call to AdditionObjRef2 via dynamic invocation
89   outParams[ 0 ].Value <<= (CORBA::Any::from_boolean ) b ;
90   outParams[ 1 ].Value <<= CORBA::Object::_nil()  ;
91   DynInvoke( AddInterface , "AdditionObjRef2" , inParams , ninParams ,
92                                                 outParams , noutParams ) ;
93   outParams[ 0 ].Value >>= sts2 ;
94   outParams[ 1 ].Value >>= objptr ;
95   Adder2 = SuperVisionTest::Adder::_narrow( objptr ) ;
96   Func2 = Adder2->Add( 1. , 2. , z2 ) ;
97   cout << "TestFunctions DynInvoke sts2 " << sts2 << " Func2 " << Func2 << " z2 " << z2
98        << endl ;
99
100   return 0;
101 }
102