]> SALOME platform Git repositories - modules/yacs.git/blob - src/RessourcesCatalog/SALOME_RessourcesCatalog_Server.cxx
Salome HOME
8ea3a1a227c6851127356857aaae9d8469a234d9
[modules/yacs.git] / src / RessourcesCatalog / SALOME_RessourcesCatalog_Server.cxx
1 //  SALOME RessourcesCatalog : implementation of catalog resources parsing (SALOME_ModuleCatalog.idl)
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_RessourcesCatalog_Server.cxx
25 //  Author : Estelle Deville
26 //  Module : SALOME
27 //  $Header$
28
29 #include <iostream>
30 #include "SALOME_NamingService.hxx"
31 #include "SALOME_RessourcesCatalog_impl.hxx"
32 #include "utilities.h"
33 #include "Utils_SINGLETON.hxx"
34 using namespace std;
35
36 int main(int argc,char **argv)
37 {
38   // initialize the ORB
39   CORBA::ORB_ptr orb = CORBA::ORB_init (argc, argv);
40   try
41     {
42       CosNaming::NamingContext_var _rootContext, catalogContext;
43
44       // initialize POA
45       //
46       long TIMESleep = 250000000;
47       int NumberOfTries = 40;
48       int a;
49       timespec ts_req;
50       ts_req.tv_nsec=TIMESleep;
51       ts_req.tv_sec=0;
52       timespec ts_rem;
53       ts_rem.tv_nsec=0;
54       ts_rem.tv_sec=0;
55       CosNaming::NamingContext_var inc;
56       PortableServer::POA_var poa;
57       CORBA::Object_var theObj;
58       CORBA::Object_var obj;
59       CORBA::Object_var object;
60       SALOME_NamingService &naming = *SINGLETON_<SALOME_NamingService>::Instance() ;
61       int RESSOURCES_CATALOG=0;
62       const char * Env = getenv("USE_LOGGER");
63       int EnvL =0;
64       if ((Env!=NULL) && (strlen(Env)))
65         EnvL=1;
66       CosNaming::Name name;
67       name.length(1);
68       name[0].id=CORBA::string_dup("Logger");    
69       PortableServer::POAManager_var mgr; 
70       for (int i = 1; i<=NumberOfTries; i++)
71         {
72           if (i!=1) 
73 #ifndef WNT
74             a=nanosleep(&ts_req,&ts_rem);
75 #else
76             Sleep(TIMESleep/1000000);
77 #endif
78           try
79             { 
80               obj = orb->resolve_initial_references("RootPOA");
81               if(!CORBA::is_nil(obj))
82                 poa = PortableServer::POA::_narrow(obj);
83               if(!CORBA::is_nil(poa))
84                 mgr = poa->the_POAManager();
85               if(!CORBA::is_nil(orb)) 
86                 theObj = orb->resolve_initial_references("NameService");
87               if (!CORBA::is_nil(theObj))
88                 inc = CosNaming::NamingContext::_narrow(theObj);
89             }
90           catch( CORBA::SystemException& )
91             {
92               INFOS( "Ressources Catalog: CORBA::SystemException: Unable to contact the Naming Service" );
93             }
94           if(!CORBA::is_nil(inc)) 
95             {
96               MESSAGE( "Ressources Catalog: Naming Service was found" );
97               if(EnvL==1)
98                 {
99                   for(int j=1; j<=NumberOfTries; j++)
100                     {
101                       if (j!=1) 
102 #ifndef WNT
103                         a=nanosleep(&ts_req, &ts_rem);
104 #else
105                     Sleep(TIMESleep/1000000);
106 #endif
107                       try{
108                         object = inc->resolve(name);
109                       }
110                       catch(CosNaming::NamingContext::NotFound)
111                         { 
112                           INFOS( "Ressources Catalog: Logger Server wasn't found" );
113                         }
114                       catch(...)
115                         { 
116                           INFOS( "Ressources Catalog: Unknown exception" );
117                         }
118                       if (!CORBA::is_nil(object))
119                         {
120                           MESSAGE( "Ressources Catalog: Loger Server was found" );
121                           RESSOURCES_CATALOG=1;
122                           break;
123                         }
124                     }
125                 }
126             }
127           if ((RESSOURCES_CATALOG==1)||((EnvL==0)&&(!CORBA::is_nil(inc))))
128             break;
129         }
130
131       // Active catalog
132   
133       SALOME_RessourcesCatalogImpl* Catalogue_i = new SALOME_RessourcesCatalogImpl(argc, argv);
134       poa->activate_object (Catalogue_i);
135       mgr->activate();
136       CORBA::Object_ptr myCata = Catalogue_i->_this();
137
138       // initialise Naming Service
139       SALOME_NamingService *_NS;
140       _NS = new SALOME_NamingService(orb);
141       // register Catalog in Naming Service
142       _NS->Register(myCata ,"/Kernel/RessourcesCatalog");
143
144       MESSAGE("Running Ressources Catalog Server.")
145
146         orb->run();
147  
148       poa->destroy(1,1);
149  
150     }
151   catch(CORBA::SystemException&) {
152     INFOS("Caught CORBA::SystemException.")
153       }
154   catch(CORBA::Exception&) {
155     INFOS("Caught CORBA::Exception.")
156       }
157
158   //  delete myThreadTrace;
159   return 0;
160 }