1 // SALOME TestContainer : test of container creation and its life cycle
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : TestContainer.cxx
25 // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
30 #include "utilities.h"
33 #include <SALOMEconfig.h>
34 #include CORBA_CLIENT_HEADER(SALOME_Component)
35 #include CORBA_CLIENT_HEADER(SALOME_TestComponent)
37 #include "SALOME_NamingService.hxx"
39 # include "Utils_ORB_INIT.hxx"
40 # include "Utils_SINGLETON.hxx"
41 # include "Utils_SALOME_Exception.hxx"
42 # include "Utils_CommException.hxx"
43 int main (int argc, char * argv[])
48 // Initializing omniORB
49 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
51 // use IOR to find container
52 //if (argc != 2) { return 1; }
53 //CORBA::Object_var obj = orb->string_to_object(argv[1]);
54 //Engines::Container_var iGenFact = Engines::Container::_narrow(obj);
56 // Obtain a reference to the root POA
58 long TIMESleep = 250000000;
59 int NumberOfTries = 40;
62 ts_req.tv_nsec=TIMESleep;
67 CosNaming::NamingContext_var inc;
68 PortableServer::POA_var poa;
69 CORBA::Object_var theObj;
70 CORBA::Object_var obj;
71 CORBA::Object_var object;
72 SALOME_Logger::Logger_var log;
73 SALOME_NamingService &naming = *SINGLETON_<SALOME_NamingService>::Instance() ;
75 const char * Env = getenv("USE_LOGGER");
77 if ((Env!=NULL) && (strlen(Env)))
81 name[0].id=CORBA::string_dup("Logger");
82 PortableServer::POAManager_var manager;
83 for (int i = 1; i<=NumberOfTries; i++){
85 a=nanosleep(&ts_req,&ts_rem);
87 obj = orb->resolve_initial_references("RootPOA");
88 if(!CORBA::is_nil(obj))
89 poa = PortableServer::POA::_narrow(obj);
90 if(!CORBA::is_nil(poa))
91 manager = poa->the_POAManager();
92 if(!CORBA::is_nil(orb))
93 theObj = orb->resolve_initial_references("NameService");
94 if (!CORBA::is_nil(theObj))
95 inc = CosNaming::NamingContext::_narrow(theObj);
97 catch( CORBA::COMM_FAILURE& )
99 MESSAGE( "Test Container: CORBA::COMM_FAILURE: Unable to contact the Naming Service" )
101 if(!CORBA::is_nil(inc)) {
102 MESSAGE( "Test Container: Naming Service was found" )
104 for(int j=1; j<=NumberOfTries; j++){
106 a=nanosleep(&ts_req, &ts_rem);
108 object = inc->resolve(name);
110 catch(CosNaming::NamingContext::NotFound){ MESSAGE( "Test Container: Logger Server wasn't found" ) }
111 catch(...){ MESSAGE( "Test Container: Unknown exception" ) }
112 if (!CORBA::is_nil(object))
113 log = SALOME_Logger::Logger::_narrow(object);
114 if (!CORBA::is_nil(log)){
115 MESSAGE( "Test Container: Loger Server was found" )
122 if ((TEST_CONTAINER==1)||((EnvL==0)&&(!CORBA::is_nil(inc))))
126 // Use Name Service to find container
127 SALOME_NamingService _NS(orb) ;
128 string containerName = "/Containers/" ;
129 string hostName = GetHostname();
130 containerName += hostName + "/FactoryServer";
132 obj = _NS.Resolve(containerName.c_str()) ;
133 Engines::Container_var iGenFact = Engines::Container::_narrow(obj);
135 Engines::TestComponent_var m1;
137 for (int iter = 0; iter < 3 ; iter++)
139 INFOS("----------------------------------------------------" << iter);
140 string dirn = getenv("SALOME_ROOT_DIR");
141 dirn += "/lib/salome/libSalomeTestComponentEngine.so";
142 obj = iGenFact->load_impl("SalomeTestComponent",dirn.c_str());
143 m1 = Engines::TestComponent::_narrow(obj);
145 SCRUTE(m1->instanceName());
146 INFOS("Coucou " << m1->Coucou(1L));
147 iGenFact->remove_impl(m1) ;
148 //iGenFact->finalize_removal() ; // unpredictable results ...
152 iGenFact->finalize_removal() ;
155 catch(CORBA::COMM_FAILURE& ex) {
156 INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.")
158 catch(CORBA::SystemException&) {
159 INFOS("Caught a CORBA::SystemException.")
161 catch(CORBA::Exception&) {
162 INFOS("Caught CORBA::Exception.")
165 INFOS("Caught unknown exception.")