-// Copyright (C) 2004 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+// Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
// File : TraceCollector_WaitForServerReadiness.cxx
// Author : Paul RASCLE (EDF)
// Module : KERNEL
// $Header$
-
+//
#include "TraceCollector_WaitForServerReadiness.hxx"
+#include "KernelBasis.hxx"
+#include "SALOME_Fake_NamingService.hxx"
+#include "OpUtil.hxx"
#include <iostream>
#include <ctime>
+#include <memory>
-using namespace std;
+
+#if defined(WIN32) && defined(_MSC_VER) && _MSC_VER < 1900
+#include <omnithread/pthread_nt.h>
+#endif
// ============================================================================
/*!
*/
// ============================================================================
-CORBA::Object_ptr TraceCollector_WaitForServerReadiness(CORBA::ORB_ptr orb,
- string serverName)
+CORBA::Object_ptr TraceCollector_WaitForServerReadiness(const std::string& serverName)
{
long TIMESleep = 500000000;
int NumberOfTries = 40;
ts_rem.tv_nsec=0;
ts_rem.tv_sec=0;
+ CORBA::ORB_var orb = KERNEL::GetRefToORB();
CORBA::Object_var obj;
try
// NB. You can't use SALOME_NamingService class because
// it uses MESSAGE macro
// Otherwise, you will get segmentation fault.
+ if(getSSLMode())
+ {
+ std::string regName(std::string("/")+serverName);
+ std::unique_ptr<SALOME_Fake_NamingService> ns(new SALOME_Fake_NamingService);
+ for (int itry=0; itry < NumberOfTries; itry++)
+ {
+ obj = ns->Resolve(regName.c_str());
+ if(!CORBA::is_nil(obj))
+ break;
+ #ifndef WIN32
+ nanosleep(&ts_req,&ts_rem);
+ #else
+ Sleep(TIMESleep / 1000000);
+ #endif
+ }
+ }
+ else
+ {
+ CosNaming::NamingContext_var inc;
+ CosNaming::Name name;
+ name.length(1);
+ name[0].id = CORBA::string_dup(serverName.c_str());
+ CORBA::Object_var theObj=CORBA::Object::_nil();
- CosNaming::NamingContext_var inc;
- CosNaming::Name name;
- name.length(1);
- name[0].id = CORBA::string_dup(serverName.c_str());
- CORBA::Object_var theObj=CORBA::Object::_nil();
-
- for (int itry=0; itry < NumberOfTries; itry++)
- {
- try
- {
- if(!CORBA::is_nil(orb))
- theObj = orb->resolve_initial_references("NameService");
- if (!CORBA::is_nil(theObj))
- inc = CosNaming::NamingContext::_narrow(theObj);
- }
- catch( CORBA::COMM_FAILURE& )
- {
- cout << "TraceCollector_WaitForServerReadiness: "
- << "CORBA::COMM_FAILURE: "
- << "Unable to contact the Naming Service" << endl;
- }
- catch(...)
- {
- cout << "TraceCollector_WaitForServerReadiness: "
- << "Unknown exception dealing with Naming Service" << endl;
- }
-
- obj=CORBA::Object::_nil();
- if(!CORBA::is_nil(inc))
- {
- try
- {
- obj = inc->resolve(name);
- if (!CORBA::is_nil(obj))
- {
- cout << "TraceCollector_WaitForServerReadiness: "
- << serverName << " found in CORBA Name Service" << endl;
- break;
- }
- }
- catch (const CosNaming::NamingContext::NotFound&)
- {
- cout << "Caught exception: Naming Service can't found Logger";
- }
- }
- int a = nanosleep(&ts_req,&ts_rem);
- cout << "TraceCollector_WaitForServerReadiness: retry look for"
- << serverName << endl;
- }
+ for (int itry=0; itry < NumberOfTries; itry++)
+ {
+ try
+ {
+ if(!CORBA::is_nil(orb))
+ theObj = orb->resolve_initial_references("NameService");
+ if (!CORBA::is_nil(theObj))
+ inc = CosNaming::NamingContext::_narrow(theObj);
+ }
+ catch( CORBA::SystemException& )
+ {
+ std::cout << "TraceCollector_WaitForServerReadiness: "
+ << "CORBA::SystemException: "
+ << "Unable to contact the Naming Service" << std::endl;
+ }
+ catch(...)
+ {
+ std::cout << "TraceCollector_WaitForServerReadiness: "
+ << "Unknown exception dealing with Naming Service" << std::endl;
+ }
+
+ obj=CORBA::Object::_nil();
+ if(!CORBA::is_nil(inc))
+ {
+ try
+ {
+ obj = inc->resolve(name);
+ if (!CORBA::is_nil(obj))
+ {
+ //cout << "TraceCollector_WaitForServerReadiness: "
+ // << serverName << " found in CORBA Name Service" << endl;
+ break;
+ }
+ }
+ catch (const CosNaming::NamingContext::NotFound&)
+ {
+ std::cout << "Caught exception: Naming Service can't found Logger";
+ }
+ }
+ #ifndef WIN32
+ nanosleep(&ts_req,&ts_rem);
+ #else
+ Sleep(TIMESleep / 1000000);
+ #endif
+ std::cout << "TraceCollector_WaitForServerReadiness: retry look for"
+ << serverName << std::endl;
+ }
+ }
}
catch (const CosNaming::NamingContext::NotFound&)
{
- cout << "Caught exception: Naming Service can't found Logger";
+ std::cout << "Caught exception: Naming Service can't found Logger";
}
catch (CORBA::COMM_FAILURE&)
{
- cout << "Caught CORBA::SystemException CommFailure.";
+ std::cout << "Caught CORBA::SystemException CommFailure.";
}
catch (CORBA::SystemException&)
{
- cout << "Caught CORBA::SystemException.";
+ std::cout << "Caught CORBA::SystemException.";
}
catch (CORBA::Exception&)
{
- cout << "Caught CORBA::Exception.";
+ std::cout << "Caught CORBA::Exception.";
}
catch (...)
{
- cout << "Caught unknown exception.";
+ std::cout << "Caught unknown exception.";
}
return obj._retn();
}