1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SALOME LifeCycleCORBA : implementation of containers and engines life cycle both in Python and C++
23 // File : TestLifeCycleCORBA.cxx
24 // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
32 #include <SALOMEconfig.h>
33 #include CORBA_CLIENT_HEADER(SALOME_Component)
34 #include CORBA_CLIENT_HEADER(SALOME_TestComponent)
35 #include "SALOME_NamingService.hxx"
36 #include "SALOME_LifeCycleCORBA.hxx"
37 #include "SALOME_FileTransferCORBA.hxx"
38 #include "utilities.h"
39 #include <Basics_Utils.hxx>
43 int main (int argc, char * argv[])
48 // --- Initialize omniORB
50 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
52 // --- Obtain a reference to the root POA
54 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
55 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
57 // --- Naming Service and LifeCycleCORBA interfaces
59 SALOME_NamingService _NS(orb) ;
60 SALOME_LifeCycleCORBA _LCC(&_NS) ;
62 // --- get a local container,
63 // load an engine, and invoque methods on that engine
65 string containerName = "myServer";
66 MESSAGE("FindOrLoadComponent " + containerName + "/" + "SalomeTestComponent" );
68 Engines::Component_var mycompo =
69 _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
70 ASSERT(!CORBA::is_nil(mycompo));
71 Engines::TestComponent_var m1;
72 m1 = Engines::TestComponent::_narrow(mycompo);
73 ASSERT(!CORBA::is_nil(m1));
74 SCRUTE(m1->instanceName());
75 MESSAGE("Coucou " << m1->Coucou(1L));
77 // --- get another container,
78 // load an engine, and invoque methods on that engine
80 string containerName2 = "otherServer";
82 Engines::Component_var mycompo2 =
83 _LCC.FindOrLoad_Component(containerName2.c_str(),"SALOME_TestComponentPy");
84 ASSERT(!CORBA::is_nil(mycompo2));
85 Engines::TestComponent_var m2;
86 m2 = Engines::TestComponent::_narrow(mycompo2);
87 ASSERT(!CORBA::is_nil(m2));
88 SCRUTE(m2->instanceName());
89 cout << m2->instanceName() << endl;
90 MESSAGE("Coucou " << m2->Coucou(1L));
92 // --- get a third container,
93 // load an engine, and invoque methods on that engine
95 Engines::Component_var mycompo3 =
96 _LCC.FindOrLoad_Component("totoPy","SALOME_TestComponentPy");
97 ASSERT(!CORBA::is_nil(mycompo3));
98 Engines::TestComponent_var m3 = Engines::TestComponent::_narrow(mycompo3);
99 ASSERT(!CORBA::is_nil(m3));
100 cout << m3->instanceName() << endl;
102 // --- yet another container, with hostname,
103 // load an engine, and invoque methods on that engine
105 string containerName4 = Kernel_Utils::GetHostname();
106 containerName4 += "/titiPy";
107 Engines::Component_var mycompo4 =
108 _LCC.FindOrLoad_Component(containerName4.c_str(),"SALOME_TestComponentPy");
109 ASSERT(!CORBA::is_nil(mycompo4));
110 Engines::TestComponent_var m4 = Engines::TestComponent::_narrow(mycompo4);
111 ASSERT(!CORBA::is_nil(m4));
112 cout << m4->instanceName() << endl;
114 // --- try a local file transfer
116 string origFileName = "/home/prascle/petitfichier";
117 SALOME_FileTransferCORBA transfer( Kernel_Utils::GetHostname(),
119 string local = transfer.getLocalFile();
122 // --- try a file transfer from another computer
124 origFileName = "/home/prascle/occ60.tgz";
125 SALOME_FileTransferCORBA transfer2( "cli76ce",
127 local = transfer2.getLocalFile();
129 local = transfer2.getLocalFile();
133 catch(CORBA::SystemException& ex)
135 INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.");
137 catch(CORBA::Exception&)
139 INFOS("Caught CORBA::Exception.");
143 INFOS("Caught unknown exception.");