1 // SALOME Registry : Registry server implementation
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_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>
52 int main( int argc , char **argv )
59 MESSAGE("you must provide the Salome session name when you call SALOME_Registry_Server") ;
60 throw CommException("you must provide the Salome session name when you call SALOME_Registry_Server") ;
62 const char *ptrSessionName=0 ;
65 for ( k=1 ; k<argc ; k++ )
67 if( strcmp(argv[k],"--salome_session")==0 )
69 ptrSessionName=argv[k+1] ;
73 ASSERT(ptrSessionName) ;
74 ASSERT(strlen( ptrSessionName )>0) ;
75 const char *registryName = "Registry" ;
76 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
77 CORBA::ORB_var &orb = init( argc , argv ) ;
79 long TIMESleep = 250000000;
80 int NumberOfTries = 40;
83 ts_req.tv_nsec=TIMESleep;
88 CosNaming::NamingContext_var inc;
89 PortableServer::POA_var poa;
90 CORBA::Object_var theObj;
91 CORBA::Object_var obj;
92 CORBA::Object_var object;
93 SALOME_NamingService &naming = *SINGLETON_<SALOME_NamingService>::Instance() ;
94 Registry::Components_var varComponents;
96 const char * Env = getenv("USE_LOGGER");
98 if ((Env!=NULL) && (strlen(Env)))
100 CosNaming::Name name;
102 name[0].id=CORBA::string_dup("Logger");
103 PortableServer::POAManager_var manager;
104 for (int i = 1; i<=NumberOfTries; i++)
107 a=nanosleep(&ts_req,&ts_rem);
110 obj = orb->resolve_initial_references("RootPOA");
111 if(!CORBA::is_nil(obj))
112 poa = PortableServer::POA::_narrow(obj);
113 if(!CORBA::is_nil(poa))
114 manager = poa->the_POAManager();
115 if(!CORBA::is_nil(orb))
116 theObj = orb->resolve_initial_references("NameService");
117 if (!CORBA::is_nil(theObj))
118 inc = CosNaming::NamingContext::_narrow(theObj);
120 catch( CORBA::COMM_FAILURE& )
122 MESSAGE( "Registry Server: CORBA::COMM_FAILURE: Unable to contact the Naming Service" );
124 if(!CORBA::is_nil(inc))
126 MESSAGE( "Registry Server: Naming Service was found" );
129 for(int j=1; j<=NumberOfTries; j++)
132 a=nanosleep(&ts_req, &ts_rem);
135 object = inc->resolve(name);
137 catch(CosNaming::NamingContext::NotFound)
139 MESSAGE( "Registry Server: Logger Server wasn't found" );
143 MESSAGE( "Registry Server: Unknown exception" );
145 if (!CORBA::is_nil(object))
147 MESSAGE( "Module Catalog Server: Logger Server was found" );
154 if ((REGISTRY==1)||((EnvL==0)&&(!CORBA::is_nil(inc))))
160 naming.init_orb( orb ) ;
161 RegistryService *ptrRegistry = SINGLETON_<RegistryService>::Instance() ;
162 ptrRegistry->SessionName( ptrSessionName ) ;
163 varComponents = ptrRegistry->_this() ;
164 // The RegistryService must not already exist.
168 CORBA::Object_var pipo = naming.Resolve( registryName ) ;
169 if (CORBA::is_nil(pipo) ) throw ServiceUnreachable() ;
170 MESSAGE("RegistryService servant already existing" ) ;
171 exit( EXIT_FAILURE ) ;
173 catch( const ServiceUnreachable &ex )
176 catch( const CORBA::Exception &exx )
179 string absoluteName = string("/") + registryName;
180 naming.Register( varComponents , absoluteName.c_str() ) ;
181 MESSAGE("On attend les requetes des clients") ;
185 MESSAGE("Activation du POA") ;
186 manager->activate() ;
188 // Lancement de l'ORB
189 MESSAGE("Lancement de l'ORB") ;
194 MESSAGE("SALOME_Registry_Server.cxx - orb->run()");
195 timer.ShowAbsolute();
199 catch( const CORBA::Exception &ex )
201 MESSAGE("Erreur systeme") ;
202 return EXIT_FAILURE ;
206 catch( const SALOME_Exception &ex )
208 MESSAGE( "Communication Error : " << ex.what() )
209 return EXIT_FAILURE ;