1 // Copyright (C) 2007-2019 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, 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 "SALOME_NamingService.hxx"
37 #include "SALOME_LifeCycleCORBA.hxx"
38 #include "SALOME_FileTransferCORBA.hxx"
39 #include "utilities.h"
40 #include <Basics_Utils.hxx>
42 int main (int argc, char * argv[])
47 // --- Initialize omniORB
49 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
51 // --- Obtain a reference to the root POA
53 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
54 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
56 // --- Naming Service and LifeCycleCORBA interfaces
58 SALOME_NamingService _NS(orb) ;
59 SALOME_LifeCycleCORBA _LCC(&_NS) ;
61 // --- get a local container,
62 // load an engine, and invoque methods on that engine
64 std::string containerName = "myServer";
65 MESSAGE("FindOrLoadComponent " + containerName + "/" + "SalomeTestComponent" );
67 Engines::EngineComponent_var mycompo =
68 _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
69 ASSERT(!CORBA::is_nil(mycompo));
70 Engines::TestComponent_var m1;
71 m1 = Engines::TestComponent::_narrow(mycompo);
72 ASSERT(!CORBA::is_nil(m1));
73 SCRUTE(m1->instanceName());
74 MESSAGE("Coucou " << m1->Coucou(1L));
76 // --- get another container,
77 // load an engine, and invoque methods on that engine
79 std::string containerName2 = "otherServer";
81 Engines::EngineComponent_var mycompo2 =
82 _LCC.FindOrLoad_Component(containerName2.c_str(),"SALOME_TestComponentPy");
83 ASSERT(!CORBA::is_nil(mycompo2));
84 Engines::TestComponent_var m2;
85 m2 = Engines::TestComponent::_narrow(mycompo2);
86 ASSERT(!CORBA::is_nil(m2));
87 SCRUTE(m2->instanceName());
88 std::cout << m2->instanceName() << std::endl;
89 MESSAGE("Coucou " << m2->Coucou(1L));
91 // --- get a third container,
92 // load an engine, and invoque methods on that engine
94 Engines::EngineComponent_var mycompo3 =
95 _LCC.FindOrLoad_Component("totoPy","SALOME_TestComponentPy");
96 ASSERT(!CORBA::is_nil(mycompo3));
97 Engines::TestComponent_var m3 = Engines::TestComponent::_narrow(mycompo3);
98 ASSERT(!CORBA::is_nil(m3));
99 std::cout << m3->instanceName() << std::endl;
101 // --- yet another container, with hostname,
102 // load an engine, and invoque methods on that engine
104 std::string containerName4 = Kernel_Utils::GetHostname();
105 containerName4 += "/titiPy";
106 Engines::EngineComponent_var mycompo4 =
107 _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 std::cout << m4->instanceName() << std::endl;
113 // --- try a local file transfer
115 std::string origFileName = "/home/prascle/petitfichier";
116 SALOME_FileTransferCORBA transfer( Kernel_Utils::GetHostname(),
118 std::string local = transfer.getLocalFile();
121 // --- try a file transfer from another computer
123 origFileName = "/home/prascle/occ60.tgz";
124 SALOME_FileTransferCORBA transfer2( "cli76ce",
126 local = transfer2.getLocalFile();
128 local = transfer2.getLocalFile();
132 catch(CORBA::SystemException& ex)
134 INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.");
136 catch(CORBA::Exception&)
138 INFOS("Caught CORBA::Exception.");
142 INFOS("Caught unknown exception.");