This appendix presents the miscellaneous programs' code presented in this book.
CFLAGS=-g -Wall
CC=gcc
all: client server
plug.h: plug.idl
orbit-idl ./plug.idl
# build the client. ie: the thing which gives a window to
# display the true GUI
client: socket.o plug-stubs.o plug-common.o plug.h
${CC} ${CFLAGS} `gnome-config --libs gnorba gnomeui` \
socket.o plug-stubs.o plug-common.o -o client
socket.o: socket.c plug.h
${CC} ${CFLAGS} `gnome-config --cflags gnorba` \
-c socket.c -o socket.o
# build the server. ie: the thing which builds the true GUI
server: plug.o plug-skels.o plug-common.o plug.h
${CC} ${CFLAGS} `gnome-config --libs gnorba gnomeui` \
plug.o plug-skels.o plug-common.o -o server
plug.o: plug.c plug.h
${CC} ${CFLAGS} `gnome-config --cflags gnorba` \
-c plug.c -o plug.o
# build stubs/skeletons
plug-skels.o: plug-skels.c plug.h
${CC} ${CFLAGS} `orbit-config --cflags server` \
`gnome-config --cflags gnorba` \
-c plug-skels.c -o plug-skels.o
plug-stubs.o: plug-stubs.c plug.h
${CC} ${CFLAGS} `orbit-config --cflags client` \
`gnome-config --cflags gnorba` \
-c plug-stubs.c -o plug-stubs.o
plug-common.o: plug-common.c plug.h
${CC} ${CFLAGS} `orbit-config --cflags` \
`gnome-config --cflags gnorba` \
-c plug-common.c -o plug-common.o
clean:
rm *.o client server *~ plug-skelimpl.c \
plug-stubs.c plug-common.c plug-skels.c \
plug.h 2>/dev/null |
module view {
interface plug {
void set_window_id (in unsigned long winid);
};
}; |
#include "plug.h"
#include <gnome.h>
#include <libgnorba/gnorba.h>
#include <ORBitservices/CosNaming.h>
/*** App-specific servant structures ***/
typedef struct {
POA_view_plug servant;
PortableServer_POA poa;
GtkWidget *widget;
} impl_POA_view_plug;
/*** Implementation stub prototypes ***/
static void impl_view_plug__destroy(impl_POA_view_plug * servant,
CORBA_Environment * ev);
static void
impl_view_plug_set_window_id(impl_POA_view_plug * servant,
CORBA_unsigned_long winid,
CORBA_Environment * ev);
/*** epv structures ***/
static PortableServer_ServantBase__epv impl_view_plug_base_epv =
{
NULL, /* _private data */
NULL, /* finalize routine */
NULL, /* default_POA routine */
};
static POA_view_plug__epv impl_view_plug_epv =
{
NULL, /* _private */
(gpointer) & impl_view_plug_set_window_id,
};
/*** vepv structures ***/
static POA_view_plug__vepv impl_view_plug_vepv =
{
&impl_view_plug_base_epv,
&impl_view_plug_epv,
};
/*** Stub implementations ***/
static view_plug
impl_view_plug__create(PortableServer_POA poa,
CORBA_Environment * ev)
{
view_plug retval;
impl_POA_view_plug *newservant;
PortableServer_ObjectId *objid;
newservant = g_new0(impl_POA_view_plug, 1);
newservant->servant.vepv = &impl_view_plug_vepv;
newservant->poa = poa;
newservant->widget = gtk_button_new_with_label ("A small button :)");
POA_view_plug__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;
}
static void
impl_view_plug__destroy(impl_POA_view_plug * servant,
CORBA_Environment * ev)
{
PortableServer_ObjectId *objid;
objid = PortableServer_POA_servant_to_id(servant->poa, servant, ev);
PortableServer_POA_deactivate_object(servant->poa, objid, ev);
CORBA_free(objid);
POA_view_plug__fini((PortableServer_Servant) servant, ev);
g_free(servant);
}
static void
impl_view_plug_set_window_id(impl_POA_view_plug * servant,
CORBA_unsigned_long winid,
CORBA_Environment * ev)
{
GtkWidget *window;
window = gtk_plug_new (winid);
gtk_container_add (GTK_CONTAINER(window),
servant->widget);
gtk_widget_show_all (window);
}
int main (int argc, char **argv)
{
CORBA_Environment ev;
CORBA_ORB orb;
PortableServer_POA root_poa;
PortableServer_POAManager root_poa_manager;
CosNaming_NamingContext name_server;
CosNaming_NameComponent name_component[1] =
{{"view_plug","server"}};
CosNaming_Name name =
{1, 1, name_component, CORBA_FALSE};
CORBA_Object obj;
CORBA_exception_init (&ev);
orb = gnome_CORBA_init ("a simple socket client",
"0.1",
&argc,
argv,
GNORBA_INIT_SERVER_FUNC,
&ev);
root_poa = (PortableServer_POA)
CORBA_ORB_resolve_initial_references (orb,
"RootPOA",
&ev);
root_poa_manager = PortableServer_POA__get_the_POAManager (root_poa,
&ev);
PortableServer_POAManager_activate (root_poa_manager, &ev);
obj = impl_view_plug__create (root_poa, &ev);
name_server = gnome_name_service_get ();
CosNaming_NamingContext_bind (name_server, &name, obj, &ev);
CORBA_exception_free (&ev);
gtk_main();
return 0;
} |
#include <orb/orbit.h>
#include <ORBitservices/CosNaming.h>
#include <gnome.h>
#include <gdk/gdkx.h>
#include <libgnorba/gnorba.h>
#include "./plug.h"
int main (int argc, char **argv)
{
CORBA_Environment ev;
CORBA_ORB orb;
CosNaming_NamingContext name_server;
CosNaming_NameComponent name_component[1] =
{{"view_plug","server"}};
CosNaming_Name name =
{1, 1, name_component, CORBA_FALSE};
CORBA_Object obj;
GtkWidget *win;
GtkWidget *socket;
CORBA_exception_init (&ev);
orb = gnome_CORBA_init ("a simple socket client",
"0.1",
&argc,
argv,
GNORBA_INIT_SERVER_FUNC,
&ev);
name_server = gnome_name_service_get ();
obj = CosNaming_NamingContext_resolve (name_server,
&name,
&ev);
win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (GTK_WINDOW (win),
300,
300);
socket = gtk_socket_new ();
gtk_container_add (GTK_CONTAINER(win),
socket);
gtk_widget_show_all (win);
view_plug_set_window_id (obj, GDK_WINDOW_XWINDOW(socket->window), &ev);
CORBA_exception_free (&ev);
gtk_main ();
return 0;
} |