1 // Copyright (C) 2007-2024 CEA, EDF, 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, or (at your option) any later version.
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
23 // SALOME LifeCycleCORBA : implementation of containers and engines life cycle both in Python and C++
24 // File : TestLifeCycleCORBA.cxx
25 // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
33 #include <SALOMEconfig.h>
34 #include CORBA_CLIENT_HEADER(SALOME_Component)
35 #include CORBA_CLIENT_HEADER(SALOME_TestComponent)
36 #include "ArgvKeeper.hxx"
37 #include "SALOME_NamingService.hxx"
38 #include "SALOME_LifeCycleCORBA.hxx"
39 #include "SALOME_FileTransferCORBA.hxx"
41 #include "utilities.h"
42 #include <Basics_Utils.hxx>
44 int main (int argc, char * argv[])
49 // --- Initialize omniORB
50 SetArgcArgv(argc, argv);
51 CORBA::ORB_var orb = KERNEL::GetRefToORB();
53 // --- Obtain a reference to the root POA
55 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
56 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
58 // --- Naming Service and LifeCycleCORBA interfaces
60 SALOME_NamingService _NS(orb) ;
61 SALOME_LifeCycleCORBA _LCC(&_NS) ;
63 // --- get a local container,
64 // load an engine, and invoque methods on that engine
66 std::string containerName = "myServer";
67 MESSAGE("FindOrLoadComponent " + containerName + "/" + "SalomeTestComponent" );
69 Engines::EngineComponent_var mycompo =
70 _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
71 ASSERT(!CORBA::is_nil(mycompo));
72 Engines::TestComponent_var m1;
73 m1 = Engines::TestComponent::_narrow(mycompo);
74 ASSERT(!CORBA::is_nil(m1));
75 SCRUTE(m1->instanceName());
76 MESSAGE("Coucou " << m1->Coucou(1L));
78 // --- get another container,
79 // load an engine, and invoque methods on that engine
81 std::string containerName2 = "otherServer";
83 Engines::EngineComponent_var mycompo2 =
84 _LCC.FindOrLoad_Component(containerName2.c_str(),"SALOME_TestComponentPy");
85 ASSERT(!CORBA::is_nil(mycompo2));
86 Engines::TestComponent_var m2;
87 m2 = Engines::TestComponent::_narrow(mycompo2);
88 ASSERT(!CORBA::is_nil(m2));
89 SCRUTE(m2->instanceName());
90 std::cout << m2->instanceName() << std::endl;
91 MESSAGE("Coucou " << m2->Coucou(1L));
93 // --- get a third container,
94 // load an engine, and invoque methods on that engine
96 Engines::EngineComponent_var mycompo3 =
97 _LCC.FindOrLoad_Component("totoPy","SALOME_TestComponentPy");
98 ASSERT(!CORBA::is_nil(mycompo3));
99 Engines::TestComponent_var m3 = Engines::TestComponent::_narrow(mycompo3);
100 ASSERT(!CORBA::is_nil(m3));
101 std::cout << m3->instanceName() << std::endl;
103 // --- yet another container, with hostname,
104 // load an engine, and invoque methods on that engine
106 std::string containerName4 = Kernel_Utils::GetHostname();
107 containerName4 += "/titiPy";
108 Engines::EngineComponent_var mycompo4 =
109 _LCC.FindOrLoad_Component(containerName4.c_str(),"SALOME_TestComponentPy");
110 ASSERT(!CORBA::is_nil(mycompo4));
111 Engines::TestComponent_var m4 = Engines::TestComponent::_narrow(mycompo4);
112 ASSERT(!CORBA::is_nil(m4));
113 std::cout << m4->instanceName() << std::endl;
115 // --- try a local file transfer
117 std::string origFileName = "/home/prascle/petitfichier";
118 SALOME_FileTransferCORBA transfer( Kernel_Utils::GetHostname(),
120 std::string local = transfer.getLocalFile();
123 // --- try a file transfer from another computer
125 origFileName = "/home/prascle/occ60.tgz";
126 SALOME_FileTransferCORBA transfer2( "cli76ce",
128 local = transfer2.getLocalFile();
130 local = transfer2.getLocalFile();
134 catch(CORBA::SystemException& ex)
136 INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.");
138 catch(CORBA::Exception&)
140 INFOS("Caught CORBA::Exception.");
144 INFOS("Caught unknown exception.");