RE: Newbie : Event service?
- From: "Verwerft, Marc" <MVerwerft nedcar nl>
- To: "'orbit-list gnome org'" <orbit-list gnome org>
- Subject: RE: Newbie : Event service?
- Date: Fri, 22 Dec 2000 15:24:02 +0100
Okay, here it comes. As you will see, they are based upon the sources that
can be found in the event directory. But be warned, you might have to change
a couple of things.
1. The sources are very simple examples for a push supplier and push
consumer. Only drawback is that they are "customized" for ORBit-0.5.3 with
specific hacks in the orbit kernel to get it to run on VMS under a C++
compiler. This means extra casting in the code which is not necessary for C.
2. I have been following your thread about IOR's with JacORB, so I presume
that will be using this ORB's event service. I used JavaORB (also open
source) which has a special extension : an eventchannelfactory. That gave
me an easy way to create an eventchannel in the eventservice.
First generate the stubs and skeletons from the eventservice idl. Then
customize the examples and link 'em against the stubs skeletons and common
files. Don't forget that even though these programs act only as "clients" of
an eventchannel, they implement real CORBA objects (a supplier and a
consumer).
I use this example as follows :
- I create an eventchannel through javaORB and write out the IOR
- I start up the cllient with the IOR
- I start up the server with the IOR
Good luck, merry X-mas and happy new year,
Marc.
PS. : after today I'm on vacation for 2 weeks. So don't hope on fast
responses from me :-)
-------------------------- eventchannel-consumer.c --------------
#include "CosEventChannel.h"
#include <stdio.h>
#include <stdlib.h>
/* The following is mostly taken from CosEventComm-impl.c as generated by
"orbit-idl -Eskeleton_impl CosEventComm.idl", only the stub
implemementations have been removed and some lines have been added,
those are marked with "added". also all supplier stuff have been removed
*/
/***************************************************************************
/
/* begin of generated part
*/
/***************************************************************************
/
/*** App-specific servant structures ***/
typedef struct {
POA_CosEventComm_PushConsumer servant;
PortableServer_POA poa;
} impl_POA_CosEventComm_PushConsumer;
typedef struct {
POA_CosEventComm_PullConsumer servant;
PortableServer_POA poa;
} impl_POA_CosEventComm_PullConsumer;
/*** Implementation stub prototypes ***/
extern "C" {
static void impl_CosEventComm_PushConsumer__destroy(
//impl_POA_CosEventComm_PushConsumer * servant,
PortableServer_Servant servant,
CORBA_Environment * ev);
void
impl_CosEventComm_PushConsumer_push(
//impl_POA_CosEventComm_PushConsumer * servant,
PortableServer_Servant servant,
const CORBA_any * data,
CORBA_Environment * ev);
void
impl_CosEventComm_PushConsumer_disconnect_push_consumer(impl_POA_CosEventCom
m_PushConsumer * servant,
CORBA_Environment * ev);
static void
impl_CosEventComm_PullConsumer__destroy(impl_POA_CosEventComm_PullConsumer *
servant,
CORBA_Environment * ev);
void
impl_CosEventComm_PullConsumer_disconnect_pull_consumer(
//impl_POA_CosEventComm_PullConsumer * servant,
PortableServer_Servant servant,
CORBA_Environment * ev);
};
/*** epv structures ***/
static PortableServer_ServantBase__epv
impl_CosEventComm_PushConsumer_base_epv =
{
NULL, /* _private data */
& impl_CosEventComm_PushConsumer__destroy, /* finalize routine */
NULL, /* default_POA routine */
};
static POA_CosEventComm_PushConsumer__epv impl_CosEventComm_PushConsumer_epv
=
{
NULL, /* _private */
& impl_CosEventComm_PushConsumer_push,
& impl_CosEventComm_PushConsumer_disconnect_push_consumer,
};
static PortableServer_ServantBase__epv
impl_CosEventComm_PullConsumer_base_epv =
{
NULL, /* _private data */
(gpointer) & impl_CosEventComm_PullConsumer__destroy, /* finalize
routine */
NULL, /* default_POA routine */
};
static POA_CosEventComm_PullConsumer__epv impl_CosEventComm_PullConsumer_epv
=
{
NULL, /* _private */
(gpointer) & impl_CosEventComm_PullConsumer_disconnect_pull_consumer,
};
/*** vepv structures ***/
static POA_CosEventComm_PushConsumer__vepv
impl_CosEventComm_PushConsumer_vepv =
{
&impl_CosEventComm_PushConsumer_base_epv,
&impl_CosEventComm_PushConsumer_epv,
};
static POA_CosEventComm_PullConsumer__vepv
impl_CosEventComm_PullConsumer_vepv =
{
&impl_CosEventComm_PullConsumer_base_epv,
&impl_CosEventComm_PullConsumer_epv,
};
/*
* Subroutines
*/
void Exception( CORBA_Environment *ev)
{
switch (ev->_major)
{
case CORBA_NO_EXCEPTION: return;
case CORBA_SYSTEM_EXCEPTION:
g_printerr ("CORBA system exception.\n");
exit (1);
case CORBA_USER_EXCEPTION:
g_printerr (CORBA_exception_id(ev));
exit(1);
default :
g_printerr ("Unknown value for major exception !!!\n");
exit(1);
}
}
/*** Stub implementations ***/
static CosEventComm_PushConsumer
impl_CosEventComm_PushConsumer__create(PortableServer_POA poa,
CORBA_Environment * ev)
{
CosEventComm_PushConsumer retval;
impl_POA_CosEventComm_PushConsumer *newservant;
PortableServer_ObjectId *objid;
newservant = g_new0(impl_POA_CosEventComm_PushConsumer, 1);
newservant->servant.vepv = &impl_CosEventComm_PushConsumer_vepv;
newservant->poa = poa;
POA_CosEventComm_PushConsumer__init((PortableServer_Servant) newservant,
ev);
objid = PortableServer_POA_activate_object(poa, newservant, ev);
CORBA_free(objid);
retval = PortableServer_POA_servant_to_reference(poa, newservant, ev);
return retval;
}
/* You shouldn't call this routine directly without first deactivating the
servant... */
static void
impl_CosEventComm_PushConsumer__destroy(
//impl_POA_CosEventComm_PushConsumer * servant,
PortableServer_Servant servant, CORBA_Environment * ev)
{
POA_CosEventComm_PushConsumer__fini((PortableServer_Servant) servant,
ev);
g_free(servant);
}
static CosEventComm_PullConsumer
impl_CosEventComm_PullConsumer__create(PortableServer_POA poa,
CORBA_Environment * ev)
{
CosEventComm_PullConsumer retval;
impl_POA_CosEventComm_PullConsumer *newservant;
PortableServer_ObjectId *objid;
newservant = g_new0(impl_POA_CosEventComm_PullConsumer, 1);
newservant->servant.vepv = &impl_CosEventComm_PullConsumer_vepv;
newservant->poa = poa;
POA_CosEventComm_PullConsumer__init((PortableServer_Servant) newservant,
ev);
objid = PortableServer_POA_activate_object(poa, newservant, ev);
CORBA_free(objid);
retval = PortableServer_POA_servant_to_reference(poa, newservant, ev);
return retval;
}
/* You shouldn't call this routine directly without first deactivating the
servant... */
static void
impl_CosEventComm_PullConsumer__destroy(impl_POA_CosEventComm_PullConsumer *
servant, CORBA_Environment * ev)
{
POA_CosEventComm_PullConsumer__fini((PortableServer_Servant) servant,
ev);
g_free(servant);
}
/* This where the magic happens ... */
void
impl_CosEventComm_PushConsumer_push(impl_POA_CosEventComm_PushConsumer *
servant,
const CORBA_any * data,
CORBA_Environment * ev)
{
if (data->_type == TC_str) {
printf("%s", *data->_value);
} else {
printf("Received data of type %d\n", data->_type);
}
CORBA_free(data->_value);
CORBA_free(data);
}
void
impl_CosEventComm_PushConsumer_disconnect_push_consumer(impl_POA_CosEventCom
m_PushConsumer * servant,
CORBA_Environment * ev)
{
}
void
impl_CosEventComm_PullConsumer_disconnect_pull_consumer(impl_POA_CosEventCom
m_PullConsumer * servant,
CORBA_Environment * ev)
{
}
int
main (int argc, char *argv[])
{
CORBA_ORB orb;
CORBA_Environment ev;
CosEventChannelAdmin_EventChannelFactory factory;
CosEventChannelAdmin_EventChannel channel;
CosEventChannelAdmin_ConsumerAdmin consumer_admin;
CosEventChannelAdmin_ProxyPushSupplier push_supplier;
CosEventComm_PushConsumer push_consumer;
PortableServer_POA root_poa;
PortableServer_POAManager pm;
FILE *infile;
char objref_str[2048];
int i;
CORBA_exception_init (&ev);
orb = CORBA_ORB_init (&argc, argv, "orbit-local-orb", &ev);
Exception(&ev);
root_poa = (PortableServer_POA)
CORBA_ORB_resolve_initial_references (orb, "RootPOA", &ev);
Exception(&ev);
pm = PortableServer_POA__get_the_POAManager (root_poa, &ev);
Exception(&ev);
PortableServer_POAManager_activate (pm, &ev);
Exception(&ev);
push_consumer = impl_CosEventComm_PushConsumer__create(root_poa, &ev);
Exception(&ev);
if (strncmp (argv[1], "IOR:", 4) == 0)
strcpy ((char *) objref_str, argv[1]);
else if ((iorf = fopen(argv[1],"r")) != NULL) {
fscanf (iorf, "%s", objref_str);
fclose(iorf);
} else {
printf("Usage : ec-sup ior_of_eventchannel\n");
exit(1);
}
g_strchug ((gchar*) objref_str);
g_strchomp ((gchar *) objref_str);
g_assert (!(strlen ((char *) objref_str) % 2));
channel = CORBA_ORB_string_to_object(orb, objref_str, &ev);
consumer_admin =
CosEventChannelAdmin_EventChannel_for_consumers( channel, &ev );
Exception(&ev);
push_supplier =
CosEventChannelAdmin_ConsumerAdmin_obtain_push_supplier( consumer_admin,
&ev );
Exception(&ev);
CosEventChannelAdmin_ProxyPushSupplier_connect_push_consumer(
push_supplier,
push_consumer,
&ev );
Exception(&ev);
CORBA_ORB_run(orb, &ev);
Exception(&ev);
return 0;
}
----------------------------------------------------------------------------
----------------------------------------------------------------------------
-
-------------------------- eventchannel-supplier.c --------------
#include <stdio.h>
#include <stdlib.h>
#include "coseventchannel.h"
/* #include "coseventcomm.h" */
#include <string.h>
#include <limits.h>
#define IS_EXCEPTION(ev, name) \
(strcmp (CORBA_exception_id (ev), ex_##name) == 0)
typedef struct {
POA_CosEventComm_PushSupplier servant;
PortableServer_POA poa;
} impl_POA_CosEventComm_PushSupplier;
/*
* Prototypes
*/
static void impl_CosEventComm_PushSupplier__destroy(
impl_POA_CosEventComm_PushSupplier * servant,
CORBA_Environment * ev);
void impl_CosEventComm_PushSupplier_disconnect_push_supplier(
// impl_POA_CosEventComm_PushSupplier * servant,
PortableServer_Servant servant,
CORBA_Environment * ev);
/*
* We're implementing a PushSupplier, so we have to setup the structures
* for one.
* A PushSupplier has only one method : disconnect_push_supplier()
*/
/*** epv structures ***/
static POA_CosEventComm_PushSupplier__epv impl_CosEventComm_PushSupplier_epv
=
{
NULL, /* _private */
&impl_CosEventComm_PushSupplier_disconnect_push_supplier
};
static PortableServer_ServantBase__epv
impl_CosEventComm_PushSupplier_base_epv =
{
NULL, /* _private data */
NULL, /* finalize routine */
NULL, /* default_POA routine */
};
/*** vepv structures ***/
static POA_CosEventComm_PushSupplier__vepv
impl_CosEventComm_PushSupplier_vepv =
{
&impl_CosEventComm_PushSupplier_base_epv,
&impl_CosEventComm_PushSupplier_epv,
};
/*
* Subroutines
*/
void Exception( CORBA_Environment *ev)
{
switch (ev->_major)
{
case CORBA_NO_EXCEPTION: return;
case CORBA_SYSTEM_EXCEPTION:
g_printerr ("CORBA system exception.\n");
exit (1);
case CORBA_USER_EXCEPTION:
g_printerr (CORBA_exception_id(ev));
exit(1);
default :
g_printerr ("Unknown value for major exception !!!\n");
exit(1);
}
}
void impl_CosEventComm_PushSupplier_disconnect_push_supplier(
impl_POA_CosEventComm_PushSupplier *servant,
CORBA_Environment *ev)
{
}
/*
* Skeleton set up to create a pushsupplier
*/
CosEventComm_PushSupplier
impl_CosEventComm_PushSupplier__create(
PortableServer_POA poa,
CORBA_Environment *ev)
{
CosEventComm_PushSupplier retval;
impl_POA_CosEventComm_PushSupplier *newservant;
PortableServer_ObjectId *objid;
newservant = g_new0(impl_POA_CosEventComm_PushSupplier, 1);
newservant->servant.vepv = &impl_CosEventComm_PushSupplier_vepv;
newservant->poa = poa;
POA_CosEventComm_PushSupplier__init((PortableServer_Servant) newservant,
ev);
objid = PortableServer_POA_activate_object(poa, newservant, ev);
CORBA_free(objid);
retval = PortableServer_POA_servant_to_reference(poa, newservant, ev);
return retval;
}
main(int argc, char *argv[])
{
CORBA_ORB orb;
CORBA_Environment ev;
FILE *iorf;
int i;
char *str;
guchar objref_str[2048];
CosEventChannelAdmin_EventChannel ec;
CosEventChannelAdmin_SupplierAdmin supadmin;
CosEventChannelAdmin_ProxyPushConsumer proxy_push_con;
CosEventComm_PushSupplier ps;
PortableServer_POA root_poa;
CORBA_any *any;
CORBA_exception_init (&ev);
orb = CORBA_ORB_init (&argc, argv, "orbit-local-orb", &ev);
if (strncmp (argv[1], "IOR:", 4) == 0)
strcpy ((char *) objref_str, argv[1]);
else if ((iorf = fopen(argv[1],"r")) != NULL) {
fscanf (iorf, "%s", objref_str);
fclose(iorf);
} else {
printf("Usage : ec-sup ior_of_eventchannel\n");
exit(1);
}
g_strchug ((gchar*) objref_str);
g_strchomp ((gchar *) objref_str);
g_assert (!(strlen ((char *) objref_str) % 2));
/* Start by resolve the RootPOA */
root_poa = (PortableServer_POA)
CORBA_ORB_resolve_initial_references (orb, "RootPOA", &ev);
/* Then create a PushSupplier */
ps = impl_CosEventComm_PushSupplier__create(root_poa, &ev);
Exception (&ev);
/*
* Use the eventchannel to push data
* Convert object reference to eventchannel object
* get a supplieradmin
* get a proxypushconsumer
* connect the pushsupplier to the proxypushconsumer
* and push data
*/
ec = CORBA_ORB_string_to_object (orb, (CORBA_char *) objref_str, &ev);
Exception (&ev);
supadmin = CosEventChannelAdmin_EventChannel_for_suppliers(ec, &ev);
Exception(&ev);
proxy_push_con =
CosEventChannelAdmin_SupplierAdmin_obtain_push_consumer(supadmin, &ev);
Exception(&ev);
CosEventChannelAdmin_ProxyPushConsumer_connect_push_supplier(proxy_push_con,
ps, &ev);
Exception(&ev);
any = CORBA_any_alloc();
str = (char *) malloc(20);
any->_value = &str;
any->_type = TC_string;
sprintf(str, "-- Start --");
CosEventChannelAdmin_ProxyPushConsumer_push(proxy_push_con, any, &ev);
Exception(&ev);
for (i=0; i< 10; i++) {
sprintf(str, "attempt %d", i);
CosEventChannelAdmin_ProxyPushConsumer_push(proxy_push_con, any, &ev);
Exception(&ev);
}
sprintf(str, "-- End --");
CosEventChannelAdmin_ProxyPushConsumer_push(proxy_push_con, any, &ev);
Exception(&ev);
}
----------------------------------------------------------------------------
----------------------------
> ----------
> From: Alejandro Imass[SMTP:aimass aimass org]
> Reply To: orbit-list gnome org
> Sent: Friday 22 December 2000 14:27
> To: orbit-list gnome org
> Subject: Re: Newbie : Event service?
>
> "Verwerft, Marc" wrote:
>
> > Quote from Wilhelmi :
> > "Believe, the code in src/services/event is just crap."
> > But keep in mind, he refers to the implemenatation of the eventservice
> > itself.
> > I have been using the pushconsumer and pushsupplier stubs for some time
> now
> > without problems.
> > I am using ORBit-0.5.3
> >
> > "Alcohol and calculus don't mix. Don't drink and derive." --Unknown
> >
>
> Do you by any chance have some real simple sample code on using the event
> service in push mode like you state above. I have been trying to locate an
> example as simple as the echo example for the event service but I've had
> no
> luck.
>
> Thanks beforehand and warm regards,
> Alejandro Imass
>
>
> _______________________________________________
> orbit-list mailing list
> orbit-list gnome org
> http://mail.gnome.org/mailman/listinfo/orbit-list
>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]