]> SALOME platform Git repositories - modules/kernel.git/blob - src/ModuleCatalog/SALOME_ModuleCatalog_Server.cxx
Salome HOME
Copyright update 2021
[modules/kernel.git] / src / ModuleCatalog / SALOME_ModuleCatalog_Server.cxx
1 // Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SALOME ModuleCatalog : implementation of ModuleCatalog server which parsers xml description of modules
24 //  File   : SALOME_ModuleCatalog_Server.cxx
25 //  Module : SALOME
26 //
27 /* $Header$ */
28
29 #include <iostream>
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
39 int main(int argc,char **argv)
40 {
41   // initialize the ORB
42   CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
43   try 
44     {
45       CosNaming::NamingContext_var _rootContext, catalogContext;
46
47       // initialize POA
48       //
49       long TIMESleep = 500000000;
50       int NumberOfTries = 40;
51       timespec ts_req;
52       ts_req.tv_nsec=TIMESleep;
53       ts_req.tv_sec=0;
54       timespec ts_rem;
55       ts_rem.tv_nsec=0;
56       ts_rem.tv_sec=0;
57       CosNaming::NamingContext_var inc;
58       PortableServer::POA_var poa;
59       CORBA::Object_var theObj;
60       CORBA::Object_var obj;
61       CORBA::Object_var object;
62       int MODULE_CATALOG=0;
63       const char * Env = getenv("USE_LOGGER");
64       int EnvL =0;
65       if ((Env!=NULL) && (strlen(Env)))
66         EnvL=1;
67       CosNaming::Name name;
68       name.length(1);
69       name[0].id=CORBA::string_dup("Logger");    
70       PortableServer::POAManager_var mgr; 
71       for (int i = 1; i<=NumberOfTries; i++)
72         {
73           if (i!=1) 
74 #ifndef WIN32
75             nanosleep(&ts_req,&ts_rem);
76 #else
77             Sleep(TIMESleep/1000000);
78 #endif
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::SystemException& )
90             {
91               INFOS( "Module Catalog Server: CORBA::SystemException: 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                   INFOS( "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 #ifndef WIN32
108                             nanosleep(&ts_req, &ts_rem);
109 #else
110                             Sleep(TIMESleep/1000000);
111 #endif
112                           try{
113                             object = inc->resolve(name);}
114                           catch(CosNaming::NamingContext::NotFound&)
115                             {
116                               INFOS( "Logger Server wasn't found" );
117                             }
118                           catch(...)
119                             {
120                               INFOS( "Module Catalog Server: Unknown exception" ) ;
121                             }
122                           if (!CORBA::is_nil(object))
123                             {
124                               INFOS( "Module Catalog Server: Logger Server was found" );
125                               MODULE_CATALOG=1;
126                               break;
127                             }
128                         }
129                     }
130                 }
131             }
132           if ((MODULE_CATALOG==1)||((EnvL==0)&&(!CORBA::is_nil(inc))))
133             break;
134         }
135   
136       // Active catalog
137
138       SALOME_ModuleCatalogImpl* Catalogue_i=new SALOME_ModuleCatalogImpl(argc, argv, orb);
139       PortableServer::ObjectId_var cataid = poa->activate_object (Catalogue_i);
140
141       //activate POA manager
142       mgr->activate();
143   
144       CORBA::Object_var myCata = Catalogue_i->_this();
145       Catalogue_i->_remove_ref();
146
147       // initialise Naming Service
148       SALOME_NamingService _NS(orb);
149       // register Catalog in Naming Service
150       _NS.Register(myCata ,"/Kernel/ModulCatalog");
151
152       MESSAGE("Running CatalogServer.");
153
154 #ifdef CHECKTIME
155       Utils_Timer timer;
156       timer.Start();
157       timer.Stop();
158       timer.ShowAbsolute();
159 #endif
160       orb->run();
161       orb->destroy();
162  
163 //       mgr->deactivate(true,true);
164 //       poa->destroy(1,1);
165
166     }
167   catch(CORBA::SystemException&) {
168     INFOS("Caught CORBA::SystemException.")
169       }
170   catch(CORBA::Exception&) {
171     INFOS("Caught CORBA::Exception.")
172       }
173
174   END_OF( argv[0] );
175   return 0;
176 }