Salome HOME
Initialisation de la base KERNEL avec la version operationnelle de KERNEL_SRC issue...
[modules/kernel.git] / src / LifeCycleCORBA / TestLifeCycleCORBA.cxx
1 using namespace std;
2 //=============================================================================
3 // File      : TestLifeCycleCORBA.cxx
4 // Created   : jeu jui 12 13:11:27 CEST 2001
5 // Author    : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
6 // Project   : SALOME
7 // Copyright : EDF 2001
8 // $Header$
9 //=============================================================================
10
11 #include "utilities.h"
12 #include <iostream>
13 #include <unistd.h>
14 #include <SALOMEconfig.h>
15 #include CORBA_CLIENT_HEADER(SALOME_Component)
16 #include CORBA_CLIENT_HEADER(SALOME_TestComponent)
17 #include "SALOME_NamingService.hxx"
18 #include "SALOME_LifeCycleCORBA.hxx"
19 #include <OpUtil.hxx>
20
21 int main (int argc, char * argv[])
22 {
23
24   try
25     {
26       // Initializing omniORB
27       CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
28     
29       // Obtain a reference to the root POA
30       CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
31       PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
32     
33       SALOME_NamingService _NS(orb) ;
34
35       SALOME_LifeCycleCORBA _LCC(&_NS) ;
36
37       // get a local container (with a name based on local hostname),
38       // load an engine, and invoque methods on that engine
39
40       string containerName = GetHostname();
41
42       Engines::Component_var mycompo =
43         _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
44
45       ASSERT(!CORBA::is_nil(mycompo));
46
47       Engines::TestComponent_var m1;
48       m1 = Engines::TestComponent::_narrow(mycompo);
49
50       ASSERT(!CORBA::is_nil(m1));
51
52       SCRUTE(m1->instanceName());
53       MESSAGE("Coucou " << m1->Coucou(1L));
54
55       // get another container (with a fixed name),
56       // load an engine, and invoque methods on that engine
57
58       string containerName2 = "FactoryServerPy";
59
60       Engines::Component_var mycompo2 =
61         _LCC.FindOrLoad_Component(containerName2.c_str(),"SALOME_TestComponentPy");
62
63       ASSERT(!CORBA::is_nil(mycompo2));
64
65       Engines::TestComponent_var m2;
66       m2 = Engines::TestComponent::_narrow(mycompo2);
67
68       ASSERT(!CORBA::is_nil(m2));
69
70       SCRUTE(m2->instanceName());
71       MESSAGE("Coucou " << m2->Coucou(1L));
72     }
73   catch(CORBA::COMM_FAILURE& ex)
74     {
75       INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.");
76     }
77   catch(CORBA::SystemException&)
78     {
79       INFOS("Caught a CORBA::SystemException.");
80     }
81   catch(CORBA::Exception&)
82     {
83       INFOS("Caught CORBA::Exception.");
84     }
85   catch(...)
86     {
87       INFOS("Caught unknown exception.");
88     }
89
90   return 0;
91 }
92