From d090d7150e3814ecd436e68bd3e247eda880ee58 Mon Sep 17 00:00:00 2001 From: fcolin Date: Mon, 3 Aug 1998 13:04:08 +0000 Subject: Ajout des fonctions pour permettre la gestion par des boucles autres que XT et Interne( select ) buschannel.h : Interface avec gestion MainLoop busloop.[ch] : Implementation MainLoop par select busxtloop.[ch] : Implementation MainLoop par Appel Xt --- src/busxtloop.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 src/busxtloop.c (limited to 'src/busxtloop.c') diff --git a/src/busxtloop.c b/src/busxtloop.c new file mode 100644 index 0000000..e95bc45 --- /dev/null +++ b/src/busxtloop.c @@ -0,0 +1,117 @@ +#ifdef WIN32 +#include +#endif +#include +#include +#include +#include +#include + +#ifdef WIN32 +#else +#include +#include +#include +#include +#include +#include +#include +#include +#endif + + + +#include + +#include "buschannel.h" +#include "busxtloop.h" + +struct _channel { + XtInputId id_read; + XtInputId id_delete; + void *data; + void (*handle_delete)( void *data ); + void (*handle_read)( Channel channel, HANDLE fd, void *data); + }; + + +static int channel_initialized = 0; + + +static XtAppContext app = NULL; + + +void BusXtChannelClose( Channel channel ) +{ + + if ( channel->handle_delete ) + (*channel->handle_delete)( channel->data ); + XtRemoveInput( channel->id_read ); + XtRemoveInput( channel->id_delete ); +} + +static void BusXtHandleChannelRead( XtPointer closure, int* source, XtInputId* id ) +{ + Channel channel = (Channel)closure; +#ifdef DEBUG + printf("Handle Channel read %d\n",*source ); +#endif + (*channel->handle_read)(channel,*source,channel->data); +} +static void BusXtHandleChannelDelete( XtPointer closure, int* source, XtInputId* id ) +{ + Channel channel = (Channel)closure; +#ifdef DEBUG + printf("Handle Channel delete %d\n",*source ); +#endif + (*channel->handle_delete)(channel->data); +} +Channel BusXtChannelSetUp(HANDLE fd, void *data, + ChannelHandleDelete handle_delete, + ChannelHandleRead handle_read + ) +{ + Channel channel; + + channel = XtNew( struct _channel ); + if ( !channel ) + { + fprintf(stderr,"NOK Memory Alloc Error\n"); + exit(0); + } + + channel->handle_delete = handle_delete; + channel->handle_read = handle_read; + channel->data = data; + + channel->id_read = XtAppAddInput( app, fd, (XtPointer)XtInputReadMask, BusXtHandleChannelRead, channel); + channel->id_delete = XtAppAddInput( app, fd, (XtPointer)XtInputExceptMask, BusXtHandleChannelDelete, channel); + + return channel; +} + + +void BusXtChannelAppContext( XtAppContext cntx ) +{ + app = cntx; +} + +void BusXtChannelInit(void) +{ + + if ( channel_initialized ) return; + + /* pour eviter les plantages quand les autres applis font core-dump */ +#ifndef WIN32 + signal( SIGPIPE, SIG_IGN); +#endif + /* verifie si init correct */ + if ( !app ) + { + fprintf( stderr, "You Must call BusXtChannelAppContext to Use XtMainLoop !!!\n"); + exit(-1); + } + channel_initialized = 1; +} + + -- cgit v1.1