Salome HOME
8e7ffe1bc930e52158c2c39a87c4c7f857e9de38
[modules/kernel.git] / src / TestContainer / TestContainer.cxx
1 //  SALOME TestContainer : test of container creation and its life cycle
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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : TestContainer.cxx
25 //  Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
26 //  Module : SALOME
27 //  $Header$
28
29 using namespace std;
30 #include "utilities.h"
31 #include <iostream>
32 #include <unistd.h>
33 #include <SALOMEconfig.h>
34 #include CORBA_CLIENT_HEADER(SALOME_Component)
35 #include CORBA_CLIENT_HEADER(SALOME_TestComponent)
36
37 #include "SALOME_NamingService.hxx"
38 #include "OpUtil.hxx"
39
40 int main (int argc, char * argv[])
41 {
42
43   try
44     {
45       // Initializing omniORB
46       CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
47     
48       // use IOR to find container
49       //if (argc != 2) { return 1; }
50       //CORBA::Object_var obj = orb->string_to_object(argv[1]);
51       //Engines::Container_var iGenFact = Engines::Container::_narrow(obj);
52
53       // Obtain a reference to the root POA
54       CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
55       PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
56     
57       // Use Name Service to find container
58       SALOME_NamingService _NS(orb) ;
59       string containerName = "/Containers/" ;
60       string hostName = GetHostname();
61       containerName += hostName + "/FactoryServer";
62
63       obj = _NS.Resolve(containerName.c_str()) ;
64       Engines::Container_var iGenFact = Engines::Container::_narrow(obj);
65
66       Engines::TestComponent_var m1;
67     
68       for (int iter = 0; iter < 3 ; iter++)
69         {
70           INFOS("----------------------------------------------------" << iter);   
71           string dirn = getenv("SALOME_ROOT_DIR");
72           dirn += "/lib/libSalomeTestComponentEngine.so";
73           obj = iGenFact->load_impl("SalomeTestComponent",dirn.c_str());
74           m1 = Engines::TestComponent::_narrow(obj);
75           INFOS("recup m1");
76           SCRUTE(m1->instanceName());
77           INFOS("Coucou " << m1->Coucou(1L));
78           iGenFact->remove_impl(m1) ;
79           //iGenFact->finalize_removal() ; // unpredictable results ...
80           sleep(5);
81         }    
82       // Clean-up.
83       iGenFact->finalize_removal() ;
84       orb->destroy();
85     }
86   catch(CORBA::COMM_FAILURE& ex) {
87     INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.")
88       }
89   catch(CORBA::SystemException&) {
90     INFOS("Caught a CORBA::SystemException.")
91       }
92   catch(CORBA::Exception&) {
93     INFOS("Caught CORBA::Exception.")
94       }
95   catch(...) {
96     INFOS("Caught unknown exception.")
97       }
98
99   return 0;
100 }
101