diff options
author | drouin | 2004-09-01 15:54:51 +0000 |
---|---|---|
committer | drouin | 2004-09-01 15:54:51 +0000 |
commit | 12751e3fc02e45da1198b82dadf83fe861ebfd1e (patch) | |
tree | a56a2fdb4d4640dc29b5e3d080265d4d164f6b5d /src/ivyglibloop.c | |
parent | d95d579469c04a581fd5559e96d28b88293613c3 (diff) | |
download | ivy-c-12751e3fc02e45da1198b82dadf83fe861ebfd1e.zip ivy-c-12751e3fc02e45da1198b82dadf83fe861ebfd1e.tar.gz ivy-c-12751e3fc02e45da1198b82dadf83fe861ebfd1e.tar.bz2 ivy-c-12751e3fc02e45da1198b82dadf83fe861ebfd1e.tar.xz |
replaced the gtk mainloop with a glib one. added -Wall compile directive . fixed some warnings
Diffstat (limited to 'src/ivyglibloop.c')
-rw-r--r-- | src/ivyglibloop.c | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/src/ivyglibloop.c b/src/ivyglibloop.c new file mode 100644 index 0000000..968824a --- /dev/null +++ b/src/ivyglibloop.c @@ -0,0 +1,127 @@ +/* + * Ivy, C interface + * + * Copyright (C) 1997-2000 + * Centre d'Études de la Navigation Aérienne + * + * Main loop based on the Gtk Toolkit + * + * Authors: François-Régis Colin <fcolin@cena.fr> + * + * $Id$ + * + * Please refer to file version.h for the + * copyright notice regarding this software + */ + +#ifdef WIN32 +#include <windows.h> +#include <stdlib.h> +#include <errno.h> +#include <stdio.h> +#include <stdarg.h> +#include <string.h> +#else +#include <signal.h> +#endif + +#include <glib.h> + +#include "ivyglibloop.h" + +struct _channel { + guint id_read; + guint id_delete; + gpointer data; + ChannelHandleDelete handle_delete; + ChannelHandleRead handle_read; + }; + +static int channel_initialized = 0; + +ChannelInit channel_init = IvyGlibChannelInit; +ChannelSetUp channel_setup = IvyGlibChannelSetUp; +ChannelClose channel_close = IvyGlibChannelClose; + +static gboolean IvyGlibHandleChannelRead(GIOChannel *source, + GIOCondition condition, + gpointer data); + +static gboolean IvyGlibHandleChannelDelete(GIOChannel *source, + GIOCondition condition, + gpointer data); + + +void IvyGlibChannelInit(void) { + if ( channel_initialized ) return; + /* fixes bug when another app coredumps */ +#ifndef WIN32 + signal( SIGPIPE, SIG_IGN); +#endif + channel_initialized = 1; +} + + + +Channel IvyGlibChannelSetUp(HANDLE fd, void *data, + ChannelHandleDelete handle_delete, + ChannelHandleRead handle_read + ) { + Channel channel; + channel = (Channel)g_new(struct _channel, 1); + + channel->handle_delete = handle_delete; + channel->handle_read = handle_read; + channel->data = data; + + { + GIOChannel* io_channel = g_io_channel_unix_new(fd); + + channel->id_read = g_io_add_watch( io_channel, G_IO_IN, + IvyGlibHandleChannelRead, channel); + channel->id_delete = g_io_add_watch( io_channel, G_IO_ERR | G_IO_HUP, + IvyGlibHandleChannelDelete, channel); + } + return channel; +} + + + + +void IvyGlibChannelClose( Channel channel ) { + if ( channel->handle_delete ) + (*channel->handle_delete)( channel->data ); + g_source_remove( channel->id_read ); + g_source_remove( channel->id_delete ); +} + + +static gboolean IvyGlibHandleChannelRead(GIOChannel *source, + GIOCondition condition, + gpointer data) { + Channel channel = (Channel)data; +#ifdef DEBUG + printf("Handle Channel read %d\n",source ); +#endif + (*channel->handle_read)(channel, g_io_channel_unix_get_fd(source), channel->data); + return TRUE; +} + +static gboolean IvyGlibHandleChannelDelete(GIOChannel *source, + GIOCondition condition, + gpointer data) { + Channel channel = (Channel)data; +#ifdef DEBUG + printf("Handle Channel delete %d\n",source ); +#endif + (*channel->handle_delete)(channel->data); + return TRUE; +} + + +void +IvyStop () +{ + /* To be implemented */ +} + |