Re: ORBit2 Naming Service.
- From: Chris Wareham <chris wareham iosystems co uk>
- To: Chris Roberts <croberts bongle co uk>
- Cc: orbit-list gnome org
- Subject: Re: ORBit2 Naming Service.
- Date: Thu, 12 Jun 2003 09:59:12 +0100
Chris Roberts wrote:
>
> I'm looking for some help with the CORBA/ORBit2 Naming Service, and I'm
> really stuck, I think this is probably a FAQ, but I've googled until my
> fingers are bleeding, and I just can't find any good material or answers
> that work.
>
I've converted a number of client programs from MICO (which uses the C++
binding) to ORBit. These use the Naming Service to locate their objects.
> Basically, my server does a few calls:
>
> CosNaming_NamingContext root_name;
> CosNaming_NameComponent name_component[2] = {{"RMP", "subcontext"},
> {"Types", "server"}};
> CosNaming_Name name = {2, 2, name_component, CORBA_FALSE};
>
>
> root_name = CORBA_ORB_resolve_initial_references(orb, "NameService",
> ev);
> if (raised_exception(ev))
> return;
>
>
> CosNaming_NamingContext_bind(root_name, &name, service, ev);
> if (raised_exception(ev))
> return;
>
>
I have a utility function that registers objects in the server:
void
register_object(char *id, char *kind, PortableServer_Servant *obj)
{
CORBA_Environment ev;
PortableServer_ObjectId *oid;
CORBA_Object ref;
CosNaming_NameComponent name_components[1];
CosNaming_Name name = { 1, 1, name_components, CORBA_FALSE };
CORBA_exception_init(&ev);
oid = PortableServer_POA_activate_object(rootpoa, obj, &ev);
ref = PortableServer_POA_id_to_reference(rootpoa, oid, &ev);
CORBA_free(oid);
name_components[0].id = id;
name_components[0].kind = kind;
CosNaming_NamingContext_bind(nameservice, &name, ref, &ev);
if (ev._major != CORBA_NO_EXCEPTION)
fprintf(stderr, "bind: %s\n", CORBA_exception_id(&ev));
CORBA_exception_free(&ev);
}
>
> and my client does what I believe is the opposite:
> CosNaming_NamingContext root_name;
> CosNaming_NameComponent name_component[2] = {{"RMP", "subcontext"},
> {"Types", "server"}};
> CosNaming_Name name = {2, 2, name_component, CORBA_FALSE};
> CORBA_Object obj;
>
> root_name = CORBA_ORB_resolve_initial_references(orb, "NameService",
> ev);
> if (raised_exception(ev))
> return;
>
> obj = CosNaming_NamingContext_resolve(root_name,
> &name,
> ev);
>
> if (raised_exception(ev))
> return;
And my clients resolve their objects using the following:
CORBA_Object
get_object(char *id, char *kind)
{
CosNaming_NameComponent name_components[1];
CosNaming_Name name = { 1, 1, name_components, CORBA_FALSE };
CORBA_Environment ev;
CORBA_Object obj;
name_components[0].id = id;
name_components[0].kind = kind;
CORBA_exception_init(&ev);
obj = CosNaming_NamingContext_resolve(naming_context, &name, &ev);
if (ev._major != CORBA_NO_EXCEPTION)
obj = CORBA_OBJECT_NIL;
CORBA_exception_free(&ev);
return obj;
}
How I get the naming_context object is shown in the full example at the
end of my post.
>
> What else, beyond this do I need to do to get my client to work? The
> rest of the CORBA initialisation on both sides seems to go fine, however
> no matter whether the server is running or not, on the client, I get a:
> ** ERROR **: IDL:omg.org/CORBA/INV_OBJREF:1.0
>
> Now, from what I've read, I may or may not need to start
> orbit-name-service, and may or may not need to pass the client and
> server IOR's of orbit-name-service? Everything else seems to work except
> this CosNaming part, and it seems to be a FAQ, but everything I've tried
> doesn't seem to work :(
>
I'm still in the process of porting the server side of my system to
ORBit, but the clients have been ported and work fine with a MICO
backend. Eventually, my client programs will read the initial IOR from a
webserver - libghttp will be used for that. For now the clients expect
the IOR to be passed on the command line.
The orbit-name-server has been removed in ORBit2, I'm hoping this means
that I just have to link my server against the libname-server2.a library
and it will then act as both name server and CORBA server. Perhaps one
of the ORBit hackers could enlighten both of us on that point!
The only documentation that I could find on the Naming Service was the
"GNOME and CORBA" book on the GNOME website. This I cross referenced
with some of the examples that come with ORBit (notably the POA ones).
I've included the complete source to a simple client below. The object
methods "read_keyed" and "read_seq" simply read through a succession of
records stored on the server.
#include <stdio.h>
#include <orbit/orbit.h>
#include <ORBitservices/CosNaming.h>
#include "base.h"
#include "client.h"
static CORBA_ORB orb;
static CosNaming_NamingContext naming_context;
static void read_clients(void);
static CORBA_Object get_object(char *, char *);
int
main(int argc, char *argv[])
{
CORBA_Environment ev;
if (argc != 2) {
fprintf(stderr, "Usage: client_dialog <ior>\n");
return 1;
}
fprintf(stderr, "Initialising ORB and Naming Context\n");
CORBA_exception_init(&ev);
orb = CORBA_ORB_init(&argc, argv, "orbit-local-orb", &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
fprintf(stderr, "Unable to initialise ORB\n");
return 1;
}
naming_context = CORBA_ORB_string_to_object(orb, argv[1], &ev);
if (CORBA_Object_is_nil(naming_context, &ev)) {
fprintf(stderr, "Unable to initialise the Naming Service\n");
return 1;
}
read_clients();
CORBA_free(naming_context);
CORBA_ORB_shutdown(orb, FALSE, &ev);
CORBA_ORB_destroy(orb, &ev);
CORBA_exception_free(&ev);
return 0;
}
void
read_clients(void)
{
CORBA_Environment ev;
CORBA_Object client_code;
WcsCorba_READ_PTR *read_ptr;
WcsCorba_CLIENT_RECORD *client_record;
CORBA_boolean status;
fprintf(stderr, "Looking up client_code object\n");
CORBA_exception_init(&ev);
client_code = get_object("client_code", "");
if (CORBA_Object_is_nil(client_code, &ev)) {
CORBA_exception_free(&ev);
return;
}
status = WcsCorba_client_code_read_keyed(client_code, &read_ptr, "",
"", &client_record, &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
CORBA_Object_release(client_code, &ev);
CORBA_exception_free(&ev);
return;
}
while (status && ev._major == CORBA_NO_EXCEPTION) {
fprintf(stderr, "Client %s %s\n", client_record->client_code,
client_record->description);
CORBA_free(client_record);
status = WcsCorba_client_code_read_seq(client_code, read_ptr,
&client_record, &ev);
}
CORBA_free(read_ptr);
CORBA_Object_release(client_code, &ev);
CORBA_exception_free(&ev);
}
CORBA_Object
get_object(char *id, char *kind)
{
CosNaming_NameComponent name_components[1];
CosNaming_Name name = { 1, 1, name_components, CORBA_FALSE };
CORBA_Environment ev;
CORBA_Object obj;
name_components[0].id = id;
name_components[0].kind = kind;
CORBA_exception_init(&ev);
obj = CosNaming_NamingContext_resolve(naming_context, &name, &ev);
if (ev._major != CORBA_NO_EXCEPTION)
obj = CORBA_OBJECT_NIL;
CORBA_exception_free(&ev);
return obj;
}
Chris
--
chris.wareham@iosystems.co.uk (work)
chris.wareham@btopenworld.com (home)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]