1 // Copyright (C) 2004 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : TraceCollector_WaitForServerReadiness.cxx
23 // Author : Paul RASCLE (EDF)
27 #include "TraceCollector_WaitForServerReadiness.hxx"
32 #include <omnithread/pthread_nt.h>
37 // ============================================================================
39 * Wait until a server is registered in naming service.
40 * \param serverName name of the server to find.
41 * When SALOME_NamingService is available,
42 * use NamingService_WaitForServerReadiness instead.
43 * This function is needed when macro MESSAGE used by SALOME_NamingService
44 * is not available (inside LocalTrace methods, for instance !).
45 * Direct access to CORBA Name Service. Look for serverName at Name service
46 * Root without extensions.
48 // ============================================================================
50 CORBA::Object_ptr TraceCollector_WaitForServerReadiness(CORBA::ORB_ptr orb,
53 long TIMESleep = 500000000;
54 int NumberOfTries = 40;
57 ts_req.tv_nsec=TIMESleep;
63 CORBA::Object_var obj;
67 // NB. You can't use SALOME_NamingService class because
68 // it uses MESSAGE macro
69 // Otherwise, you will get segmentation fault.
71 CosNaming::NamingContext_var inc;
74 name[0].id = CORBA::string_dup(serverName.c_str());
75 CORBA::Object_var theObj=CORBA::Object::_nil();
77 for (int itry=0; itry < NumberOfTries; itry++)
81 if(!CORBA::is_nil(orb))
82 theObj = orb->resolve_initial_references("NameService");
83 if (!CORBA::is_nil(theObj))
84 inc = CosNaming::NamingContext::_narrow(theObj);
86 catch( CORBA::SystemException& )
88 cout << "TraceCollector_WaitForServerReadiness: "
89 << "CORBA::SystemException: "
90 << "Unable to contact the Naming Service" << endl;
94 cout << "TraceCollector_WaitForServerReadiness: "
95 << "Unknown exception dealing with Naming Service" << endl;
98 obj=CORBA::Object::_nil();
99 if(!CORBA::is_nil(inc))
103 obj = inc->resolve(name);
104 if (!CORBA::is_nil(obj))
106 //cout << "TraceCollector_WaitForServerReadiness: "
107 // << serverName << " found in CORBA Name Service" << endl;
111 catch (const CosNaming::NamingContext::NotFound&)
113 cout << "Caught exception: Naming Service can't found Logger";
117 int a = nanosleep(&ts_req,&ts_rem);
119 Sleep(TIMESleep / 1000000);
121 cout << "TraceCollector_WaitForServerReadiness: retry look for"
122 << serverName << endl;
125 catch (const CosNaming::NamingContext::NotFound&)
127 cout << "Caught exception: Naming Service can't found Logger";
129 catch (CORBA::COMM_FAILURE&)
131 cout << "Caught CORBA::SystemException CommFailure.";
133 catch (CORBA::SystemException&)
135 cout << "Caught CORBA::SystemException.";
137 catch (CORBA::Exception&)
139 cout << "Caught CORBA::Exception.";
143 cout << "Caught unknown exception.";