Back to index

salome-kernel  6.5.0
SALOMEDS_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 SALOMEDS : data structure of SALOME and sources of Salome data server 
00024 //  File   : SALOMEDS_Server.cxx
00025 //  Author : Yves FRICAUD
00026 //  Module : SALOME
00027 //  $Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/SALOMEDS/SALOMEDS_Server.cxx,v 1.13.2.1.10.2.12.1 2012-04-12 14:05:26 vsr Exp $
00028 //
00029 #include "utilities.h"
00030 #include "Utils_SINGLETON.hxx"
00031 
00032 #include "SALOME_NamingService.hxx"
00033 #include "SALOMEDS_StudyManager_i.hxx"
00034 
00035 #include <SALOMEconfig.h>
00036 #include CORBA_SERVER_HEADER(SALOMEDS)
00037 
00038 #ifdef CHECKTIME
00039 #include <Utils_Timer.hxx>
00040 #endif
00041 
00042 // extern "C"
00043 // { // for ccmalloc memory debug
00044 // void ccmalloc_static_initialization(void);
00045 // }
00046 
00049 int main(int argc, char** argv)
00050 {
00051   //   ccmalloc_static_initialization();
00052 
00053   MESSAGE("SALOMEDS_Server - main");
00054   try 
00055     {
00056       // Initialise the ORB.
00057 #if OMNIORB_VERSION >= 4
00058       CORBA::ORB_var orb = CORBA::ORB_init( argc, argv, "omniORB4" ) ;
00059 #else
00060       CORBA::ORB_var orb = CORBA::ORB_init( argc, argv, "omniORB3" );
00061 #endif      
00062       // Obtain a reference to the root POA.
00063       long TIMESleep = 500000000;
00064       int NumberOfTries = 40;
00065       int a;
00066       timespec ts_req;
00067       ts_req.tv_nsec=TIMESleep;
00068       ts_req.tv_sec=0;
00069       timespec ts_rem;
00070       ts_rem.tv_nsec=0;
00071       ts_rem.tv_sec=0;
00072       CosNaming::NamingContext_var inc;
00073       PortableServer::POA_var poa;
00074       CORBA::Object_var theObj;
00075       CORBA::Object_var obj;
00076       CORBA::Object_var object;
00077       int SALOMEDS=0;
00078       const char * Env = getenv("USE_LOGGER");
00079       int EnvL =0;
00080       if ((Env!=NULL) && (strlen(Env)))
00081         EnvL=1;
00082       CosNaming::Name name;
00083       name.length(1);
00084       name[0].id=CORBA::string_dup("Logger");    
00085       PortableServer::POAManager_var pman; 
00086       for (int i = 1; i<=NumberOfTries; i++)
00087         {
00088           if (i!=1) 
00089 #ifndef WIN32
00090             a=nanosleep(&ts_req,&ts_rem);
00091 #else
00092                 Sleep(TIMESleep/1000000);
00093 #endif
00094           try
00095             { 
00096               obj = orb->resolve_initial_references("RootPOA");
00097               if(!CORBA::is_nil(obj))
00098                 poa = PortableServer::POA::_narrow(obj);
00099               if(!CORBA::is_nil(poa))
00100                 pman = poa->the_POAManager();
00101               if(!CORBA::is_nil(orb)) 
00102                 theObj = orb->resolve_initial_references("NameService"); 
00103               if (!CORBA::is_nil(theObj)){
00104                 inc = CosNaming::NamingContext::_narrow(theObj);
00105                 if(!CORBA::is_nil(inc))
00106                   {
00107                     MESSAGE( "SalomeDS Server: Naming Service was found" );
00108                     if(EnvL==1)
00109                       {
00110                         CORBA::ORB_var orb1 = CORBA::ORB_init(argc,argv) ;
00111                         SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance() ;
00112                         NS.init_orb( orb1 ) ;
00113                         for(int j=1; j<=NumberOfTries; j++)
00114                           {
00115                             if (j!=1) 
00116 #ifndef WIN32
00117                               a=nanosleep(&ts_req, &ts_rem);
00118 #else
00119                               Sleep(TIMESleep/1000000);
00120 #endif
00121                             try
00122                               {
00123                                 object = inc->resolve(name);
00124                               }
00125                             catch(CosNaming::NamingContext::NotFound)
00126                               { 
00127                                 MESSAGE( "SalomeDS Server: Logger Server wasn't found" ); }
00128 
00129                             catch(...)
00130                               {
00131                                 MESSAGE( "SalomeDS Server: Unknown exception" );
00132                               }
00133                             if (!CORBA::is_nil(object))
00134                               {
00135                                 MESSAGE( "SalomeDS Server: Logger Server was found" );
00136                                 SALOMEDS=1;
00137                                 break;
00138                               }
00139                           }
00140                       }
00141                   }
00142               }
00143         
00144             }
00145           catch( const SALOME_Exception &ex )
00146             {
00147               MESSAGE( "Communication Error : " << ex.what() );
00148               return EXIT_FAILURE ;
00149             }
00150           if ((SALOMEDS==1)||((EnvL==0)&&(!CORBA::is_nil(inc))))
00151             break;
00152         }
00153     
00154       // We allocate the objects on the heap.  Since these are reference
00155       // counted objects, they will be deleted by the POA when they are no
00156       // longer needed.    
00157       SALOMEDS_StudyManager_i * myStudyManager_i = new  SALOMEDS_StudyManager_i(orb,poa);
00158  
00159       // Activate the objects.  This tells the POA that the objects are
00160       // ready to accept requests.
00161       PortableServer::ObjectId_var myStudyManager_iid = poa->activate_object(myStudyManager_i);
00162       myStudyManager_i->register_name("/myStudyManager");
00163       myStudyManager_i->_remove_ref();
00164        
00165       // Obtain a POAManager, and tell the POA to start accepting
00166       // requests on its objects.
00167       pman = poa->the_POAManager();
00168       pman->activate();
00169 
00170 #ifdef CHECKTIME
00171       Utils_Timer timer;
00172       timer.Start();
00173       timer.Stop();
00174       MESSAGE("SALOME_Registry_Server.cxx - orb->run()");
00175       timer.ShowAbsolute();
00176 #endif
00177       orb->run();
00178       MESSAGE( "end of SALOME_DS server" );
00179       orb->destroy();
00180     }
00181   catch(CORBA::SystemException&)
00182     {
00183       MESSAGE( "Caught CORBA::SystemException." );
00184     }
00185   catch(CORBA::Exception&)
00186     {
00187       MESSAGE( "Caught CORBA::Exception." );
00188     }
00189   catch(omniORB::fatalException& fe)
00190     {
00191       MESSAGE( "Caught omniORB::fatalException:" );
00192       MESSAGE( "  file: " << fe.file() );
00193       MESSAGE( "  line: " << fe.line() );
00194       MESSAGE( "  mesg: " << fe.errmsg() );
00195     }
00196   catch(...) 
00197     {
00198       MESSAGE( "Caught unknown exception." );
00199     }
00200   return 0;
00201 }