Re: ORBit-0.5.8 Event Service.



> Do u have any sample releated to
> the Event Service & Naming Service.

I haven't got onto the Event Service yet, but I can tell you how to use
the Naming Service.

Before you start your application that needs the naming service, start the
name server:
	orbit-name-server

The IOR that it prints on stdout needs to be passed as:
	-ORBnamingIOR=<IOR>
as one of the arguments in argv when you call CORBA_ORB_init().

Then you can call:

CosNaming_NamingContext nameserver =
	CORBA_ORB_resolve_initial_references(orb, "NameService", &ev);

to get the nameserver. Once you have a nameserver you can call:

CosNaming_NamingContext_bind(nameserver, name, (CORBA_Object) <object>,
&ev);

where <object> is any object reference to a CORBA object you have created,
and <name> is a CosNaming_Name *. A simple method to create a
CosNaming_Name * from a string is below:

static CosNaming_Name* create_name(const char* name) {
  CosNaming_Name *cos_name;
  CosNaming_NameComponent *cos_name_cmp;
  char *id;
  char *kind;
  char *dummy_kind = "filler";

  /* Allocate a CosNaming::Name (sequence of CosNaming::NameComponent) */
  cos_name = (CosNaming_Name *) malloc (sizeof(CosNaming_Name));
  cos_name->_maximum=1L;
  cos_name->_length=1L;

  /* Relinquish ownership of the NameComponent to the sequence. When
     CORBA_free is called on it later, the NameComponent will be freed */
  CORBA_sequence_set_release(cos_name, FALSE);

  /* Create the naming component.  We don't care about the kind, so
   * we give it a dummy value */
  cos_name_cmp = (CosNaming_NameComponent*)
    malloc(sizeof(CosNaming_NameComponent));

  /* Create id and kind value components. id is the name of our object */
  id = CORBA_string_alloc(strlen(name));
  strcpy(id,name);
  cos_name_cmp->id = id;
  kind=CORBA_string_alloc(strlen(dummy_kind));
  strcpy(kind,dummy_kind);
  cos_name_cmp->kind=kind;

  cos_name->_buffer=cos_name_cmp;

  return cos_name;
}

Hope this helps,
Gareth





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]