summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorjestin2004-06-25 18:26:19 +0000
committerjestin2004-06-25 18:26:19 +0000
commitcfc602e2408bf90cce7be62f3f1e940cd5af7172 (patch)
treef3b3078f308ff676acfee099aa3c0a4268e15b9a /examples
parent43eaf35871578ea498e20ed4f945cce14f8f3032 (diff)
downloadivy-c-cfc602e2408bf90cce7be62f3f1e940cd5af7172.zip
ivy-c-cfc602e2408bf90cce7be62f3f1e940cd5af7172.tar.gz
ivy-c-cfc602e2408bf90cce7be62f3f1e940cd5af7172.tar.bz2
ivy-c-cfc602e2408bf90cce7be62f3f1e940cd5af7172.tar.xz
j'ajoute des exemples de code dans le CVS. il faudra les intégrer à la doc...
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile36
-rwxr-xr-xexamples/Test.tcl17
-rwxr-xr-xexamples/button.tk21
-rw-r--r--examples/gtkIvyButton.c34
-rw-r--r--examples/motifButtonIvy.c37
-rw-r--r--examples/testUnbind.c35
-rwxr-xr-xexamples/unBind.tcl22
7 files changed, 202 insertions, 0 deletions
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 <gtk/gtk.h>
+#include <ivy.h>
+#include <ivygtkloop.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+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 <stdlib.h>
+#include <stdio.h>
+#include <strings.h>
+#include <Xm/PushB.h>
+#include <ivy.h>
+#include <ivyxtloop.h>
+
+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 <jestin@cena.fr>
+ *
+ * Please refer to file ../src/version.h for the
+ * copyright notice regarding this software
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ivyloop.h>
+#include <ivy.h>
+#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