[omniORB] Testing Name Service Existence

Matthew Berry Matthew.Berry@aspentech.com
Fri Jul 26 11:43:00 2002


Hi,

I am writing a configuration application and want to test whether the user
has entered a valid naming service configuration. I am using the code below
to perform the test. Is it a "good" way of doing things? Will it always
work? If not, can you suggest a better way?

Many thanks
Matthew


bool testConfig(const char* host, long port)
{
  // Exception-handling left out
  char ref[100];
  sprintf(ref, "corbaloc:iiop:%s:%i/NameService", host, port);

  CORBA::Object_var obj = orb->string_to_object(ref);

  // This will invoke _is_a which will call the object
  CosNaming::NamingContext_var context =
CosNaming::NamingContext::_narrow(obj);

  if (!CORBA::is_nil(context))
  {
    return true;
  }

  return false;
}