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