Salome HOME
b917ec29f1ccf53ba5133995b5b1e0b3d2ce7170
[modules/kernel.git] / src / Registry / SALOME_Registry_Server.cxx
1 using namespace std;
2 //=============================================================================
3 // File      : SALOME_Registry_Server.cxx
4 // Created   : Mon Nov  5 17:26:23 CET 2001
5 // Author    : Pascale NOYRET - Antoine YESSAYAN, EDF
6 // Project   : SALOME
7 // Copyright : EDF 2001
8 // $Header$
9 //=============================================================================
10
11 # include <stdlib.h>
12 # include <iostream.h>
13 # include <fstream.h>
14
15 extern "C"
16 {
17 # include <stdio.h>
18 }
19
20 # include "utilities.h"
21 # include "Utils_ORB_INIT.hxx"
22 # include "Utils_SINGLETON.hxx"
23 # include "Utils_SALOME_Exception.hxx"
24 # include "Utils_CommException.hxx"
25 # include "ServiceUnreachable.hxx"
26 # include "SALOME_NamingService.hxx"
27 # include "RegistryService.hxx"
28
29 int main( int argc , char **argv )
30 {
31         BEGIN_OF( argv[0] )
32         INFOS_COMPILATION 
33         SCRUTE(argc) 
34         if( argc<3 )
35         {
36                 MESSAGE("you must provide the Salome session name when you call SALOME_Registry_Server") ;
37                 throw CommException("you must provide the Salome session name when you call SALOME_Registry_Server") ;
38         }
39         const char *ptrSessionName=0 ;
40
41         int k=0 ;
42         for ( k=1 ; k<argc ; k++ )
43         {
44                 if( strcmp(argv[k],"--salome_session")==0 )
45                 {
46                         ptrSessionName=argv[k+1] ;
47                         break ;
48                 }
49         }
50         ASSERT(ptrSessionName) ;
51         ASSERT(strlen( ptrSessionName )>0) ;
52         const char *registryName = "Registry" ;
53
54
55         try
56         {
57                 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
58                 CORBA::ORB_var &orb = init( argc , argv ) ;
59
60
61                 SALOME_NamingService &naming = *SINGLETON_<SALOME_NamingService>::Instance() ;
62                 naming.init_orb( orb ) ;
63
64                 RegistryService *ptrRegistry = SINGLETON_<RegistryService>::Instance() ;
65                 ptrRegistry->SessionName( ptrSessionName ) ;
66                 Registry::Components_var varComponents = ptrRegistry->_this() ;
67
68                 // The RegistryService must not already exist.
69
70                 try
71                 {
72                         CORBA::Object_var pipo = naming.Resolve( registryName ) ;
73                         if (CORBA::is_nil(pipo) )  throw ServiceUnreachable() ;
74                         MESSAGE("RegistryService servant already existing" ) ;
75                         exit( EXIT_FAILURE ) ;
76                 }
77                 catch( const ServiceUnreachable &ex )
78                 {
79                 }
80                 catch( const CORBA::Exception &exx )
81                 {
82                 }
83                 string absoluteName = string("/") + registryName;
84                 naming.Register( varComponents , absoluteName.c_str() ) ;
85
86
87                 CORBA::Object_var poaObj = orb->resolve_initial_references( "RootPOA" ) ;
88                 PortableServer::POA_var poa = PortableServer::POA::_narrow(poaObj) ;
89                 PortableServer::POAManager_var manager = poa->the_POAManager() ;
90
91
92                 MESSAGE("On attend les requetes des clients") ;
93                 try
94                 {
95                         // Activation du POA
96                         MESSAGE("Activation du POA") ;
97                         manager->activate() ;
98
99                         // Lancement de l'ORB
100                         MESSAGE("Lancement de l'ORB") ;
101                         orb->run() ;
102                 }
103                 catch( const CORBA::Exception &ex )
104                 {
105                         MESSAGE("Erreur systeme") ;
106                         return EXIT_FAILURE ;
107                 }
108
109         }
110         catch( const SALOME_Exception &ex )
111         {
112                 MESSAGE( "Communication Error : " << ex.what() )
113                 return EXIT_FAILURE ;
114         }
115
116         END_OF( argv[0] ) ;
117         return 0 ;
118 }