]> SALOME platform Git repositories - modules/kernel.git/blob - src/LifeCycleCORBA/Test_LifeCycleCORBA.cxx
Salome HOME
updated copyright message
[modules/kernel.git] / src / LifeCycleCORBA / Test_LifeCycleCORBA.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
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
26 //  Module : SALOME
27 //  $Header$
28 //
29 #include <iostream>
30 #ifndef WIN32
31 #include <unistd.h>
32 #endif
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"
40 #include "OpUtil.hxx"
41 #include "utilities.h"
42 #include <Basics_Utils.hxx>
43
44 int main (int argc, char * argv[])
45 {
46
47   try
48     {
49       // --- Initialize omniORB
50       SetArgcArgv(argc, argv);
51       CORBA::ORB_var orb = KERNEL::GetRefToORB();
52     
53       // --- Obtain a reference to the root POA
54
55       CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
56       PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
57
58       // --- Naming Service and LifeCycleCORBA interfaces
59     
60       SALOME_NamingService _NS(orb) ;
61       SALOME_LifeCycleCORBA _LCC(&_NS) ;
62
63       // --- get a local container,
64       //     load an engine, and invoque methods on that engine
65
66       std::string containerName = "myServer";
67       MESSAGE("FindOrLoadComponent " + containerName + "/" + "SalomeTestComponent" );
68
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));
77
78       // --- get another container,
79       //     load an engine, and invoque methods on that engine
80
81       std::string containerName2 = "otherServer";
82
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));
92
93       // --- get a third container,
94       //     load an engine, and invoque methods on that engine
95
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;
102
103       // --- yet another container, with hostname,
104       //     load an engine, and invoque methods on that engine
105
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;
114
115       // --- try a local file transfer
116
117       std::string origFileName = "/home/prascle/petitfichier";
118       SALOME_FileTransferCORBA transfer( Kernel_Utils::GetHostname(),
119                                          origFileName);
120       std::string local = transfer.getLocalFile();
121       SCRUTE(local);
122
123       // --- try a file transfer from another computer
124
125       origFileName = "/home/prascle/occ60.tgz";
126       SALOME_FileTransferCORBA transfer2( "cli76ce",
127                                          origFileName);
128       local = transfer2.getLocalFile();
129       SCRUTE(local);
130       local = transfer2.getLocalFile();
131       SCRUTE(local);
132
133     }
134   catch(CORBA::SystemException& ex)
135     {
136       INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.");
137     }
138   catch(CORBA::Exception&)
139     {
140       INFOS("Caught CORBA::Exception.");
141     }
142   catch(...)
143     {
144       INFOS("Caught unknown exception.");
145     }
146
147   return 0;
148 }