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
29 #include "utilities.h"
32 #include <SALOMEconfig.h>
33 #include CORBA_CLIENT_HEADER(SALOME_Component)
34 #include CORBA_CLIENT_HEADER(SALOME_TestComponent)
36 #include "SALOME_NamingService.hxx"
38 #include "Utils_ORB_INIT.hxx"
39 #include "Utils_SINGLETON.hxx"
40 #include "Utils_SALOME_Exception.hxx"
41 #include "Utils_CommException.hxx"
44 int main (int argc, char * argv[])
49 // Initializing omniORB
50 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
52 // use IOR to find container
53 //if (argc != 2) { return 1; }
54 //CORBA::Object_var obj = orb->string_to_object(argv[1]);
55 //Engines::Container_var iGenFact = Engines::Container::_narrow(obj);
57 // Obtain a reference to the root POA
59 long TIMESleep = 250000000;
60 int NumberOfTries = 40;
63 ts_req.tv_nsec=TIMESleep;
68 CosNaming::NamingContext_var inc;
69 PortableServer::POA_var poa;
70 CORBA::Object_var theObj;
71 CORBA::Object_var obj;
72 CORBA::Object_var object;
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++)
86 a=nanosleep(&ts_req,&ts_rem);
89 obj = orb->resolve_initial_references("RootPOA");
90 if(!CORBA::is_nil(obj))
91 poa = PortableServer::POA::_narrow(obj);
92 if(!CORBA::is_nil(poa))
93 manager = poa->the_POAManager();
94 if(!CORBA::is_nil(orb))
95 theObj = orb->resolve_initial_references("NameService");
96 if (!CORBA::is_nil(theObj))
97 inc = CosNaming::NamingContext::_narrow(theObj);
99 catch( CORBA::COMM_FAILURE& )
101 MESSAGE( "Test Container: CORBA::COMM_FAILURE: Unable to contact the Naming Service" )
103 if(!CORBA::is_nil(inc))
105 MESSAGE( "Test Container: Naming Service was found" )
108 for(int j=1; j<=NumberOfTries; j++)
111 a=nanosleep(&ts_req, &ts_rem);
114 object = inc->resolve(name);
116 catch(CosNaming::NamingContext::NotFound)
118 MESSAGE( "Test Container: Logger Server wasn't found" );
122 MESSAGE( "Test Container: Unknown exception" );
124 if (!CORBA::is_nil(object))
126 MESSAGE( "Test Container: Loger Server was found" );
133 if ((TEST_CONTAINER==1)||((EnvL==0)&&(!CORBA::is_nil(inc))))
137 // Use Name Service to find container
138 SALOME_NamingService _NS(orb) ;
139 string containerName = "/Containers/" ;
140 string hostName = GetHostname();
141 containerName += hostName + "/FactoryServer";
143 obj = _NS.Resolve(containerName.c_str()) ;
144 Engines::Container_var iGenFact = Engines::Container::_narrow(obj);
146 Engines::TestComponent_var m1;
148 for (int iter = 0; iter < 3 ; iter++)
150 INFOS("----------------------------------------------------" << iter);
151 string dirn = getenv("SALOME_ROOT_DIR");
152 dirn += "/lib/salome/libSalomeTestComponentEngine.so";
153 obj = iGenFact->load_impl("SalomeTestComponent",dirn.c_str());
154 m1 = Engines::TestComponent::_narrow(obj);
156 SCRUTE(m1->instanceName());
157 INFOS("Coucou " << m1->Coucou(1L));
158 iGenFact->remove_impl(m1) ;
159 //iGenFact->finalize_removal() ; // unpredictable results ...
163 iGenFact->finalize_removal() ;
166 catch(CORBA::COMM_FAILURE& ex) {
167 INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.")
169 catch(CORBA::SystemException&) {
170 INFOS("Caught a CORBA::SystemException.")
172 catch(CORBA::Exception&) {
173 INFOS("Caught CORBA::Exception.")
176 INFOS("Caught unknown exception.")