Salome HOME
PR : merge branch V1_2c dans branche principale pour V1_3_0_b1
[modules/kernel.git] / src / DataTypeCatalog / SALOME_DataTypeCatalog_Server.cxx
1 //  SALOME DataTypeCatalog : catalog of data types
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_DataTypeCatalog_Server.cxx
25 //  Author : Estelle Deville
26 //  Module : SALOME
27 //  $Header$
28
29 using namespace std;
30 #include <iostream.h>
31 #include "SALOME_NamingService.hxx"
32 #include "SALOME_DataTypeCatalog_impl.hxx"
33 #include "utilities.h"
34 # include "Utils_SINGLETON.hxx"
35 int main(int argc,char **argv)
36 {
37   try {
38   CosNaming::NamingContext_var _rootContext, catalogContext;
39   // initialize the ORB
40   CORBA::ORB_ptr orb = CORBA::ORB_init (argc, argv);
41   // initialize POA
42   //
43   long TIMESleep = 250000000;
44   int NumberOfTries = 40;
45   int a;
46   timespec ts_req;
47   ts_req.tv_nsec=TIMESleep;
48   ts_req.tv_sec=0;
49   timespec ts_rem;
50   ts_rem.tv_nsec=0;
51   ts_rem.tv_sec=0;
52   CosNaming::NamingContext_var inc;
53   PortableServer::POA_var poa;
54   CORBA::Object_var theObj;
55   CORBA::Object_var obj;
56   CORBA::Object_var object;
57   SALOME_Logger::Logger_var log;
58   int DATA_TYPE_CATALOG=0;
59   const char * Env = getenv("USE_LOGGER"); 
60   int EnvL =0;
61   if ((Env!=NULL) && (strlen(Env)))
62     EnvL=1;  
63   CosNaming::Name name;
64   name.length(1);
65   name[0].id=CORBA::string_dup("Logger");    
66   PortableServer::POAManager_var mgr; 
67  
68   for (int i = 1; i<=NumberOfTries; i++){
69     if (i!=1) 
70       a=nanosleep(&ts_req,&ts_rem);
71     try{ 
72       obj = orb->resolve_initial_references("RootPOA");
73       if(!CORBA::is_nil(obj))
74         poa = PortableServer::POA::_narrow(obj);
75       if(!CORBA::is_nil(poa))
76         mgr = poa->the_POAManager();
77       if(!CORBA::is_nil(orb)) 
78         theObj = orb->resolve_initial_references("NameService");
79       if (!CORBA::is_nil(theObj))
80         inc = CosNaming::NamingContext::_narrow(theObj);}
81     catch( CORBA::COMM_FAILURE& )
82       {
83         MESSAGE( "Data Type Catalog: CORBA::COMM_FAILURE: Unable to contact the Naming Service" )
84           }
85     if(!CORBA::is_nil(inc)) {
86       MESSAGE( "Data Type Catalog: Naming Service was found" )
87         if(EnvL==1){
88           CORBA::ORB_var orb1 = CORBA::ORB_init(argc,argv) ;
89           SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance() ;
90           NS.init_orb( orb1 ) ;
91           for(int j=1; j<=NumberOfTries; j++){
92             if (j!=1) 
93                   a=nanosleep(&ts_req, &ts_rem);
94             try{
95               object = inc->resolve(name);}
96             catch(CosNaming::NamingContext::NotFound){ MESSAGE( "Data Type Catalog: Logger Server wasn't found" ) }
97             catch(...){ MESSAGE( "Data Type Catalog: Unknown exception" ) }
98             if (!CORBA::is_nil(object))
99               log = SALOME_Logger::Logger::_narrow(object);
100             if (!CORBA::is_nil(log)){
101               MESSAGE( "Data Type Catalog: Logger Server was found" )
102                 log->ping();
103               DATA_TYPE_CATALOG=1;
104                   break;
105             }
106             
107           }}
108     }
109     if ((DATA_TYPE_CATALOG==1)||((EnvL==0)&&(!CORBA::is_nil(inc))))
110       break;
111             }
112
113   //
114   // Active catalog
115
116   SALOME_DataTypeCatalogImpl* Catalogue_i = new SALOME_DataTypeCatalogImpl(argc, argv);
117   poa->activate_object (Catalogue_i);
118
119   mgr->activate();
120
121   
122   CORBA::Object_ptr myCata = Catalogue_i->_this();
123
124   // initialise Naming Service
125   SALOME_NamingService *_NS;
126   _NS = new SALOME_NamingService(orb);
127   // register Catalog in Naming Service
128   _NS->Register(myCata ,"/Kernel/DataTypeCatalog");
129
130   MESSAGE("Running DataType Catalog Server.")
131
132   orb->run();
133  
134   poa->destroy(1,1);
135  
136  }
137     catch(CORBA::SystemException&) {
138     INFOS("Caught CORBA::SystemException.")
139   }
140     catch(CORBA::Exception&) {
141     INFOS("Caught CORBA::Exception.")
142   }
143
144   return 0;
145 }