Salome HOME
b67b988b63932908d394774f5e7e2026e57340c7
[modules/kernel.git] / src / LifeCycleCORBA / TestLifeCycleCORBA.cxx
1 //  SALOME LifeCycleCORBA : implementation of containers and engines life cycle both in Python and C++
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : TestLifeCycleCORBA.cxx
25 //  Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
26 //  Module : SALOME
27 //  $Header$
28
29 using namespace std;
30 #include "utilities.h"
31 #include <iostream>
32 #include <unistd.h>
33 #include <SALOMEconfig.h>
34 #include CORBA_CLIENT_HEADER(SALOME_Component)
35 #include CORBA_CLIENT_HEADER(SALOME_TestComponent)
36 #include "SALOME_NamingService.hxx"
37 #include "SALOME_LifeCycleCORBA.hxx"
38 #include <OpUtil.hxx>
39
40 int main (int argc, char * argv[])
41 {
42
43   try
44     {
45       // Initializing omniORB
46       CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
47     
48       // Obtain a reference to the root POA
49       CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
50       PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
51     
52       SALOME_NamingService _NS(orb) ;
53
54       SALOME_LifeCycleCORBA _LCC(&_NS) ;
55
56       // get a local container (with a name based on local hostname),
57       // load an engine, and invoque methods on that engine
58
59       string containerName = GetHostname();
60
61       Engines::Component_var mycompo =
62         _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
63
64       ASSERT(!CORBA::is_nil(mycompo));
65
66       Engines::TestComponent_var m1;
67       m1 = Engines::TestComponent::_narrow(mycompo);
68
69       ASSERT(!CORBA::is_nil(m1));
70
71       SCRUTE(m1->instanceName());
72       MESSAGE("Coucou " << m1->Coucou(1L));
73
74       // get another container (with a fixed name),
75       // load an engine, and invoque methods on that engine
76
77       string containerName2 = "FactoryServerPy";
78
79       Engines::Component_var mycompo2 =
80         _LCC.FindOrLoad_Component(containerName2.c_str(),"SALOME_TestComponentPy");
81
82       ASSERT(!CORBA::is_nil(mycompo2));
83
84       Engines::TestComponent_var m2;
85       m2 = Engines::TestComponent::_narrow(mycompo2);
86
87       ASSERT(!CORBA::is_nil(m2));
88
89       SCRUTE(m2->instanceName());
90       MESSAGE("Coucou " << m2->Coucou(1L));
91     }
92   catch(CORBA::COMM_FAILURE& ex)
93     {
94       INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.");
95     }
96   catch(CORBA::SystemException&)
97     {
98       INFOS("Caught a CORBA::SystemException.");
99     }
100   catch(CORBA::Exception&)
101     {
102       INFOS("Caught CORBA::Exception.");
103     }
104   catch(...)
105     {
106       INFOS("Caught unknown exception.");
107     }
108
109   return 0;
110 }
111