1 // Copyright (C) 2007-2010 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.
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 Registry : Registry server implementation
24 // File : SALOME_Registry_Server.cxx
25 // Author : Pascale NOYRET - Antoine YESSAYAN, EDF
38 #include "utilities.h"
39 #include "Utils_ORB_INIT.hxx"
40 #include "Utils_SINGLETON.hxx"
41 #include "Utils_SALOME_Exception.hxx"
42 #include "Utils_CommException.hxx"
43 #include "ServiceUnreachable.hxx"
44 #include "SALOME_NamingService.hxx"
45 #include "RegistryService.hxx"
48 #include <Utils_Timer.hxx>
51 int main( int argc , char **argv )
53 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
54 CORBA::ORB_var &orb = init( argc , argv ) ;
55 // LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
61 MESSAGE("you must provide the Salome session name when you call SALOME_Registry_Server") ;
62 throw CommException("you must provide the Salome session name when you call SALOME_Registry_Server") ;
64 const char *ptrSessionName=0 ;
67 for ( k=1 ; k<argc ; k++ )
69 if( strcmp(argv[k],"--salome_session")==0 )
71 ptrSessionName=argv[k+1] ;
75 ASSERT(ptrSessionName) ;
76 ASSERT(strlen( ptrSessionName )>0) ;
77 const char *registryName = "Registry" ;
78 long TIMESleep = 250000000;
79 int NumberOfTries = 40;
84 ts_req.tv_nsec=TIMESleep;
89 CosNaming::NamingContext_var inc;
90 PortableServer::POA_var poa;
91 CORBA::Object_var theObj;
92 CORBA::Object_var obj;
93 CORBA::Object_var object;
94 SALOME_NamingService &naming = *SINGLETON_<SALOME_NamingService>::Instance() ;
95 Registry::Components_var varComponents;
97 const char * Env = getenv("USE_LOGGER");
99 if ((Env!=NULL) && (strlen(Env)))
101 CosNaming::Name name;
103 name[0].id=CORBA::string_dup("Logger");
104 PortableServer::POAManager_var manager;
105 for (int i = 1; i<=NumberOfTries; i++)
109 a=nanosleep(&ts_req,&ts_rem);
111 Sleep(TIMESleep/1000000);
115 obj = orb->resolve_initial_references("RootPOA");
116 if(!CORBA::is_nil(obj))
117 poa = PortableServer::POA::_narrow(obj);
118 if(!CORBA::is_nil(poa))
119 manager = poa->the_POAManager();
120 if(!CORBA::is_nil(orb))
121 theObj = orb->resolve_initial_references("NameService");
122 if (!CORBA::is_nil(theObj))
123 inc = CosNaming::NamingContext::_narrow(theObj);
125 catch( CORBA::SystemException& )
127 MESSAGE( "Registry Server: CORBA::SystemException: Unable to contact the Naming Service" );
129 if(!CORBA::is_nil(inc))
131 MESSAGE( "Registry Server: Naming Service was found" );
134 for(int j=1; j<=NumberOfTries; j++)
138 a=nanosleep(&ts_req, &ts_rem);
140 Sleep(TIMESleep/1000000);
144 object = inc->resolve(name);
146 catch(CosNaming::NamingContext::NotFound)
148 MESSAGE( "Registry Server: Logger Server wasn't found" );
152 MESSAGE( "Registry Server: Unknown exception" );
154 if (!CORBA::is_nil(object))
156 MESSAGE( "Module Catalog Server: Logger Server was found" );
163 if ((REGISTRY==1)||((EnvL==0)&&(!CORBA::is_nil(inc))))
169 naming.init_orb( orb ) ;
170 RegistryService *ptrRegistry = SINGLETON_<RegistryService>::Instance() ;
171 ptrRegistry->SessionName( ptrSessionName ) ;
172 ptrRegistry->SetOrb(orb);
173 varComponents = ptrRegistry->_this() ;
174 ptrRegistry->_remove_ref(); //let poa manage registryservice deletion
175 // The RegistryService must not already exist.
179 CORBA::Object_var pipo = naming.Resolve( registryName ) ;
180 if (CORBA::is_nil(pipo) ) throw ServiceUnreachable() ;
181 MESSAGE("RegistryService servant already existing" ) ;
182 exit( EXIT_FAILURE ) ;
184 catch( const ServiceUnreachable & )
187 catch( const CORBA::Exception & )
190 std::string absoluteName = std::string("/") + registryName;
191 naming.Register( varComponents , absoluteName.c_str() ) ;
192 MESSAGE("Wait client requests") ;
196 MESSAGE("POA activation") ;
197 manager->activate() ;
199 // Lancement de l'ORB
200 MESSAGE("ORB launching") ;
205 MESSAGE("SALOME_Registry_Server.cxx - orb->run()");
206 timer.ShowAbsolute();
210 catch( const CORBA::Exception & )
212 MESSAGE("System error") ;
213 return EXIT_FAILURE ;
217 catch( const SALOME_Exception &ex )
219 MESSAGE( "Communication Error : " << ex.what() )
220 return EXIT_FAILURE ;
224 // delete myThreadTrace;