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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
22 // File : LocalTrace_WaitForServerReadiness.cxx
23 // Author : Paul RASCLE (EDF)
27 #include "LocalTrace_WaitForServerReadiness.hxx"
33 // ============================================================================
35 * Wait until a server is registered in naming service.
36 * \param serverName name of the server to find.
37 * When SALOME_NamingService is available,
38 * use NamingService_WaitForServerReadiness instead.
39 * This function is needed when macro MESSAGE used by SALOME_NamingService
40 * is not available (inside LocalTrace methods, for instance !).
41 * Direct access to CORBA Name Service. Look for serverName at Name service
42 * Root without extensions.
44 // ============================================================================
46 CORBA::Object_ptr LocalTrace_WaitForServerReadiness(CORBA::ORB_ptr orb,
49 long TIMESleep = 250000000;
50 int NumberOfTries = 40;
53 ts_req.tv_nsec=TIMESleep;
59 CORBA::Object_var obj;
63 // NB. You can't use SALOME_NamingService class because
64 // it uses MESSAGE macro
65 // Otherwise, you will get segmentation fault.
67 CosNaming::NamingContext_var inc;
70 name[0].id = CORBA::string_dup(serverName.c_str());
71 CORBA::Object_var theObj;
73 for (int itry=0; itry < NumberOfTries; itry++)
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);
82 catch( CORBA::COMM_FAILURE& )
84 cout << "LocalTrace_WaitForServerReadiness: "
85 << "CORBA::COMM_FAILURE: "
86 << "Unable to contact the Naming Service" << endl;
90 cout << "LocalTrace_WaitForServerReadiness: "
91 << "Unknown exception dealing with Naming Service" << endl;
94 if(!CORBA::is_nil(inc))
96 obj = inc->resolve(name);
97 if (!CORBA::is_nil(obj))
99 cout << "LocalTrace_WaitForServerReadiness: "
100 << serverName << " found in CORBA Name Service" << endl;
104 int a = nanosleep(&ts_req,&ts_rem);
105 cout << "LocalTrace_WaitForServerReadiness: retry look for"
106 << serverName << endl;
109 catch (const CosNaming::NamingContext::NotFound&)
111 cout << "Caught exception: Naming Service can't found Logger";
113 catch (CORBA::COMM_FAILURE&)
115 cout << "Caught CORBA::SystemException CommFailure.";
117 catch (CORBA::SystemException&)
119 cout << "Caught CORBA::SystemException.";
121 catch (CORBA::Exception&)
123 cout << "Caught CORBA::Exception.";
127 cout << "Caught unknown exception.";