From cfc602e2408bf90cce7be62f3f1e940cd5af7172 Mon Sep 17 00:00:00 2001 From: jestin Date: Fri, 25 Jun 2004 18:26:19 +0000 Subject: j'ajoute des exemples de code dans le CVS. il faudra les intégrer à la doc... --- examples/Makefile | 36 ++++++++++++++++++++++++++++++++++++ examples/Test.tcl | 17 +++++++++++++++++ examples/button.tk | 21 +++++++++++++++++++++ examples/gtkIvyButton.c | 34 ++++++++++++++++++++++++++++++++++ examples/motifButtonIvy.c | 37 +++++++++++++++++++++++++++++++++++++ examples/testUnbind.c | 35 +++++++++++++++++++++++++++++++++++ examples/unBind.tcl | 22 ++++++++++++++++++++++ 7 files changed, 202 insertions(+) create mode 100644 examples/Makefile create mode 100755 examples/Test.tcl create mode 100755 examples/button.tk create mode 100644 examples/gtkIvyButton.c create mode 100644 examples/motifButtonIvy.c create mode 100644 examples/testUnbind.c create mode 100755 examples/unBind.tcl (limited to 'examples') diff --git a/examples/Makefile b/examples/Makefile new file mode 100644 index 0000000..234618f --- /dev/null +++ b/examples/Makefile @@ -0,0 +1,36 @@ +.SUFFIXES: .c .o + + CC = gcc -g +TARGETS = motifButtonIvy gtkIvyButton testUnbind + SRCS = motifButtonIvy.c gtkIvyButton.c testUnbind.c + OBJS = $(SRCS:.c=.o) +PCRELIB = `pcre-config --libs` +EXTRALIB= -L../src +GTKLIB = `pkg-config gtk+-x11-2.0 --libs` +GTKINC = `pkg-config gtk+-x11-2.0 --cflags` +MOTIFINC= +MOTIFLIB= -L/usr/X11R6/lib -lXm -lXt -lX11 +#MOTIFINC= -I/sw/include +#MOTIFLIB= -L/sw/lib -L/usr/X11R6/lib -lXm -lXt -lX11 + + +all: $(TARGETS) + +testUnbind: testUnbind.o + $(CC) -o $@ $< -livy $(PCRELIB) $(EXTRALIB) + +gtkIvyButton.o: gtkIvyButton.c + $(CC) -c $< $(GTKINC) + +gtkIvyButton: gtkIvyButton.o + $(CC) -o $@ $< $(GTKLIB) -lgivy $(EXTRALIB) + +motifButtonIvy.o: motifButtonIvy.c + $(CC) -c $< $(MOTIFINC) $(EXTRALIB) + +motifButtonIvy: motifButtonIvy.o + $(CC) -o $@ $< $(MOTIFLIB) -lxtivy -lpcre $(EXTRALIB) + + +clean: + rm -fR $(OBJS) $(TARGETS) diff --git a/examples/Test.tcl b/examples/Test.tcl new file mode 100755 index 0000000..e2bb650 --- /dev/null +++ b/examples/Test.tcl @@ -0,0 +1,17 @@ +#!/usr/bin/tclsh + +load ../src/libtclivy.so.3.6 + +proc connxCB { name event } { + puts "an Ivy agent named $name $event" +} + +proc msgCB {client str} { + puts "received $str from client $client" +} + +Ivy::init "TESTTCL" "TESTTCL Ready" connxCB connxCB +set id [ Ivy::bind "(.*)" msgCB ] +Ivy::start "" + +vwait tcl_interactive diff --git a/examples/button.tk b/examples/button.tk new file mode 100755 index 0000000..c7809ba --- /dev/null +++ b/examples/button.tk @@ -0,0 +1,21 @@ +#!/usr/bin/wish +load ../src/libtclivy.so.3.6 + +proc connect { client action } { } +proc send { } { + global tosend + Ivy::send $tosend +} + +proc dotext {client text} { + global tosend + set tosend $text + puts "text to send set to $text" +} + +Ivy::init "TCLTK" "TCLTK Ready" connect connect +Ivy::start 127.255.255.255:2010 +Ivy::bind "^Ivy Button text=(.*)" dotext +set tosend foo +button .send -command send -text "send msg" +pack .send diff --git a/examples/gtkIvyButton.c b/examples/gtkIvyButton.c new file mode 100644 index 0000000..be8cc4a --- /dev/null +++ b/examples/gtkIvyButton.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include +#include + +void hello( GtkWidget *widget, gpointer data ) { + fprintf(stderr,"%s\n",*((char**)data)); + IvySendMsg(*((char**)data)); +} + +void textCallback(IvyClientPtr app, void *user_data, int argc, char *argv[]){ + *((char **)user_data)=argv[0]; +} + +int main( int argc, char *argv[] ) { + GtkWidget *window; + GtkWidget *button; + char *bus=getenv("IVYBUS"); + char *tosend="foo"; + gtk_init (&argc, &argv); + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_container_set_border_width (GTK_CONTAINER (window), 10); + button = gtk_button_new_with_label ("send message"); + g_signal_connect (G_OBJECT(button),"clicked",G_CALLBACK(hello),&tosend); + gtk_container_add (GTK_CONTAINER(window),button); + gtk_widget_show (button); + gtk_widget_show (window); + IvyInit ("IvyGtkButton", "IvyGtkButton READY",NULL,NULL,NULL,NULL); + IvyBindMsg(textCallback,&tosend,"^Ivy Button text=(.*)"); + IvyStart (bus); + gtk_main (); + return 0; +} diff --git a/examples/motifButtonIvy.c b/examples/motifButtonIvy.c new file mode 100644 index 0000000..f4336aa --- /dev/null +++ b/examples/motifButtonIvy.c @@ -0,0 +1,37 @@ +#include +#include +#include +#include +#include +#include + +void myMotifCallback(Widget w,XtPointer client_d,XtPointer call_d){ + // sends the string on the bus + IvySendMsg (*((char**)client_d)); +} + +void textCallback(IvyClientPtr app, void *user_data, int argc, char *argv[]){ + printf("%s sent %s\n",IvyGetApplicationName(app),argv[0]); + // updates the string we want to send + *((char **)user_data)=argv[0]; +} + +void DieCallback (IvyClientPtr app, void *data, int id){ exit(0); } + +int main(int argc,char *argv[]){ + Widget toplevel,pushb; + XtAppContext app_context; + Arg myargs[10]; + char *bus=getenv("IVYBUS"); + char *tosend="foo"; + toplevel=XtAppInitialize(&app_context,"Ivy Button",NULL,0,&argc,argv,NULL,myargs,0); + pushb=XmCreatePushButton(toplevel,"send message",myargs,1); + XtManageChild(pushb); + XtAddCallback(pushb,XmNactivateCallback,myMotifCallback,&tosend); + XtRealizeWidget(toplevel); + IvyXtChannelAppContext(app_context); + IvyInit("IvyMotif","IvyMotif connected",NULL,NULL,DieCallback,NULL); + IvyBindMsg(textCallback,&tosend,"^Ivy Button text=(.*)"); + IvyStart(bus); + XtAppMainLoop(app_context); +} diff --git a/examples/testUnbind.c b/examples/testUnbind.c new file mode 100644 index 0000000..16a4a8a --- /dev/null +++ b/examples/testUnbind.c @@ -0,0 +1,35 @@ +/* + * Ivy unbind Test + * + * Copyright (C) 1997-2004 + * Centre d'Études de la Navigation Aérienne + * + * Authors: Yannick Jestin + * + * Please refer to file ../src/version.h for the + * copyright notice regarding this software + */ + +#include +#include +#include +#include +#include +#define REGEXP "^ub" + +void Callback (IvyClientPtr app, void *user_data, int argc, char *argv[]) { + MsgRcvPtr *ptr = (MsgRcvPtr *) user_data; + printf ("%s sent unbind message, unbinding to %s\n", + IvyGetApplicationName(app),REGEXP); + IvyUnbindMsg(*ptr); +} + +int main(int argc, char *argv[]) { + MsgRcvPtr ptr; + IvyInit("TestUnbind","TestUnbind Ready",NULL,NULL,NULL,NULL); + ptr=IvyBindMsg(Callback,&ptr,REGEXP); + printf("bound to %s\n",REGEXP); + IvyStart(NULL); + IvyMainLoop(0); + return 0; +} diff --git a/examples/unBind.tcl b/examples/unBind.tcl new file mode 100755 index 0000000..6440f1a --- /dev/null +++ b/examples/unBind.tcl @@ -0,0 +1,22 @@ +#!/usr/bin/tclsh +load ./libtclivy.so.3.6 + +proc connect { client action } { } + +proc send { } { + global tosend + Ivy::send $tosend +} + +proc dotext {client} { + global id + puts "$client told me to unbind (to $id)" + Ivy::unbind $id +} + +Ivy::init "TCLTK" "TCLTK Ready" connect connect +Ivy::start "" +set id [Ivy::bind "^unbind" dotext] +puts "bound to value $id" + +vwait tcl_interactive -- cgit v1.1