Salome HOME
Synchronize adm files
[modules/kernel.git] / src / LifeCycleCORBA / Test_LifeCycleCORBA.cxx
1 // Copyright (C) 2007-2014  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 "SALOME_NamingService.hxx"
37 #include "SALOME_LifeCycleCORBA.hxx"
38 #include "SALOME_FileTransferCORBA.hxx"
39 #include "utilities.h"
40 #include <Basics_Utils.hxx>
41
42 int main (int argc, char * argv[])
43 {
44
45   try
46     {
47       // --- Initialize omniORB
48
49       CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
50     
51       // --- Obtain a reference to the root POA
52
53       CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
54       PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
55
56       // --- Naming Service and LifeCycleCORBA interfaces
57     
58       SALOME_NamingService _NS(orb) ;
59       SALOME_LifeCycleCORBA _LCC(&_NS) ;
60
61       // --- get a local container,
62       //     load an engine, and invoque methods on that engine
63
64       std::string containerName = "myServer";
65       MESSAGE("FindOrLoadComponent " + containerName + "/" + "SalomeTestComponent" );
66
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));
75
76       // --- get another container,
77       //     load an engine, and invoque methods on that engine
78
79       std::string containerName2 = "otherServer";
80
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));
90
91       // --- get a third container,
92       //     load an engine, and invoque methods on that engine
93
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;
100
101       // --- yet another container, with hostname,
102       //     load an engine, and invoque methods on that engine
103
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;
112
113       // --- try a local file transfer
114
115       std::string origFileName = "/home/prascle/petitfichier";
116       SALOME_FileTransferCORBA transfer( Kernel_Utils::GetHostname(),
117                                          origFileName);
118       std::string local = transfer.getLocalFile();
119       SCRUTE(local);
120
121       // --- try a file transfer from another computer
122
123       origFileName = "/home/prascle/occ60.tgz";
124       SALOME_FileTransferCORBA transfer2( "cli76ce",
125                                          origFileName);
126       local = transfer2.getLocalFile();
127       SCRUTE(local);
128       local = transfer2.getLocalFile();
129       SCRUTE(local);
130
131     }
132   catch(CORBA::SystemException& ex)
133     {
134       INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.");
135     }
136   catch(CORBA::Exception&)
137     {
138       INFOS("Caught CORBA::Exception.");
139     }
140   catch(...)
141     {
142       INFOS("Caught unknown exception.");
143     }
144
145   return 0;
146 }