1 // Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SALOME SALOMEDS : data structure of SALOME and sources of Salome data server
24 // File : SALOMEDS_Server.cxx
25 // Author : Yves FRICAUD
29 #include "utilities.h"
30 #include "Utils_SINGLETON.hxx"
32 #include "SALOME_NamingService.hxx"
33 #include "SALOMEDS_Study_i.hxx"
35 #include <SALOMEconfig.h>
36 #include CORBA_SERVER_HEADER(SALOMEDS)
39 #include <Utils_Timer.hxx>
43 // { // for ccmalloc memory debug
44 // void ccmalloc_static_initialization(void);
47 ///////////////////////////// MAIN ///////////////////////////////////////
48 //////////////////////////////////////////////////////////////////////////
49 int main(int argc, char** argv)
51 // ccmalloc_static_initialization();
53 MESSAGE("SALOMEDS_Server - main");
56 // Initialise the ORB.
57 #if OMNIORB_VERSION >= 4
58 CORBA::ORB_var orb = CORBA::ORB_init( argc, argv, "omniORB4" ) ;
60 CORBA::ORB_var orb = CORBA::ORB_init( argc, argv, "omniORB3" );
62 SALOME_NamingService* NS = 0;
63 // Obtain a reference to the root POA.
64 long TIMESleep = 500000000;
65 int NumberOfTries = 40;
68 ts_req.tv_nsec=TIMESleep;
73 CosNaming::NamingContext_var inc;
74 PortableServer::POA_var defaultPoa;
75 PortableServer::POA_var poa;
76 CORBA::Object_var theObj;
77 CORBA::Object_var obj;
78 CORBA::Object_var object;
80 const char * Env = getenv("USE_LOGGER");
82 if ((Env!=NULL) && (strlen(Env)))
86 name[0].id=CORBA::string_dup("Logger");
87 PortableServer::POAManager_var pman;
88 for (int i = 1; i<=NumberOfTries; i++)
92 a=nanosleep(&ts_req,&ts_rem);
94 Sleep(TIMESleep/1000000);
98 obj = orb->resolve_initial_references("RootPOA");
99 if(!CORBA::is_nil(obj))
100 defaultPoa = PortableServer::POA::_narrow(obj);
101 if(!CORBA::is_nil(defaultPoa))
102 pman = defaultPoa->the_POAManager();
104 PortableServer::POAManager_var pman = defaultPoa->the_POAManager();
105 CORBA::PolicyList policies;
107 //PortableServer::ThreadPolicy_var threadPol(defaultPoa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL));
108 PortableServer::ThreadPolicy_var threadPol(defaultPoa->create_thread_policy(PortableServer::ORB_CTRL_MODEL)); // default for all POAs
109 PortableServer::ImplicitActivationPolicy_var implicitPol(defaultPoa->create_implicit_activation_policy(PortableServer::IMPLICIT_ACTIVATION)); // default for Root_POA, NO for others
110 policies[0] = PortableServer::ThreadPolicy::_duplicate(threadPol);
111 policies[1] = PortableServer::ImplicitActivationPolicy::_duplicate(implicitPol);
112 poa = defaultPoa->create_POA("KERNELStandaloneStudySingleThreadPOA",pman,policies);
113 threadPol->destroy();
114 SALOMEDS_Study_i::SetThePOA(poa);
116 if(!CORBA::is_nil(orb))
117 theObj = orb->resolve_initial_references("NameService");
118 if (!CORBA::is_nil(theObj)){
119 inc = CosNaming::NamingContext::_narrow(theObj);
120 if(!CORBA::is_nil(inc))
122 MESSAGE( "SalomeDS Server: Naming Service was found" );
125 CORBA::ORB_var orb1 = CORBA::ORB_init(argc,argv) ;
126 NS = SINGLETON_<SALOME_NamingService>::Instance() ;
127 NS->init_orb( orb1 ) ;
128 for(int j=1; j<=NumberOfTries; j++)
132 a=nanosleep(&ts_req, &ts_rem);
134 Sleep(TIMESleep/1000000);
138 object = inc->resolve(name);
140 catch(CosNaming::NamingContext::NotFound)
142 MESSAGE( "SalomeDS Server: Logger Server wasn't found" ); }
146 MESSAGE( "SalomeDS Server: Unknown exception" );
148 if (!CORBA::is_nil(object))
150 MESSAGE( "SalomeDS Server: Logger Server was found" );
160 catch( const SALOME_Exception &ex )
162 MESSAGE( "Communication Error : " << ex.what() );
163 return EXIT_FAILURE ;
165 if ((SALOMEDS==1)||((EnvL==0)&&(!CORBA::is_nil(inc))))
169 // We allocate the objects on the heap. Since these are reference
170 // counted objects, they will be deleted by the POA when they are no
172 SALOMEDS_Study_i * myStudy_i = new SALOMEDS_Study_i(orb);
174 // Activate the objects. This tells the POA that the objects are
175 // ready to accept requests.
176 PortableServer::ObjectId_var myStudy_iid = poa->activate_object(myStudy_i);
177 SALOMEDS::Study_var Study = myStudy_i->_this();
180 NS = SINGLETON_<SALOME_NamingService>::Instance();
183 NS->Register(Study, "/Study");
184 myStudy_i->_remove_ref();
186 // Obtain a POAManager, and tell the POA to start accepting
187 // requests on its objects.
188 pman = poa->the_POAManager();
195 MESSAGE("SALOME_Registry_Server.cxx - orb->run()");
196 timer.ShowAbsolute();
199 MESSAGE( "end of SALOME_DS server" );
200 NS->Destroy_Name("/Study");
203 catch(CORBA::SystemException&)
205 MESSAGE( "Caught CORBA::SystemException." );
207 catch(CORBA::Exception&)
209 MESSAGE( "Caught CORBA::Exception." );
211 catch(omniORB::fatalException& fe)
213 MESSAGE( "Caught omniORB::fatalException:" );
214 MESSAGE( " file: " << fe.file() );
215 MESSAGE( " line: " << fe.line() );
216 MESSAGE( " mesg: " << fe.errmsg() );
220 MESSAGE( "Caught unknown exception." );