Salome HOME
Initialisation de la base KERNEL avec la version operationnelle de KERNEL_SRC issue...
[modules/kernel.git] / src / TestContainer / TestContainer.cxx
1 using namespace std;
2 //=============================================================================
3 // File      : TestContainer.cxx
4 // Created   : jeu jui 12 13:11:27 CEST 2001
5 // Author    : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
6 // Project   : SALOME
7 // Copyright : EDF 2001
8 // $Header$
9 //=============================================================================
10
11 #include "utilities.h"
12 #include <iostream>
13 #include <unistd.h>
14 #include <SALOMEconfig.h>
15 #include CORBA_CLIENT_HEADER(SALOME_Component)
16 #include CORBA_CLIENT_HEADER(SALOME_TestComponent)
17
18 #include "SALOME_NamingService.hxx"
19 #include "OpUtil.hxx"
20
21 int main (int argc, char * argv[])
22 {
23
24   try
25     {
26       // Initializing omniORB
27       CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
28     
29       // use IOR to find container
30       //if (argc != 2) { return 1; }
31       //CORBA::Object_var obj = orb->string_to_object(argv[1]);
32       //Engines::Container_var iGenFact = Engines::Container::_narrow(obj);
33
34       // Obtain a reference to the root POA
35       CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
36       PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
37     
38       // Use Name Service to find container
39       SALOME_NamingService _NS(orb) ;
40       string containerName = "/Containers/" ;
41       string hostName = GetHostname();
42       containerName += hostName;
43
44       obj = _NS.Resolve(containerName.c_str()) ;
45       Engines::Container_var iGenFact = Engines::Container::_narrow(obj);
46
47       Engines::TestComponent_var m1;
48     
49       for (int iter = 0; iter < 3 ; iter++)
50         {
51           MESSAGE("----------------------------------------------------" << iter);   
52     
53           obj = iGenFact->load_impl("SalomeTestComponent",
54                                     "../lib/libSalomeTestComponentEngine.so");
55           m1 = Engines::TestComponent::_narrow(obj);
56           MESSAGE("recup m1");
57           SCRUTE(m1->instanceName());
58           MESSAGE("Coucou " << m1->Coucou(1L));
59           iGenFact->remove_impl(m1) ;
60           //iGenFact->finalize_removal() ; // unpredictable results ...
61           sleep(5);
62         }    
63       // Clean-up.
64       iGenFact->finalize_removal() ;
65       orb->destroy();
66     }
67   catch(CORBA::COMM_FAILURE& ex) {
68     INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.")
69       }
70   catch(CORBA::SystemException&) {
71     INFOS("Caught a CORBA::SystemException.")
72       }
73   catch(CORBA::Exception&) {
74     INFOS("Caught CORBA::Exception.")
75       }
76   catch(...) {
77     INFOS("Caught unknown exception.")
78       }
79
80   return 0;
81 }
82