1 // SALOME SALOMEDS : data structure of SALOME and sources of Salome data server
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 : SALOMEDS_Server.cxx
25 // Author : Yves FRICAUD
30 #include <SALOMEconfig.h>
31 #include CORBA_SERVER_HEADER(SALOMEDS)
32 #include "SALOMEDS_StudyManager_i.hxx"
33 #include "utilities.h"
34 # include "Utils_SINGLETON.hxx"
35 #include "SALOME_NamingService.hxx"
38 #include <Utils_Timer.hxx>
42 // { // for ccmalloc memory debug
43 // void ccmalloc_static_initialization(void);
46 ///////////////////////////// MAIN ///////////////////////////////////////
47 //////////////////////////////////////////////////////////////////////////
48 int main(int argc, char** argv)
50 // ccmalloc_static_initialization();
52 MESSAGE("SALOMEDS_Server - main");
54 // Initialise the ORB.
55 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB3");
56 omniORB::MaxMessageSize(100 * 1024 * 1024);
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_Logger::Logger_var log;
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 pman;
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 pman = 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);
96 if(!CORBA::is_nil(inc)) {
97 MESSAGE( "SalomeDS Server: Naming Service was found" )
99 CORBA::ORB_var orb1 = CORBA::ORB_init(argc,argv) ;
100 SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance() ;
101 NS.init_orb( orb1 ) ;
102 for(int j=1; j<=NumberOfTries; j++){
104 a=nanosleep(&ts_req, &ts_rem);
106 object = inc->resolve(name);}
107 catch(CosNaming::NamingContext::NotFound){ MESSAGE( "SalomeDS Server: Logger Server wasn't found" ) }
108 catch(...){ MESSAGE( "SalomeDS Server: Unknown exception" ) }
109 if (!CORBA::is_nil(object))
110 log = SALOME_Logger::Logger::_narrow(object);
111 if (!CORBA::is_nil(log)){
112 MESSAGE( "SalomeDS Server: Logger Server was found" )
121 catch( const SALOME_Exception &ex )
123 MESSAGE( "Communication Error : " << ex.what() )
124 return EXIT_FAILURE ;
126 if ((SALOMEDS==1)||((EnvL==0)&&(!CORBA::is_nil(inc))))
131 // We allocate the objects on the heap. Since these are reference
132 // counted objects, they will be deleted by the POA when they are no
134 SALOMEDS_StudyManager_i * myStudyManager_i = new SALOMEDS_StudyManager_i(orb);
136 // Activate the objects. This tells the POA that the objects are
137 // ready to accept requests.
138 PortableServer::ObjectId_var myStudyManager_iid = poa->activate_object(myStudyManager_i);
139 myStudyManager_i->register_name("/myStudyManager");
141 // Obtain a POAManager, and tell the POA to start accepting
142 // requests on its objects.
143 pman = poa->the_POAManager();
150 MESSAGE("SALOME_Registry_Server.cxx - orb->run()");
151 timer.ShowAbsolute();
156 catch(CORBA::SystemException&) {
157 MESSAGE( "Caught CORBA::SystemException." )
159 catch(CORBA::Exception&) {
160 MESSAGE( "Caught CORBA::Exception." )
162 catch(omniORB::fatalException& fe) {
163 MESSAGE( "Caught omniORB::fatalException:" )
164 MESSAGE( " file: " << fe.file() )
165 MESSAGE( " line: " << fe.line() )
166 MESSAGE( " mesg: " << fe.errmsg() )
169 MESSAGE( "Caught unknown exception." )