Salome HOME
Porting to Mandrake 10.1 and new products:
[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 #include <iostream>
30 #include <unistd.h>
31 #include <SALOMEconfig.h>
32 #include CORBA_CLIENT_HEADER(SALOME_Component)
33 #include CORBA_CLIENT_HEADER(SALOME_TestComponent)
34 #include "SALOME_NamingService.hxx"
35 #include "SALOME_LifeCycleCORBA.hxx"
36 #include "utilities.h"
37 #include "SALOMETraceCollector.hxx"
38 #include <OpUtil.hxx>
39
40 using namespace std;
41
42 int main (int argc, char * argv[])
43 {
44
45   try
46     {
47       // Initializing omniORB
48       CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
49       SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
50     
51       // Obtain a reference to the root POA
52       CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
53       PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
54     
55       SALOME_NamingService _NS(orb) ;
56
57       SALOME_LifeCycleCORBA _LCC(&_NS) ;
58
59       // get a local container (with a name based on local hostname),
60       // load an engine, and invoque methods on that engine
61
62       string containerName = GetHostname();
63
64       cout << containerName << endl;
65       cout << "FindOrLoadComponent " + containerName + "/" + "SalomeTestComponent" << endl;
66       MESSAGE("FindOrLoadComponent " + containerName + "/" + "SalomeTestComponent" );
67
68       Engines::Component_var mycompo =
69         _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
70
71       ASSERT(!CORBA::is_nil(mycompo));
72
73       Engines::TestComponent_var m1;
74       m1 = Engines::TestComponent::_narrow(mycompo);
75
76       ASSERT(!CORBA::is_nil(m1));
77
78       SCRUTE(m1->instanceName());
79       MESSAGE("Coucou " << m1->Coucou(1L));
80
81       // get another container (with a fixed name),
82       // load an engine, and invoque methods on that engine
83
84       string containerName2 = "FactoryServerPy";
85
86       Engines::Component_var mycompo2 =
87         _LCC.FindOrLoad_Component(containerName2.c_str(),"SALOME_TestComponentPy");
88
89       ASSERT(!CORBA::is_nil(mycompo2));
90
91       Engines::TestComponent_var m2;
92       m2 = Engines::TestComponent::_narrow(mycompo2);
93
94       ASSERT(!CORBA::is_nil(m2));
95
96       SCRUTE(m2->instanceName());
97       cout << m2->instanceName() << endl;
98       MESSAGE("Coucou " << m2->Coucou(1L));
99
100       Engines::Component_var mycompo3 = _LCC.FindOrLoad_Component("totoPy","SALOME_TestComponentPy");
101       ASSERT(!CORBA::is_nil(mycompo3));
102       Engines::TestComponent_var m3 = Engines::TestComponent::_narrow(mycompo3);
103       ASSERT(!CORBA::is_nil(m3));
104       cout << m3->instanceName() << endl;
105
106       string containerName4 = containerName + "/titiPy";
107       Engines::Component_var mycompo4 = _LCC.FindOrLoad_Component(containerName4.c_str(),"SALOME_TestComponentPy");
108       ASSERT(!CORBA::is_nil(mycompo4));
109       Engines::TestComponent_var m4 = Engines::TestComponent::_narrow(mycompo4);
110       ASSERT(!CORBA::is_nil(m4));
111       cout << m4->instanceName() << endl;
112
113     }
114   catch(CORBA::SystemException& ex)
115     {
116       INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.");
117     }
118   catch(CORBA::SystemException&)
119     {
120       INFOS("Caught a CORBA::SystemException.");
121     }
122   catch(CORBA::Exception&)
123     {
124       INFOS("Caught CORBA::Exception.");
125     }
126   catch(...)
127     {
128       INFOS("Caught unknown exception.");
129     }
130
131   return 0;
132 }
133