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