[omniORB] Resolving Names.

Duncan Grisby dgrisby@uk.research.att.com
Wed, 16 Jan 2002 16:21:41 +0000


On Wednesday 16 January, =?iso-8859-1?Q?=D3scar?= Rafael de la Cruz =?iso-8859-1?Q?S=E1nchez?= de la Plaza wrote:

> I would like to have two utilities to work with the Naming Service. It
> would be interesting to have two utility functions:
> 
> - One receiving a name in format
> "context/subcontext1/subtontext2/.../object" and a CORBA::Object_ptr.
> The funcion binds the object reference received with the given name.
> - The other one receiving a name (in the same format) and returning an
> object reference if it exists.

The standard CosNaming::NamingContextExt interface almost does what
you want:

  interface NamingContextExt : NamingContext {
    ...
    Name        to_name(in StringName sn) raises(InvalidName);
    ...
    Object      resolve_str(in StringName n)
      raises(NotFound, CannotProceed, InvalidName, AlreadyBound);
  };

resolve_str() does the second of your wishes; to bind an object, you
need two calls:

  Name_var name = nc->to_name("path/to/object");
  nc->bind(name, obj);

Unfortunately, the to_name() call involves a remote call to the Naming
service. You can avoid it with the omniORB-specific:

  Name_var name = omniURI::stringToName("path/to/object");
  nc->bind(name, obj);

Cheers,

Duncan.

-- 
 -- Duncan Grisby  \  Research Engineer  --
  -- AT&T Laboratories Cambridge          --
   -- http://www.uk.research.att.com/~dpg1 --