1 // SALOME Container : implementation of container and engine for Kernel
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 : SALOME_Container.cxx
25 // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
33 # include "Utils_ORB_INIT.hxx"
34 # include "Utils_SINGLETON.hxx"
35 #include "SALOME_NamingService.hxx"
36 #include "SALOME_Container_i.hxx"
39 #include "utilities.h"
43 #include <Utils_Timer.hxx>
48 static PyMethodDef MethodPyVoidMethod[] = {
52 int main(int argc, char* argv[])
58 PySys_SetArgv( argc , argv ) ;
59 Py_InitModule( "InitPyRunMethod" , MethodPyVoidMethod ) ;
63 // Initialise the ORB.
64 // CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
65 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
66 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
67 CORBA::ORB_var &orb = init( argc , argv ) ;
69 // Obtain a reference to the root POA.
70 // obtain the root poa manager
72 long TIMESleep = 250000000;
73 int NumberOfTries = 40;
76 ts_req.tv_nsec=TIMESleep;
81 CosNaming::NamingContext_var inc;
82 PortableServer::POA_var root_poa;
83 CORBA::Object_var theObj;
84 CORBA::Object_var obj;
85 CORBA::Object_var object;
86 SALOME_Logger::Logger_var log;
87 SALOME_NamingService &naming = *SINGLETON_<SALOME_NamingService>::Instance() ;
89 const char * Env = getenv("USE_LOGGER");
91 if ((Env!=NULL) && (strlen(Env)))
96 name[0].id=CORBA::string_dup("Logger");
97 PortableServer::POAManager_var pman;
98 for (int i = 1; i<=NumberOfTries; i++){
100 a=nanosleep(&ts_req,&ts_rem);
102 obj = orb->resolve_initial_references("RootPOA");
103 if(!CORBA::is_nil(obj))
104 root_poa = PortableServer::POA::_narrow(obj);
105 if(!CORBA::is_nil(root_poa))
106 pman = root_poa->the_POAManager();
107 if(!CORBA::is_nil(orb))
108 theObj = orb->resolve_initial_references("NameService");
109 if (!CORBA::is_nil(theObj))
110 inc = CosNaming::NamingContext::_narrow(theObj);
112 catch( CORBA::COMM_FAILURE& )
114 MESSAGE( "Container: CORBA::COMM_FAILURE: Unable to contact the Naming Service" )
116 if(!CORBA::is_nil(inc)) {
117 MESSAGE( "Container: Naming Service was found" )
119 for(int j=1; j<=NumberOfTries; j++){
121 a=nanosleep(&ts_req, &ts_rem);
123 object = inc->resolve(name);
125 catch(CosNaming::NamingContext::NotFound){ MESSAGE( "Container: Logger Server wasn't found" ) }
126 catch(...){ MESSAGE( "Container: Unknown exception" ) }
127 if (!CORBA::is_nil(object))
128 log = SALOME_Logger::Logger::_narrow(object);
129 if (!CORBA::is_nil(log)){
130 MESSAGE( "Container: Logger Server was found" )
137 if ((CONTAINER==1)||((EnvL==0)&&(!CORBA::is_nil(inc))))
142 // define policy objects
143 PortableServer::ImplicitActivationPolicy_var implicitActivation =
144 root_poa->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION) ;
146 // default = NO_IMPLICIT_ACTIVATION
147 PortableServer::ThreadPolicy_var threadPolicy =
148 root_poa->create_thread_policy(PortableServer::ORB_CTRL_MODEL) ;
149 // default = ORB_CTRL_MODEL, other choice SINGLE_THREAD_MODEL
151 // create policy list
152 CORBA::PolicyList policyList;
153 policyList.length(2);
154 policyList[0] = PortableServer::ImplicitActivationPolicy::_duplicate(implicitActivation) ;
155 policyList[1] = PortableServer::ThreadPolicy::_duplicate(threadPolicy) ;
157 // create the child POA
158 PortableServer::POAManager_var nil_mgr = PortableServer::POAManager::_nil() ;
159 PortableServer::POA_var factory_poa =
160 root_poa->create_POA("factory_poa", pman, policyList) ;
161 //with nil_mgr instead of pman, a new POA manager is created with the new POA
163 // destroy policy objects
164 implicitActivation->destroy() ;
165 threadPolicy->destroy() ;
167 char *containerName = "";
170 containerName = argv[1] ;
173 Engines_Container_i * myContainer
174 = new Engines_Container_i(orb, factory_poa, containerName , argc , argv );
176 // Engines_Container_i * myContainer
177 // = new Engines_Container_i(string(argv[1]),string(argv[2]), orb, factory_poa);
179 // use naming service
180 // myContainer->_NS.init_orb(orb);
181 // Engines::Container_ptr pCont = Engines::Container::_narrow(myContainer->_this());
182 // myContainer->_NS.Register(pCont, argv[2]);
190 MESSAGE("SALOME_Registry_Server.cxx - orb->run()");
191 timer.ShowAbsolute();
197 catch(CORBA::SystemException&)
199 INFOS("Caught CORBA::SystemException.")
201 catch(PortableServer::POA::WrongPolicy&)
203 INFOS("Caught CORBA::WrongPolicyException.")
205 catch(PortableServer::POA::ServantAlreadyActive&)
207 INFOS("Caught CORBA::ServantAlreadyActiveException")
209 catch(CORBA::Exception&)
211 INFOS("Caught CORBA::Exception.")
215 INFOS("Caught unknown exception.")