Salome HOME
Removed CASCatch
[modules/kernel.git] / src / LifeCycleCORBA / Test_LifeCycleCORBA.cxx
1 //  SALOME LifeCycleCORBA : implementation of containers and engines life cycle both in Python and C++
2 //
3 //  Copyright (C) 2003  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 //
23 //
24 //  File   : TestLifeCycleCORBA.cxx
25 //  Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
26 //  Module : SALOME
27 //  $Header$
28
29 #include <iostream>
30 #ifndef WNT
31 #include <unistd.h>
32 #endif
33 #include <SALOMEconfig.h>
34 #ifndef WNT
35 #include CORBA_CLIENT_HEADER(SALOME_Component)
36 #include CORBA_CLIENT_HEADER(SALOME_TestComponent)
37 #else
38 #include <SALOME_Component.hh>
39 #include <SALOME_TestComponent.hh>
40 #endif
41 #include "SALOME_NamingService.hxx"
42 #include "SALOME_LifeCycleCORBA.hxx"
43 #include "SALOME_FileTransferCORBA.hxx"
44 #include "utilities.h"
45 #include <OpUtil.hxx>
46
47 using namespace std;
48
49 int main (int argc, char * argv[])
50 {
51
52   try
53     {
54       // --- Initialize omniORB
55
56       CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
57     
58       // --- Obtain a reference to the root POA
59
60       CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
61       PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
62
63       // --- Naming Service and LifeCycleCORBA interfaces
64     
65       SALOME_NamingService _NS(orb) ;
66       SALOME_LifeCycleCORBA _LCC(&_NS) ;
67
68       // --- get a local container,
69       //     load an engine, and invoque methods on that engine
70
71       string containerName = "myServer";
72       MESSAGE("FindOrLoadComponent " + containerName + "/" + "SalomeTestComponent" );
73
74       Engines::Component_var mycompo =
75         _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
76       ASSERT(!CORBA::is_nil(mycompo));
77       Engines::TestComponent_var m1;
78       m1 = Engines::TestComponent::_narrow(mycompo);
79       ASSERT(!CORBA::is_nil(m1));
80       SCRUTE(m1->instanceName());
81       MESSAGE("Coucou " << m1->Coucou(1L));
82
83       // --- get another container,
84       //     load an engine, and invoque methods on that engine
85
86       string containerName2 = "otherServer";
87
88       Engines::Component_var mycompo2 =
89         _LCC.FindOrLoad_Component(containerName2.c_str(),"SALOME_TestComponentPy");
90       ASSERT(!CORBA::is_nil(mycompo2));
91       Engines::TestComponent_var m2;
92       m2 = Engines::TestComponent::_narrow(mycompo2);
93       ASSERT(!CORBA::is_nil(m2));
94       SCRUTE(m2->instanceName());
95       cout << m2->instanceName() << endl;
96       MESSAGE("Coucou " << m2->Coucou(1L));
97
98       // --- get a third container,
99       //     load an engine, and invoque methods on that engine
100
101       Engines::Component_var mycompo3 =
102         _LCC.FindOrLoad_Component("totoPy","SALOME_TestComponentPy");
103       ASSERT(!CORBA::is_nil(mycompo3));
104       Engines::TestComponent_var m3 = Engines::TestComponent::_narrow(mycompo3);
105       ASSERT(!CORBA::is_nil(m3));
106       cout << m3->instanceName() << endl;
107
108       // --- yet another container, with hostname,
109       //     load an engine, and invoque methods on that engine
110
111       string containerName4 = GetHostname();
112       containerName4  += "/titiPy";
113       Engines::Component_var mycompo4 = 
114         _LCC.FindOrLoad_Component(containerName4.c_str(),"SALOME_TestComponentPy");
115       ASSERT(!CORBA::is_nil(mycompo4));
116       Engines::TestComponent_var m4 = Engines::TestComponent::_narrow(mycompo4);
117       ASSERT(!CORBA::is_nil(m4));
118       cout << m4->instanceName() << endl;
119
120       // --- try a local file transfer
121
122       string origFileName = "/home/prascle/petitfichier";
123       SALOME_FileTransferCORBA transfer( GetHostname(),
124                                          origFileName);
125       string local = transfer.getLocalFile();
126       SCRUTE(local);
127
128       // --- try a file transfer from another computer
129
130       origFileName = "/home/prascle/occ60.tgz";
131       SALOME_FileTransferCORBA transfer2( "cli76ce",
132                                          origFileName);
133       local = transfer2.getLocalFile();
134       SCRUTE(local);
135       local = transfer2.getLocalFile();
136       SCRUTE(local);
137
138     }
139   catch(CORBA::SystemException& ex)
140     {
141       INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.");
142     }
143 #ifndef WNT
144   catch(CORBA::SystemException&)
145     {
146       INFOS("Caught a CORBA::SystemException.");
147     }
148 #endif
149   catch(CORBA::Exception&)
150     {
151       INFOS("Caught CORBA::Exception.");
152     }
153   catch(...)
154     {
155       INFOS("Caught unknown exception.");
156     }
157
158   return 0;
159 }
160