]> SALOME platform Git repositories - modules/kernel.git/blob - src/SALOMEDS/SALOMEDS_Server.cxx
Salome HOME
Updated SALOME Kernel sources for building under Ms Visual .NET on Windows platform.
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_Server.cxx
1 //  SALOME SALOMEDS : data structure of SALOME and sources of Salome data server 
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   : SALOMEDS_Server.cxx
25 //  Author : Yves FRICAUD
26 //  Module : SALOME
27 //  $Header$
28
29 #include <SALOMEconfig.h>
30 #include CORBA_SERVER_HEADER(SALOMEDS)
31
32 #include "SALOMEDS_StudyManager_i.hxx"
33 #include "utilities.h"
34 #include "Utils_SINGLETON.hxx"
35 #include "SALOME_NamingService.hxx"
36
37 #ifdef CHECKTIME
38 #include <Utils_Timer.hxx>
39 #endif
40 using namespace std;
41
42 // extern "C"
43 // { // for ccmalloc memory debug
44 // void ccmalloc_static_initialization(void);
45 // }
46
47 ///////////////////////////// MAIN ///////////////////////////////////////
48 //////////////////////////////////////////////////////////////////////////
49 int main(int argc, char** argv)
50 {
51   //   ccmalloc_static_initialization();
52
53   MESSAGE("SALOMEDS_Server - main");
54   try 
55     {
56       // Initialise the ORB.
57 #if OMNIORB_VERSION >= 4
58       const char* options[][2] = { { "giopMaxMsgSize", "104857600" }, { 0, 0 } };
59       CORBA::ORB_var orb = CORBA::ORB_init( argc , argv , "omniORB4", options) ;
60 #else
61       CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB3");
62       omniORB::MaxMessageSize(100 * 1024 * 1024);
63 #endif      
64       // Obtain a reference to the root POA.
65       long TIMESleep = 500000000;
66       int NumberOfTries = 40;
67       int a;
68       timespec ts_req;
69       ts_req.tv_nsec=TIMESleep;
70       ts_req.tv_sec=0;
71       timespec ts_rem;
72       ts_rem.tv_nsec=0;
73       ts_rem.tv_sec=0;
74       CosNaming::NamingContext_var inc;
75       PortableServer::POA_var poa;
76       CORBA::Object_var theObj;
77       CORBA::Object_var obj;
78       CORBA::Object_var object;
79       int SALOMEDS=0;
80       const char * Env = getenv("USE_LOGGER");
81       int EnvL =0;
82       if ((Env!=NULL) && (strlen(Env)))
83         EnvL=1;
84       CosNaming::Name name;
85       name.length(1);
86       name[0].id=CORBA::string_dup("Logger");    
87       PortableServer::POAManager_var pman; 
88       for (int i = 1; i<=NumberOfTries; i++)
89         {
90           if (i!=1) 
91 #ifndef WNT
92             a=nanosleep(&ts_req,&ts_rem);
93 #else
94                 Sleep(TIMESleep/1000000);
95 #endif
96           try
97             { 
98               obj = orb->resolve_initial_references("RootPOA");
99               if(!CORBA::is_nil(obj))
100                 poa = PortableServer::POA::_narrow(obj);
101               if(!CORBA::is_nil(poa))
102                 pman = poa->the_POAManager();
103               if(!CORBA::is_nil(orb)) 
104                 theObj = orb->resolve_initial_references("NameService"); 
105               if (!CORBA::is_nil(theObj)){
106                 inc = CosNaming::NamingContext::_narrow(theObj);
107                 if(!CORBA::is_nil(inc))
108                   {
109                     MESSAGE( "SalomeDS Server: Naming Service was found" );
110                     if(EnvL==1)
111                       {
112                         CORBA::ORB_var orb1 = CORBA::ORB_init(argc,argv) ;
113                         SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance() ;
114                         NS.init_orb( orb1 ) ;
115                         for(int j=1; j<=NumberOfTries; j++)
116                           {
117                             if (j!=1) 
118 #ifndef WNT
119                               a=nanosleep(&ts_req, &ts_rem);
120 #else
121                               Sleep(TIMESleep/1000000);
122 #endif
123                             try
124                               {
125                                 object = inc->resolve(name);
126                               }
127                             catch(CosNaming::NamingContext::NotFound)
128                               { 
129                                 MESSAGE( "SalomeDS Server: Logger Server wasn't found" ); }
130
131                             catch(...)
132                               {
133                                 MESSAGE( "SalomeDS Server: Unknown exception" );
134                               }
135                             if (!CORBA::is_nil(object))
136                               {
137                                 MESSAGE( "SalomeDS Server: Logger Server was found" );
138                                 SALOMEDS=1;
139                                 break;
140                               }
141                           }
142                       }
143                   }
144               }
145         
146             }
147           catch( const SALOME_Exception &ex )
148             {
149               MESSAGE( "Communication Error : " << ex.what() );
150               return EXIT_FAILURE ;
151             }
152           if ((SALOMEDS==1)||((EnvL==0)&&(!CORBA::is_nil(inc))))
153             break;
154         }
155     
156       // We allocate the objects on the heap.  Since these are reference
157       // counted objects, they will be deleted by the POA when they are no
158       // longer needed.    
159       SALOMEDS_StudyManager_i * myStudyManager_i = new  SALOMEDS_StudyManager_i(orb,poa);
160  
161       // Activate the objects.  This tells the POA that the objects are
162       // ready to accept requests.
163       PortableServer::ObjectId_var myStudyManager_iid = poa->activate_object(myStudyManager_i);
164       myStudyManager_i->register_name("/myStudyManager");
165        
166       // Obtain a POAManager, and tell the POA to start accepting
167       // requests on its objects.
168       pman = poa->the_POAManager();
169       pman->activate();
170
171 #ifdef CHECKTIME
172       Utils_Timer timer;
173       timer.Start();
174       timer.Stop();
175       MESSAGE("SALOME_Registry_Server.cxx - orb->run()");
176       timer.ShowAbsolute();
177 #endif
178       orb->run();
179       orb->destroy();
180     }
181   catch(CORBA::SystemException&)
182     {
183       MESSAGE( "Caught CORBA::SystemException." );
184     }
185   catch(CORBA::Exception&)
186     {
187       MESSAGE( "Caught CORBA::Exception." );
188     }
189   catch(omniORB::fatalException& fe)
190     {
191       MESSAGE( "Caught omniORB::fatalException:" );
192       MESSAGE( "  file: " << fe.file() );
193       MESSAGE( "  line: " << fe.line() );
194       MESSAGE( "  mesg: " << fe.errmsg() );
195     }
196   catch(...) 
197     {
198       MESSAGE( "Caught unknown exception." );
199     }
200   return 0;
201 }