From 809dd9c2eeb1441f04234bdd23d862b98fe4ff9b Mon Sep 17 00:00:00 2001 From: jestin Date: Wed, 11 Dec 2002 15:29:28 +0000 Subject: Adding examples for Xt/Motif, Tcl/Tk and GTK in the documentation --- doc/ivy-c.sgml | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 161 insertions(+), 6 deletions(-) (limited to 'doc') diff --git a/doc/ivy-c.sgml b/doc/ivy-c.sgml index 56a61fa..7365746 100644 --- a/doc/ivy-c.sgml +++ b/doc/ivy-c.sgml @@ -32,18 +32,22 @@ StéphaneChatty
chatty@cena.fr
+ +YannickJestin +
jestin@cena.fr
+
-August 4, 2000 +December 11, 2002 -2000 +1998-2002 Centre d'Études de la Navigation Aérienne This document is a programmer's guide that describes how to use the Ivy C -library to connect applications to an Ivy bus. This guide describes version 3.0 +library to connect applications to an Ivy bus. This guide describes version 3.2 of the library. @@ -505,20 +509,171 @@ library, this is obtained by passing a null value to IvyStart Using Ivy with another main loop + +The ivyprobe source code holds examples of use of Ivy within other main loops, +namely Xt and Gtk. + + Using Ivy with the X Toolkit -to be written +The basics for using the Ivy withing the XtAppMainLoop() are the +following ones: + + + +include the ivy.h and ivyxtloop.h +link with libxtivy.o ( add the ld flag and NOT the ) +create the ivy bus + + IvyXtChannelAppContect(app_context) with an existing Xt + context + You can add channels to be handled by Ivy, for instance, + stdin, with the IvyXtChannelSetUp function + IvyInit(char *name,char *readyMessage,IvyApplicationCallback + cb,void *cbUserData,IvyDieCallback dieCb,void *dieCbUserdata) + IvyBindMsg() for the behavior + IvyStart(char *domain) + +run the Xt main loop with XtAppMainLoop(app_context) + + +Here is an example, motifButtonIvy.c. You can compile it with the +following command line: + +cc -o motifButtonIvy motifButtonIvy.c -lxtivy + +The result is a simple single-buttoned application emitting a message on the +bus. The message defaults to "foo", but can be updated via an Ivy Button +text=bar message. + + +#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){ + IvySendMsg (*((char**)client_d)); +} +void textCallback(IvyClientPtr app, void *user_data, int argc, char *argv[]){ + *((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); +} + + Using Ivy with Tcl/Tk -to be written +Just load the libtclivy.so package, and use the following commands + +#!/usr/bin/tclsh +Ivy::init $name $hellomessge connectproc dieproc +Ivy::start $domain +Ivy::bind $regexp ballback +Ivy::applist +Ivy::send $message +Ivy::applist +mainloop + +A full example in Tcl/Tk is provided here: + +#!/usr/bin/wish +load libtclivy.so.3.4 +proc connect {args} { } +proc send { } { + global tosend + Ivy::send $tosend +} +proc dotext {text} { + global tosend + set tosend $text +} +Ivy::init "IvyTCLTK" "IvyTCLTK READY" connect echo +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 + + Using Ivy with Gtk -to be written +There is little to do to make your gtk applications Ivy aware: just add +the following lines into your code: + +#include <ivy.h> +#include <ivygtkloop.h> +... +IvyInit ("IvyGtkButton", "IvyGtkButton READY",NULL,NULL,NULL,NULL); +IvyBindMsg(textCallback,&tosend,"^Ivy Button text=(.*)"); +IvyStart (bus); + + + +A full example: gtkIvyButton.c is provided below, compile it with the +-lgtkivy flag. The other flags depend on your system installation ( replace +pkg-config with gtk-config for older gnome1 libs) + +#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; +} + -- cgit v1.1