summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorchatty1999-01-08 10:32:55 +0000
committerchatty1999-01-08 10:32:55 +0000
commit862c79e17a75e38a85687534fa0d38f43236c604 (patch)
tree7cf503250273515067219235263245194c7cb8c7 /src
parentb2d8c1c820685fe92fa4667a694fe4947b216685 (diff)
downloadivy-c-862c79e17a75e38a85687534fa0d38f43236c604.zip
ivy-c-862c79e17a75e38a85687534fa0d38f43236c604.tar.gz
ivy-c-862c79e17a75e38a85687534fa0d38f43236c604.tar.bz2
ivy-c-862c79e17a75e38a85687534fa0d38f43236c604.tar.xz
Bus -> Ivy
Simplified management of different versions of channel management. SetChannelManagement has disappeared.
Diffstat (limited to 'src')
-rw-r--r--src/ivyloop.c67
-rw-r--r--src/ivyloop.h22
-rw-r--r--src/ivysocket.c21
-rw-r--r--src/ivyxtloop.c70
4 files changed, 91 insertions, 89 deletions
diff --git a/src/ivyloop.c b/src/ivyloop.c
index 92f6301..a65e8d0 100644
--- a/src/ivyloop.c
+++ b/src/ivyloop.c
@@ -2,7 +2,7 @@
*
* Ivy, C interface
*
- * Copyright 1997-1998
+ * Copyright 1997-1999
* Centre d'Etudes de la Navigation Aerienne
*
* Main loop handling around select
@@ -20,8 +20,7 @@
#include <stdarg.h>
#include <string.h>
-#ifdef WIN32
-#else
+#ifndef WIN32
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
@@ -45,9 +44,14 @@ struct _channel {
int tobedeleted;
ChannelHandleDelete handle_delete;
ChannelHandleRead handle_read;
- };
+};
+
+ChannelInit channel_init = IvyChannelInit;
+ChannelSetUp channel_setup = IvyChannelSetUp;
+ChannelClose channel_close = IvyChannelClose;
+
static Channel channels_list = NULL;
@@ -60,12 +64,12 @@ static int MainLoop = 1;
WSADATA WsaData;
#endif
-void BusLoopChannelClose( Channel channel )
+void IvyChannelClose( Channel channel )
{
channel->tobedeleted = 1;
}
-static void BusLoopChannelDelete( Channel channel )
+static void IvyChannelDelete( Channel channel )
{
if ( channel->handle_delete )
(*channel->handle_delete)( channel->data );
@@ -73,6 +77,7 @@ static void BusLoopChannelDelete( Channel channel )
FD_CLR(channel->fd, &open_fds);
LIST_REMOVE( channels_list, channel );
}
+
static void ChannelDefferedDelete()
{
Channel channel,next;
@@ -80,12 +85,12 @@ static void ChannelDefferedDelete()
{
if ( channel->tobedeleted )
{
- BusLoopChannelDelete( channel );
+ IvyChannelDelete( channel );
}
}
}
-Channel BusLoopChannelSetUp(HANDLE fd, void *data,
+Channel IvyChannelSetUp(HANDLE fd, void *data,
ChannelHandleDelete handle_delete,
ChannelHandleRead handle_read
)
@@ -109,7 +114,7 @@ Channel BusLoopChannelSetUp(HANDLE fd, void *data,
return channel;
}
-static void BusLoopChannelHandleRead(fd_set *current)
+static void IvyChannelHandleRead(fd_set *current)
{
Channel channel,next;
@@ -122,7 +127,7 @@ static void BusLoopChannelHandleRead(fd_set *current)
}
}
-static void BusLoopChannelHandleExcpt(fd_set *current)
+static void IvyChannelHandleExcpt(fd_set *current)
{
Channel channel,next;
LIST_EACH_SAFE( channels_list, channel, next )
@@ -130,12 +135,12 @@ static void BusLoopChannelHandleExcpt(fd_set *current)
if (FD_ISSET( channel->fd, current ) )
{
(*channel->handle_delete)(channel->data);
-// BusLoopChannelClose( channel );
+// IvyChannelClose( channel );
}
}
}
-void BusLoopChannelInit(void)
+void IvyChannelInit(void)
{
#ifdef WIN32
int error;
@@ -157,37 +162,37 @@ void BusLoopChannelInit(void)
}
-void BusLoopChannelStop(void)
+void IvyChannelStop(void)
{
MainLoop = 0;
}
-void BusLoopChannelMainLoop(void(*hook)(void))
+void IvyMainLoop(void(*hook)(void))
{
-fd_set rdset;
-fd_set exset;
-int ready;
+ fd_set rdset;
+ fd_set exset;
+ int ready;
- while (MainLoop) {
- ChannelDefferedDelete();
- if ( hook ) (*hook)();
- rdset = open_fds;
- exset = open_fds;
- ready = select(64, &rdset, 0, &exset, TimerGetSmallestTimeout());
- if ( ready < 0 && ( errno != EINTR ))
+ while (MainLoop) {
+ ChannelDefferedDelete();
+ if ( hook ) (*hook)();
+ rdset = open_fds;
+ exset = open_fds;
+ ready = select(64, &rdset, 0, &exset, TimerGetSmallestTimeout());
+ if ( ready < 0 && ( errno != EINTR ))
{
- perror("select");
- return;
+ perror("select");
+ return;
}
- TimerScan();
- if ( ready > 0 )
+ TimerScan();
+ if ( ready > 0 )
{
- BusLoopChannelHandleExcpt(&exset);
- BusLoopChannelHandleRead(&rdset);
- continue;
+ IvyChannelHandleExcpt(&exset);
+ IvyChannelHandleRead(&rdset);
+ continue;
}
}
}
diff --git a/src/ivyloop.h b/src/ivyloop.h
index 9dbb52d..9aa3bc9 100644
--- a/src/ivyloop.h
+++ b/src/ivyloop.h
@@ -2,7 +2,7 @@
*
* Ivy, C interface
*
- * Copyright 1997-1998
+ * Copyright 1997-1999
* Centre d'Etudes de la Navigation Aerienne
*
* Main loop based on select
@@ -31,18 +31,18 @@ extern "C" {
#define HANDLE int
#endif
-extern void BusLoopChannelInit(void);
-extern void BusLoopChannelStop(void);
-extern void BusLoopChannelMainLoop(void(*hook)(void) );
+extern void IvyChannelInit(void);
+extern void IvyChannelStop(void);
+extern void IvyMainLoop(void(*hook)(void) );
-extern Channel BusLoopChannelSetUp(
- HANDLE fd,
- void *data,
- ChannelHandleDelete handle_delete,
- ChannelHandleRead handle_read
- );
+extern Channel IvyChannelSetUp(
+ HANDLE fd,
+ void *data,
+ ChannelHandleDelete handle_delete,
+ ChannelHandleRead handle_read
+);
-extern void BusLoopChannelClose( Channel channel );
+extern void IvyChannelClose( Channel channel );
#ifdef __cplusplus
diff --git a/src/ivysocket.c b/src/ivysocket.c
index c785de2..7fe8870 100644
--- a/src/ivysocket.c
+++ b/src/ivysocket.c
@@ -2,7 +2,7 @@
*
* Ivy, C interface
*
- * Copyright 1997-1998
+ * Copyright 1997-1999
* Centre d'Etudes de la Navigation Aerienne
*
* Sockets
@@ -37,10 +37,8 @@
#include "list.h"
#include "ivychannel.h"
#include "ivysocket.h"
+#include "ivyloop.h"
-static ChannelInit channel_init = NULL;
-static ChannelSetUp channel_setup = NULL;
-static ChannelClose channel_close = NULL;
#define MAX_BUFFER 2048
@@ -73,27 +71,19 @@ static Client clients_list = NULL;
-
#ifdef WIN32
-WSADATA WsaData;
+WSADATA WsaData;
#endif
-void BusSetChannelManagement( ChannelInit init_chan, ChannelSetUp setup_chan, ChannelClose close_chan )
-{
- channel_init = init_chan;
- channel_setup = setup_chan;
- channel_close = close_chan;
-}
-
void SocketInit()
{
if ( ! channel_init )
{
- fprintf( stderr, "You Must call BusSetChannelManagement before all !!!\n");
+ fprintf( stderr, "Channel management functions not set, exiting.\n");
exit(-1);
}
- (*channel_init)();
+ (*channel_init)();
}
static void DeleteSocket(void *data)
@@ -105,6 +95,7 @@ static void DeleteSocket(void *data)
close( client->fd );
LIST_REMOVE( clients_list, client );
}
+
static void HandleSocket( Channel channel, HANDLE fd, void *data)
{
Client client = (Client)data;
diff --git a/src/ivyxtloop.c b/src/ivyxtloop.c
index 3a17b61..9f3a408 100644
--- a/src/ivyxtloop.c
+++ b/src/ivyxtloop.c
@@ -2,7 +2,7 @@
*
* Ivy, C interface
*
- * Copyright 1997-1998
+ * Copyright 1997-1999
* Centre d'Etudes de la Navigation Aerienne
*
* Main loop based on X Toolkit
@@ -53,8 +53,30 @@ static int channel_initialized = 0;
static XtAppContext app = NULL;
+ChannelInit channel_init = IvyXtChannelInit;
+ChannelSetUp channel_setup = IvyXtChannelSetUp;
+ChannelClose channel_close = IvyXtChannelClose;
-void BusXtChannelClose( Channel channel )
+
+void IvyXtChannelInit(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 IvyXtChannelAppContext before XtMainLoop. Exiting.\n");
+ exit(-1);
+ }
+ channel_initialized = 1;
+}
+
+void IvyXtChannelClose( Channel channel )
{
if ( channel->handle_delete )
@@ -63,7 +85,8 @@ void BusXtChannelClose( Channel channel )
XtRemoveInput( channel->id_delete );
}
-static void BusXtHandleChannelRead( XtPointer closure, int* source, XtInputId* id )
+
+static void IvyXtHandleChannelRead( XtPointer closure, int* source, XtInputId* id )
{
Channel channel = (Channel)closure;
#ifdef DEBUG
@@ -71,7 +94,8 @@ static void BusXtHandleChannelRead( XtPointer closure, int* source, XtInputId* i
#endif
(*channel->handle_read)(channel,*source,channel->data);
}
-static void BusXtHandleChannelDelete( XtPointer closure, int* source, XtInputId* id )
+
+static void IvyXtHandleChannelDelete( XtPointer closure, int* source, XtInputId* id )
{
Channel channel = (Channel)closure;
#ifdef DEBUG
@@ -79,7 +103,14 @@ static void BusXtHandleChannelDelete( XtPointer closure, int* source, XtInputId*
#endif
(*channel->handle_delete)(channel->data);
}
-Channel BusXtChannelSetUp(HANDLE fd, void *data,
+
+
+void IvyXtChannelAppContext( XtAppContext cntx )
+{
+ app = cntx;
+}
+
+Channel IvyXtChannelSetUp(HANDLE fd, void *data,
ChannelHandleDelete handle_delete,
ChannelHandleRead handle_read
)
@@ -97,34 +128,9 @@ Channel BusXtChannelSetUp(HANDLE fd, void *data,
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);
+ channel->id_read = XtAppAddInput( app, fd, (XtPointer)XtInputReadMask, IvyXtHandleChannelRead, channel);
+ channel->id_delete = XtAppAddInput( app, fd, (XtPointer)XtInputExceptMask, IvyXtHandleChannelDelete, 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;
-}
-
-