Back to index

salome-kernel  6.5.0
SALOME_ModuleCatalog_Server.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME ModuleCatalog : implementation of ModuleCatalog server which parsers xml description of modules
00024 //  File   : SALOME_ModuleCatalog_Server.cxx
00025 //  Module : SALOME
00026 //
00027 /* $Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/ModuleCatalog/SALOME_ModuleCatalog_Server.cxx,v 1.15.2.2.10.2.12.1 2012-04-12 14:05:17 vsr Exp $ */
00028 
00029 #include <iostream>
00030 #include "SALOME_NamingService.hxx"
00031 #include "SALOME_ModuleCatalog_impl.hxx"
00032 #include "utilities.h"
00033 #include "Utils_SINGLETON.hxx"
00034 
00035 #ifdef CHECKTIME
00036 #include <Utils_Timer.hxx>
00037 #endif
00038 
00039 int main(int argc,char **argv)
00040 {
00041   // initialize the ORB
00042   CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
00043   try 
00044     {
00045       CosNaming::NamingContext_var _rootContext, catalogContext;
00046 
00047       // initialize POA
00048       //
00049       long TIMESleep = 500000000;
00050       int NumberOfTries = 40;
00051 #ifndef WIN32
00052       int a;
00053 #endif
00054       timespec ts_req;
00055       ts_req.tv_nsec=TIMESleep;
00056       ts_req.tv_sec=0;
00057       timespec ts_rem;
00058       ts_rem.tv_nsec=0;
00059       ts_rem.tv_sec=0;
00060       CosNaming::NamingContext_var inc;
00061       PortableServer::POA_var poa;
00062       CORBA::Object_var theObj;
00063       CORBA::Object_var obj;
00064       CORBA::Object_var object;
00065       int MODULE_CATALOG=0;
00066       const char * Env = getenv("USE_LOGGER");
00067       int EnvL =0;
00068       if ((Env!=NULL) && (strlen(Env)))
00069         EnvL=1;
00070       CosNaming::Name name;
00071       name.length(1);
00072       name[0].id=CORBA::string_dup("Logger");    
00073       PortableServer::POAManager_var mgr; 
00074       for (int i = 1; i<=NumberOfTries; i++)
00075         {
00076           if (i!=1) 
00077 #ifndef WIN32
00078             a=nanosleep(&ts_req,&ts_rem);
00079 #else
00080             Sleep(TIMESleep/1000000);
00081 #endif
00082           try
00083             { 
00084               obj = orb->resolve_initial_references("RootPOA");
00085               if(!CORBA::is_nil(obj))
00086                 poa = PortableServer::POA::_narrow(obj);
00087               if(!CORBA::is_nil(poa))
00088                 mgr = poa->the_POAManager();
00089               if(!CORBA::is_nil(orb)) 
00090                 theObj = orb->resolve_initial_references("NameService"); 
00091             }
00092           catch( CORBA::SystemException& )
00093             {
00094               INFOS( "Module Catalog Server: CORBA::SystemException: Unable to contact the Naming Service" );
00095             }
00096           if (!CORBA::is_nil(theObj))
00097             {
00098               inc = CosNaming::NamingContext::_narrow(theObj);
00099               if(!CORBA::is_nil(inc))
00100                 {
00101                   INFOS( "Module Catalog Server: Naming Service was found" );
00102                   if(EnvL==1)
00103                     {
00104                       CORBA::ORB_var orb1 = CORBA::ORB_init(argc,argv) ;
00105                       SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance() ;
00106                       NS.init_orb( orb1 ) ;
00107                       for(int j=1; j<=NumberOfTries; j++)
00108                         {
00109                           if (j!=1) 
00110 #ifndef WIN32
00111                             a=nanosleep(&ts_req, &ts_rem);
00112 #else
00113                             Sleep(TIMESleep/1000000);
00114 #endif
00115                           try{
00116                             object = inc->resolve(name);}
00117                           catch(CosNaming::NamingContext::NotFound)
00118                             {
00119                               INFOS( "Logger Server wasn't found" );
00120                             }
00121                           catch(...)
00122                             {
00123                               INFOS( "Module Catalog Server: Unknown exception" ) ;
00124                             }
00125                           if (!CORBA::is_nil(object))
00126                             {
00127                               INFOS( "Module Catalog Server: Logger Server was found" );
00128                               MODULE_CATALOG=1;
00129                               break;
00130                             }
00131                         }
00132                     }
00133                 }
00134             }
00135           if ((MODULE_CATALOG==1)||((EnvL==0)&&(!CORBA::is_nil(inc))))
00136             break;
00137         }
00138   
00139       // Active catalog
00140 
00141       SALOME_ModuleCatalogImpl* Catalogue_i=new SALOME_ModuleCatalogImpl(argc, argv, orb);
00142       PortableServer::ObjectId_var cataid = poa->activate_object (Catalogue_i);
00143 
00144       //activate POA manager
00145       mgr->activate();
00146   
00147       CORBA::Object_var myCata = Catalogue_i->_this();
00148       Catalogue_i->_remove_ref();
00149 
00150       // initialise Naming Service
00151       SALOME_NamingService _NS(orb);
00152       // register Catalog in Naming Service
00153       _NS.Register(myCata ,"/Kernel/ModulCatalog");
00154 
00155       MESSAGE("Running CatalogServer.");
00156 
00157 #ifdef CHECKTIME
00158       Utils_Timer timer;
00159       timer.Start();
00160       timer.Stop();
00161       timer.ShowAbsolute();
00162 #endif
00163       orb->run();
00164       orb->destroy();
00165  
00166 //       mgr->deactivate(true,true);
00167 //       poa->destroy(1,1);
00168 
00169     }
00170   catch(CORBA::SystemException&) {
00171     INFOS("Caught CORBA::SystemException.")
00172       }
00173   catch(CORBA::Exception&) {
00174     INFOS("Caught CORBA::Exception.")
00175       }
00176 
00177   END_OF( argv[0] );
00178   return 0;
00179 }