1 // SALOME ModuleCatalog : implementation of ModuleCatalog server which parsers xml description of modules
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SALOME_ModuleCatalog_Server.cxx
29 #include "SALOME_NamingService.hxx"
30 #include "SALOME_ModuleCatalog_impl.hxx"
31 #include "utilities.h"
32 #include "Utils_SINGLETON.hxx"
35 #include <Utils_Timer.hxx>
39 int main(int argc,char **argv)
42 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
43 // LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
46 CosNaming::NamingContext_var _rootContext, catalogContext;
50 long TIMESleep = 500000000;
51 int NumberOfTries = 40;
54 ts_req.tv_nsec=TIMESleep;
59 CosNaming::NamingContext_var inc;
60 PortableServer::POA_var poa;
61 CORBA::Object_var theObj;
62 CORBA::Object_var obj;
63 CORBA::Object_var object;
65 const char * Env = getenv("USE_LOGGER");
67 if ((Env!=NULL) && (strlen(Env)))
71 name[0].id=CORBA::string_dup("Logger");
72 PortableServer::POAManager_var mgr;
73 for (int i = 1; i<=NumberOfTries; i++)
77 a=nanosleep(&ts_req,&ts_rem);
79 Sleep(TIMESleep/1000000);
83 obj = orb->resolve_initial_references("RootPOA");
84 if(!CORBA::is_nil(obj))
85 poa = PortableServer::POA::_narrow(obj);
86 if(!CORBA::is_nil(poa))
87 mgr = poa->the_POAManager();
88 if(!CORBA::is_nil(orb))
89 theObj = orb->resolve_initial_references("NameService");
91 catch( CORBA::SystemException& )
93 INFOS( "Module Catalog Server: CORBA::SystemException: Unable to contact the Naming Service" );
95 if (!CORBA::is_nil(theObj))
97 inc = CosNaming::NamingContext::_narrow(theObj);
98 if(!CORBA::is_nil(inc))
100 INFOS( "Module Catalog Server: Naming Service was found" );
103 CORBA::ORB_var orb1 = CORBA::ORB_init(argc,argv) ;
104 SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance() ;
105 NS.init_orb( orb1 ) ;
106 for(int j=1; j<=NumberOfTries; j++)
110 a=nanosleep(&ts_req, &ts_rem);
112 Sleep(TIMESleep/1000000);
115 object = inc->resolve(name);}
116 catch(CosNaming::NamingContext::NotFound)
118 INFOS( "Logger Server wasn't found" );
122 INFOS( "Module Catalog Server: Unknown exception" ) ;
124 if (!CORBA::is_nil(object))
126 INFOS( "Module Catalog Server: Logger Server was found" );
134 if ((MODULE_CATALOG==1)||((EnvL==0)&&(!CORBA::is_nil(inc))))
140 SALOME_ModuleCatalogImpl* Catalogue_i=new SALOME_ModuleCatalogImpl(argc, argv, orb);
141 PortableServer::ObjectId_var cataid = poa->activate_object (Catalogue_i);
143 //activate POA manager
146 CORBA::Object_var myCata = Catalogue_i->_this();
147 Catalogue_i->_remove_ref();
149 // initialise Naming Service
150 SALOME_NamingService _NS(orb);
151 // register Catalog in Naming Service
152 _NS.Register(myCata ,"/Kernel/ModulCatalog");
154 MESSAGE("Running CatalogServer.");
160 MESSAGE("SALOME_Registry_Server.cxx - orb->run()");
161 timer.ShowAbsolute();
164 std::cerr << "server returned from orb->run()" << std::endl;
167 // mgr->deactivate(true,true);
168 // poa->destroy(1,1);
171 catch(CORBA::SystemException&) {
172 INFOS("Caught CORBA::SystemException.")
174 catch(CORBA::Exception&) {
175 INFOS("Caught CORBA::Exception.")
179 // delete myThreadTrace;