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