1 // Copyright (C) 2007-2021 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 "ArgvKeeper.hxx"
31 #include "utilities.h"
32 #include "Utils_SINGLETON.hxx"
34 #include "SALOME_NamingService.hxx"
35 #include "SALOMEDS_Study_i.hxx"
37 #include <SALOMEconfig.h>
38 #include CORBA_SERVER_HEADER(SALOMEDS)
41 #include <Utils_Timer.hxx>
45 // { // for ccmalloc memory debug
46 // void ccmalloc_static_initialization(void);
49 ///////////////////////////// MAIN ///////////////////////////////////////
50 //////////////////////////////////////////////////////////////////////////
51 int main(int argc, char** argv)
53 // ccmalloc_static_initialization();
55 MESSAGE("SALOMEDS_Server - main");
58 // Initialise the ORB.
59 SetArgcArgv(argc, argv);
60 CORBA::ORB_var orb = KERNEL::GetRefToORB() ;
61 SALOME_NamingService* NS = 0;
62 // Obtain a reference to the root POA.
63 long TIMESleep = 500000000;
64 int NumberOfTries = 40;
66 ts_req.tv_nsec=TIMESleep;
71 CosNaming::NamingContext_var inc;
72 PortableServer::POA_var defaultPoa;
73 PortableServer::POA_var poa;
74 CORBA::Object_var theObj;
75 CORBA::Object_var obj;
76 CORBA::Object_var object;
78 const char * Env = getenv("USE_LOGGER");
80 if ((Env!=NULL) && (strlen(Env)))
84 name[0].id=CORBA::string_dup("Logger");
85 PortableServer::POAManager_var pman;
86 for (int i = 1; i<=NumberOfTries; i++)
90 nanosleep(&ts_req,&ts_rem);
92 Sleep(TIMESleep/1000000);
96 obj = orb->resolve_initial_references("RootPOA");
97 if(!CORBA::is_nil(obj))
98 defaultPoa = PortableServer::POA::_narrow(obj);
99 if(!CORBA::is_nil(defaultPoa))
100 pman = defaultPoa->the_POAManager();
102 PortableServer::POAManager_var pman = defaultPoa->the_POAManager();
103 CORBA::PolicyList policies;
105 //PortableServer::ThreadPolicy_var threadPol(defaultPoa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL));
106 PortableServer::ThreadPolicy_var threadPol(defaultPoa->create_thread_policy(PortableServer::ORB_CTRL_MODEL)); // default for all POAs
107 PortableServer::ImplicitActivationPolicy_var implicitPol(defaultPoa->create_implicit_activation_policy(PortableServer::IMPLICIT_ACTIVATION)); // default for Root_POA, NO for others
108 policies[0] = PortableServer::ThreadPolicy::_duplicate(threadPol);
109 policies[1] = PortableServer::ImplicitActivationPolicy::_duplicate(implicitPol);
110 poa = defaultPoa->create_POA("KERNELStandaloneStudySingleThreadPOA",pman,policies);
111 threadPol->destroy();
112 SALOMEDS_Study_i::SetThePOA(poa);
114 if(!CORBA::is_nil(orb))
115 theObj = orb->resolve_initial_references("NameService");
116 if (!CORBA::is_nil(theObj)){
117 inc = CosNaming::NamingContext::_narrow(theObj);
118 if(!CORBA::is_nil(inc))
120 MESSAGE( "SalomeDS Server: Naming Service was found" );
123 CORBA::ORB_var orb1 = KERNEL::GetRefToORB() ;
124 NS = SINGLETON_<SALOME_NamingService>::Instance() ;
125 NS->init_orb( orb1 ) ;
126 for(int j=1; j<=NumberOfTries; j++)
130 nanosleep(&ts_req, &ts_rem);
132 Sleep(TIMESleep/1000000);
136 object = inc->resolve(name);
138 catch(CosNaming::NamingContext::NotFound&)
140 MESSAGE( "SalomeDS Server: Logger Server wasn't found" ); }
144 MESSAGE( "SalomeDS Server: Unknown exception" );
146 if (!CORBA::is_nil(object))
148 MESSAGE( "SalomeDS Server: Logger Server was found" );
158 catch( const SALOME_Exception &ex )
160 MESSAGE( "Communication Error : " << ex.what() );
161 return EXIT_FAILURE ;
163 if ((SALOMEDS==1)||((EnvL==0)&&(!CORBA::is_nil(inc))))
167 // We allocate the objects on the heap. Since these are reference
168 // counted objects, they will be deleted by the POA when they are no
170 SALOMEDS_Study_i * myStudy_i = new SALOMEDS_Study_i(orb);
172 // Activate the objects. This tells the POA that the objects are
173 // ready to accept requests.
174 PortableServer::ObjectId_var myStudy_iid = poa->activate_object(myStudy_i);
175 SALOMEDS::Study_var Study = myStudy_i->_this();
178 NS = SINGLETON_<SALOME_NamingService>::Instance();
181 NS->Register(Study, "/Study");
182 myStudy_i->_remove_ref();
184 // Obtain a POAManager, and tell the POA to start accepting
185 // requests on its objects.
186 pman = poa->the_POAManager();
193 MESSAGE("SALOME_Registry_Server.cxx - orb->run()");
194 timer.ShowAbsolute();
197 MESSAGE( "end of SALOME_DS server" );
198 NS->Destroy_Name("/Study");
201 catch(CORBA::SystemException&)
203 MESSAGE( "Caught CORBA::SystemException." );
205 catch(CORBA::Exception&)
207 MESSAGE( "Caught CORBA::Exception." );
209 catch(omniORB::fatalException& fe)
211 MESSAGE( "Caught omniORB::fatalException:" );
212 MESSAGE( " file: " << fe.file() );
213 MESSAGE( " line: " << fe.line() );
214 MESSAGE( " mesg: " << fe.errmsg() );
218 MESSAGE( "Caught unknown exception." );