Salome HOME
This commit was generated by cvs2git to create tag 'V1_4_0b1'.
[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 #include <iostream.h>
30 #include "SALOME_NamingService.hxx"
31 #include "SALOME_DataTypeCatalog_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   try 
39     {
40       CosNaming::NamingContext_var _rootContext, catalogContext;
41       // initialize the ORB
42       CORBA::ORB_ptr orb = CORBA::ORB_init (argc, argv);
43       // initialize POA
44       //
45       long TIMESleep = 250000000;
46       int NumberOfTries = 40;
47       int a;
48       timespec ts_req;
49       ts_req.tv_nsec=TIMESleep;
50       ts_req.tv_sec=0;
51       timespec ts_rem;
52       ts_rem.tv_nsec=0;
53       ts_rem.tv_sec=0;
54       CosNaming::NamingContext_var inc;
55       PortableServer::POA_var poa;
56       CORBA::Object_var theObj;
57       CORBA::Object_var obj;
58       CORBA::Object_var object;
59       int DATA_TYPE_CATALOG=0;
60       const char * Env = getenv("USE_LOGGER"); 
61       int EnvL =0;
62       if ((Env!=NULL) && (strlen(Env)))
63         EnvL=1;  
64       CosNaming::Name name;
65       name.length(1);
66       name[0].id=CORBA::string_dup("Logger");    
67       PortableServer::POAManager_var mgr; 
68  
69       for (int i = 1; i<=NumberOfTries; i++)
70         {
71           if (i!=1) 
72             a=nanosleep(&ts_req,&ts_rem);
73           try
74             { 
75               obj = orb->resolve_initial_references("RootPOA");
76               if(!CORBA::is_nil(obj))
77                 poa = PortableServer::POA::_narrow(obj);
78               if(!CORBA::is_nil(poa))
79                 mgr = poa->the_POAManager();
80               if(!CORBA::is_nil(orb)) 
81                 theObj = orb->resolve_initial_references("NameService");
82               if (!CORBA::is_nil(theObj))
83                 inc = CosNaming::NamingContext::_narrow(theObj);}
84           catch( CORBA::COMM_FAILURE& )
85             {
86               MESSAGE( "Data Type Catalog: CORBA::COMM_FAILURE: Unable to contact the Naming Service" );
87             }
88           if(!CORBA::is_nil(inc))
89             {
90               MESSAGE( "Data Type Catalog: Naming Service was found" );
91               if(EnvL==1)
92                 {
93                   CORBA::ORB_var orb1 = CORBA::ORB_init(argc,argv) ;
94                   SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance() ;
95                   NS.init_orb( orb1 ) ;
96                   for(int j=1; j<=NumberOfTries; j++)
97                     {
98                       if (j!=1) 
99                         a=nanosleep(&ts_req, &ts_rem);
100                       try
101                         {
102                           object = inc->resolve(name);
103                         }
104                       catch(CosNaming::NamingContext::NotFound)
105                         {
106                           MESSAGE( "Data Type Catalog: Logger Server wasn't found" );
107                         }
108                       catch(...)
109                         {
110                           MESSAGE( "Data Type Catalog: Unknown exception" );
111                         }
112                       if (!CORBA::is_nil(object))
113                         {
114                           MESSAGE( "Data Type Catalog: Logger Server was found" );
115                           DATA_TYPE_CATALOG=1;
116                           break;
117                         }
118             
119                     }
120                 }
121             }
122           if ((DATA_TYPE_CATALOG==1)||((EnvL==0)&&(!CORBA::is_nil(inc))))
123             break;
124         }
125
126       // Active catalog
127
128       SALOME_DataTypeCatalogImpl* Catalogue_i = new SALOME_DataTypeCatalogImpl(argc, argv);
129       poa->activate_object (Catalogue_i);
130
131       mgr->activate();
132
133   
134       CORBA::Object_ptr myCata = Catalogue_i->_this();
135
136       // initialise Naming Service
137       SALOME_NamingService *_NS;
138       _NS = new SALOME_NamingService(orb);
139       // register Catalog in Naming Service
140       _NS->Register(myCata ,"/Kernel/DataTypeCatalog");
141
142       MESSAGE("Running DataType Catalog Server.")
143
144         orb->run();
145  
146       poa->destroy(1,1);
147  
148     }
149   catch(CORBA::SystemException&) {
150     INFOS("Caught CORBA::SystemException.")
151       }
152   catch(CORBA::Exception&) {
153     INFOS("Caught CORBA::Exception.")
154       }
155
156   return 0;
157 }