]> SALOME platform Git repositories - modules/kernel.git/blob - src/ModuleCatalog/SALOME_ModuleCatalog_Server.cxx
Salome HOME
PR: mergefrom_PRAS_br2_14Jan04
[modules/kernel.git] / src / ModuleCatalog / SALOME_ModuleCatalog_Server.cxx
1 //  SALOME ModuleCatalog : implementation of ModuleCatalog server which parsers xml description of modules
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SALOME_ModuleCatalog_Server.cxx
25 //  Module : SALOME
26
27 /* $Header$ */
28
29 #include <iostream.h>
30 #include "SALOME_NamingService.hxx"
31 #include "SALOME_ModuleCatalog_impl.hxx"
32 #include "utilities.h"
33 #include "Utils_SINGLETON.hxx"
34
35 #ifdef CHECKTIME
36 #include <Utils_Timer.hxx>
37 #endif
38 using namespace std;
39
40 int main(int argc,char **argv)
41 {
42   try 
43     {
44       CosNaming::NamingContext_var _rootContext, catalogContext;
45
46       // initialize the ORB
47
48       CORBA::ORB_ptr orb = CORBA::ORB_init (argc, argv);
49
50       // initialize POA
51       //
52       long TIMESleep = 250000000;
53       int NumberOfTries = 40;
54       int a;
55       timespec ts_req;
56       ts_req.tv_nsec=TIMESleep;
57       ts_req.tv_sec=0;
58       timespec ts_rem;
59       ts_rem.tv_nsec=0;
60       ts_rem.tv_sec=0;
61       CosNaming::NamingContext_var inc;
62       PortableServer::POA_var poa;
63       CORBA::Object_var theObj;
64       CORBA::Object_var obj;
65       CORBA::Object_var object;
66       int MODULE_CATALOG=0;
67       const char * Env = getenv("USE_LOGGER");
68       int EnvL =0;
69       if ((Env!=NULL) && (strlen(Env)))
70         EnvL=1;
71       CosNaming::Name name;
72       name.length(1);
73       name[0].id=CORBA::string_dup("Logger");    
74       PortableServer::POAManager_var mgr; 
75       for (int i = 1; i<=NumberOfTries; i++)
76         {
77           if (i!=1) 
78             a=nanosleep(&ts_req,&ts_rem);
79           try
80             { 
81               obj = orb->resolve_initial_references("RootPOA");
82               if(!CORBA::is_nil(obj))
83                 poa = PortableServer::POA::_narrow(obj);
84               if(!CORBA::is_nil(poa))
85                 mgr = poa->the_POAManager();
86               if(!CORBA::is_nil(orb)) 
87                 theObj = orb->resolve_initial_references("NameService"); 
88             }
89           catch( CORBA::COMM_FAILURE& )
90             {
91               MESSAGE( "Module Catalog Server: CORBA::COMM_FAILURE: Unable to contact the Naming Service" );
92             }
93           if (!CORBA::is_nil(theObj))
94             {
95               inc = CosNaming::NamingContext::_narrow(theObj);
96               if(!CORBA::is_nil(inc))
97                 {
98                   MESSAGE( "Module Catalog Server: Naming Service was found" );
99                   if(EnvL==1)
100                     {
101                       CORBA::ORB_var orb1 = CORBA::ORB_init(argc,argv) ;
102                       SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance() ;
103                       NS.init_orb( orb1 ) ;
104                       for(int j=1; j<=NumberOfTries; j++)
105                         {
106                           if (j!=1) 
107                             a=nanosleep(&ts_req, &ts_rem);
108                           try{
109                             object = inc->resolve(name);}
110                           catch(CosNaming::NamingContext::NotFound)
111                             {
112                               MESSAGE( "Logger Server wasn't found" );
113                             }
114                           catch(...)
115                             {
116                               MESSAGE( "Module Catalog Server: Unknown exception" ) ;
117                             }
118                           if (!CORBA::is_nil(object))
119                             {
120                               MESSAGE( "Module Catalog Server: Logger Server was found" );
121                               MODULE_CATALOG=1;
122                               break;
123                             }
124                         }
125                     }
126                 }
127             }
128           if ((MODULE_CATALOG==1)||((EnvL==0)&&(!CORBA::is_nil(inc))))
129             break;
130         }
131   
132       // Active catalog
133
134       SALOME_ModuleCatalogImpl* Catalogue_i = new SALOME_ModuleCatalogImpl(argc, argv);
135       poa->activate_object (Catalogue_i);
136
137       mgr->activate();
138
139   
140       CORBA::Object_ptr myCata = Catalogue_i->_this();
141
142       // initialise Naming Service
143       SALOME_NamingService *_NS;
144       _NS = new SALOME_NamingService(orb);
145       // register Catalog in Naming Service
146       _NS->Register(myCata ,"/Kernel/ModulCatalog");
147
148       MESSAGE("Running CatalogServer.");
149
150 #ifdef CHECKTIME
151       Utils_Timer timer;
152       timer.Start();
153       timer.Stop();
154       MESSAGE("SALOME_Registry_Server.cxx - orb->run()");
155       timer.ShowAbsolute();
156 #endif
157       orb->run();
158  
159       poa->destroy(1,1);
160  
161     }
162   catch(CORBA::SystemException&) {
163     INFOS("Caught CORBA::SystemException.")
164       }
165   catch(CORBA::Exception&) {
166     INFOS("Caught CORBA::Exception.")
167       }
168
169   return 0;
170 }