summaryrefslogtreecommitdiff
path: root/src/ivyxtloop.c
diff options
context:
space:
mode:
authorjacomi1998-08-12 10:23:25 +0000
committerjacomi1998-08-12 10:23:25 +0000
commitd3b04f0209ea826c67a2ee84ced889ee907f49a0 (patch)
treee0900dda136b9a9f38ee7b412db427a7315b06dc /src/ivyxtloop.c
parent6ff2ef5124e1101f475ad87b178b925489de2845 (diff)
downloadivy-c-d3b04f0209ea826c67a2ee84ced889ee907f49a0.zip
ivy-c-d3b04f0209ea826c67a2ee84ced889ee907f49a0.tar.gz
ivy-c-d3b04f0209ea826c67a2ee84ced889ee907f49a0.tar.bz2
ivy-c-d3b04f0209ea826c67a2ee84ced889ee907f49a0.tar.xz
version relookee en ivy
Diffstat (limited to 'src/ivyxtloop.c')
-rw-r--r--src/ivyxtloop.c116
1 files changed, 116 insertions, 0 deletions
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 <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 "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;
+}
+
+