1 // SALOME LifeCycleCORBA : implementation of containers and engines life cycle both in Python and C++
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : TestLifeCycleCORBA.cxx
25 // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
33 #include <SALOMEconfig.h>
35 #include CORBA_CLIENT_HEADER(SALOME_Component)
36 #include CORBA_CLIENT_HEADER(SALOME_TestComponent)
38 #include <SALOME_Component.hh>
39 #include <SALOME_TestComponent.hh>
41 #include "SALOME_NamingService.hxx"
42 #include "SALOME_LifeCycleCORBA.hxx"
43 #include "utilities.h"
44 #include "SALOMETraceCollector.hxx"
49 int main (int argc, char * argv[])
54 // Initializing omniORB
55 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
56 // LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
58 // Obtain a reference to the root POA
59 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
60 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
62 SALOME_NamingService _NS(orb) ;
64 SALOME_LifeCycleCORBA _LCC(&_NS) ;
66 // get a local container (with a name based on local hostname),
67 // load an engine, and invoque methods on that engine
69 string containerName = GetHostname();
71 cout << containerName << endl;
72 cout << "FindOrLoadComponent " + containerName + "/" + "SalomeTestComponent" << endl;
73 MESSAGE("FindOrLoadComponent " + containerName + "/" + "SalomeTestComponent" );
75 Engines::Component_var mycompo =
76 _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
78 ASSERT(!CORBA::is_nil(mycompo));
80 Engines::TestComponent_var m1;
81 m1 = Engines::TestComponent::_narrow(mycompo);
83 ASSERT(!CORBA::is_nil(m1));
85 SCRUTE(m1->instanceName());
86 MESSAGE("Coucou " << m1->Coucou(1L));
88 // get another container (with a fixed name),
89 // load an engine, and invoque methods on that engine
91 string containerName2 = "FactoryServerPy";
93 Engines::Component_var mycompo2 =
94 _LCC.FindOrLoad_Component(containerName2.c_str(),"SALOME_TestComponentPy");
96 ASSERT(!CORBA::is_nil(mycompo2));
98 Engines::TestComponent_var m2;
99 m2 = Engines::TestComponent::_narrow(mycompo2);
101 ASSERT(!CORBA::is_nil(m2));
103 SCRUTE(m2->instanceName());
104 cout << m2->instanceName() << endl;
105 MESSAGE("Coucou " << m2->Coucou(1L));
107 Engines::Component_var mycompo3 = _LCC.FindOrLoad_Component("totoPy","SALOME_TestComponentPy");
108 ASSERT(!CORBA::is_nil(mycompo3));
109 Engines::TestComponent_var m3 = Engines::TestComponent::_narrow(mycompo3);
110 ASSERT(!CORBA::is_nil(m3));
111 cout << m3->instanceName() << endl;
113 string containerName4 = containerName + "/titiPy";
114 Engines::Component_var mycompo4 = _LCC.FindOrLoad_Component(containerName4.c_str(),"SALOME_TestComponentPy");
115 ASSERT(!CORBA::is_nil(mycompo4));
116 Engines::TestComponent_var m4 = Engines::TestComponent::_narrow(mycompo4);
117 ASSERT(!CORBA::is_nil(m4));
118 cout << m4->instanceName() << endl;
121 catch(CORBA::SystemException& ex)
123 INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.");
126 catch(CORBA::SystemException&)
128 INFOS("Caught a CORBA::SystemException.");
131 catch(CORBA::Exception&)
133 INFOS("Caught CORBA::Exception.");
137 INFOS("Caught unknown exception.");