summaryrefslogtreecommitdiff
path: root/src/busxtloop.c
diff options
context:
space:
mode:
authorfcolin1998-08-03 13:04:08 +0000
committerfcolin1998-08-03 13:04:08 +0000
commitd090d7150e3814ecd436e68bd3e247eda880ee58 (patch)
treeca37ee2c4b7fe217abe78baeb83c8ba4168ada1d /src/busxtloop.c
parentb8dda6ecdfc747d561d170bd3d8512dc6914d238 (diff)
downloadivy-c-d090d7150e3814ecd436e68bd3e247eda880ee58.zip
ivy-c-d090d7150e3814ecd436e68bd3e247eda880ee58.tar.gz
ivy-c-d090d7150e3814ecd436e68bd3e247eda880ee58.tar.bz2
ivy-c-d090d7150e3814ecd436e68bd3e247eda880ee58.tar.xz
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
Diffstat (limited to 'src/busxtloop.c')
-rw-r--r--src/busxtloop.c117
1 files changed, 117 insertions, 0 deletions
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 <windows.h>
+#endif
+#include <stdlib.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+
+#ifdef WIN32
+#else
+#include <unistd.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <signal.h>
+#endif
+
+
+
+#include <X11/Intrinsic.h>
+
+#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;
+}
+
+