From d3b04f0209ea826c67a2ee84ced889ee907f49a0 Mon Sep 17 00:00:00 2001 From: jacomi Date: Wed, 12 Aug 1998 10:23:25 +0000 Subject: version relookee en ivy --- src/ivyxtloop.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 src/ivyxtloop.c (limited to 'src/ivyxtloop.c') diff --git a/src/ivyxtloop.c b/src/ivyxtloop.c new file mode 100644 index 0000000..e2620aa --- /dev/null +++ b/src/ivyxtloop.c @@ -0,0 +1,116 @@ +#ifdef WIN32 +#include +#endif +#include +#include +#include +#include +#include + +#ifdef WIN32 +#else +#include +#include +#include +#include +#include +#include +#include +#include +#endif + + +#include + +#include "ivychannel.h" +#include "ivyxtloop.h" + +struct _channel { + XtInputId id_read; + XtInputId id_delete; + void *data; + ChannelHandleDelete handle_delete; + ChannelHandleRead handle_read; + }; + + +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