Back to index

salome-kernel  6.5.0
Test_LifeCycleCORBA.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME LifeCycleCORBA : implementation of containers and engines life cycle both in Python and C++
00024 //  File   : TestLifeCycleCORBA.cxx
00025 //  Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
00026 //  Module : SALOME
00027 //  $Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/LifeCycleCORBA/Test_LifeCycleCORBA.cxx,v 1.7.2.1.10.3.12.1 2012-04-12 14:05:16 vsr Exp $
00028 //
00029 #include <iostream>
00030 #ifndef WIN32
00031 #include <unistd.h>
00032 #endif
00033 #include <SALOMEconfig.h>
00034 #include CORBA_CLIENT_HEADER(SALOME_Component)
00035 #include CORBA_CLIENT_HEADER(SALOME_TestComponent)
00036 #include "SALOME_NamingService.hxx"
00037 #include "SALOME_LifeCycleCORBA.hxx"
00038 #include "SALOME_FileTransferCORBA.hxx"
00039 #include "utilities.h"
00040 #include <Basics_Utils.hxx>
00041 
00042 int main (int argc, char * argv[])
00043 {
00044 
00045   try
00046     {
00047       // --- Initialize omniORB
00048 
00049       CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
00050     
00051       // --- Obtain a reference to the root POA
00052 
00053       CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
00054       PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
00055 
00056       // --- Naming Service and LifeCycleCORBA interfaces
00057     
00058       SALOME_NamingService _NS(orb) ;
00059       SALOME_LifeCycleCORBA _LCC(&_NS) ;
00060 
00061       // --- get a local container,
00062       //     load an engine, and invoque methods on that engine
00063 
00064       std::string containerName = "myServer";
00065       MESSAGE("FindOrLoadComponent " + containerName + "/" + "SalomeTestComponent" );
00066 
00067       Engines::EngineComponent_var mycompo =
00068         _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
00069       ASSERT(!CORBA::is_nil(mycompo));
00070       Engines::TestComponent_var m1;
00071       m1 = Engines::TestComponent::_narrow(mycompo);
00072       ASSERT(!CORBA::is_nil(m1));
00073       SCRUTE(m1->instanceName());
00074       MESSAGE("Coucou " << m1->Coucou(1L));
00075 
00076       // --- get another container,
00077       //     load an engine, and invoque methods on that engine
00078 
00079       std::string containerName2 = "otherServer";
00080 
00081       Engines::EngineComponent_var mycompo2 =
00082         _LCC.FindOrLoad_Component(containerName2.c_str(),"SALOME_TestComponentPy");
00083       ASSERT(!CORBA::is_nil(mycompo2));
00084       Engines::TestComponent_var m2;
00085       m2 = Engines::TestComponent::_narrow(mycompo2);
00086       ASSERT(!CORBA::is_nil(m2));
00087       SCRUTE(m2->instanceName());
00088       std::cout << m2->instanceName() << std::endl;
00089       MESSAGE("Coucou " << m2->Coucou(1L));
00090 
00091       // --- get a third container,
00092       //     load an engine, and invoque methods on that engine
00093 
00094       Engines::EngineComponent_var mycompo3 =
00095         _LCC.FindOrLoad_Component("totoPy","SALOME_TestComponentPy");
00096       ASSERT(!CORBA::is_nil(mycompo3));
00097       Engines::TestComponent_var m3 = Engines::TestComponent::_narrow(mycompo3);
00098       ASSERT(!CORBA::is_nil(m3));
00099       std::cout << m3->instanceName() << std::endl;
00100 
00101       // --- yet another container, with hostname,
00102       //     load an engine, and invoque methods on that engine
00103 
00104       std::string containerName4 = Kernel_Utils::GetHostname();
00105       containerName4  += "/titiPy";
00106       Engines::EngineComponent_var mycompo4 = 
00107         _LCC.FindOrLoad_Component(containerName4.c_str(),"SALOME_TestComponentPy");
00108       ASSERT(!CORBA::is_nil(mycompo4));
00109       Engines::TestComponent_var m4 = Engines::TestComponent::_narrow(mycompo4);
00110       ASSERT(!CORBA::is_nil(m4));
00111       std::cout << m4->instanceName() << std::endl;
00112 
00113       // --- try a local file transfer
00114 
00115       std::string origFileName = "/home/prascle/petitfichier";
00116       SALOME_FileTransferCORBA transfer( Kernel_Utils::GetHostname(),
00117                                          origFileName);
00118       std::string local = transfer.getLocalFile();
00119       SCRUTE(local);
00120 
00121       // --- try a file transfer from another computer
00122 
00123       origFileName = "/home/prascle/occ60.tgz";
00124       SALOME_FileTransferCORBA transfer2( "cli76ce",
00125                                          origFileName);
00126       local = transfer2.getLocalFile();
00127       SCRUTE(local);
00128       local = transfer2.getLocalFile();
00129       SCRUTE(local);
00130 
00131     }
00132   catch(CORBA::SystemException& ex)
00133     {
00134       INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.");
00135     }
00136   catch(CORBA::Exception&)
00137     {
00138       INFOS("Caught CORBA::Exception.");
00139     }
00140   catch(...)
00141     {
00142       INFOS("Caught unknown exception.");
00143     }
00144 
00145   return 0;
00146 }