diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile | 4 | ||||
-rwxr-xr-x | src/Makefile.win32 | 7 | ||||
-rw-r--r-- | src/ivy.c | 81 | ||||
-rw-r--r-- | src/ivy.h | 12 | ||||
-rw-r--r-- | src/ivychannel.h | 14 | ||||
-rw-r--r-- | src/ivyglibloop.c | 22 | ||||
-rw-r--r-- | src/ivyglibloop.h | 20 | ||||
-rwxr-xr-x | src/ivyglutloop.c | 24 | ||||
-rwxr-xr-x | src/ivyglutloop.h | 25 | ||||
-rw-r--r-- | src/ivyloop.c | 11 | ||||
-rw-r--r-- | src/ivyloop.h | 27 | ||||
-rw-r--r-- | src/ivyprobe.c | 71 | ||||
-rw-r--r-- | src/ivysocket.c | 38 | ||||
-rw-r--r-- | src/ivysocket.h | 4 | ||||
-rwxr-xr-x | src/ivytcl.c | 28 | ||||
-rwxr-xr-x | src/ivytcl.h | 24 | ||||
-rw-r--r-- | src/ivyxtloop.c | 28 | ||||
-rw-r--r-- | src/ivyxtloop.h | 24 | ||||
-rw-r--r-- | src/list.h | 2 | ||||
-rw-r--r-- | src/timer.c | 2 | ||||
-rw-r--r-- | src/timer.h | 2 | ||||
-rw-r--r-- | src/version.h | 8 |
22 files changed, 164 insertions, 314 deletions
diff --git a/src/Makefile b/src/Makefile index b3f6cd1..b5128c8 100644 --- a/src/Makefile +++ b/src/Makefile @@ -16,8 +16,8 @@ # change this in version.h too !!!! -MAJOR=3 -MINOR=7 +MAJOR=4 +MINOR=0 XTINC = -I/usr/X11R6/include XTLIB = -L/usr/X11R6/lib -lXt -lX11 -lSM -lICE diff --git a/src/Makefile.win32 b/src/Makefile.win32 index dab95dd..3599350 100755 --- a/src/Makefile.win32 +++ b/src/Makefile.win32 @@ -16,8 +16,8 @@ # change this in version.h too !!!! -MAJOR=3 -MINOR=7 +MAJOR=4 +MINOR=0 PCREINC = -I "C:\Program Files\GnuWin32\include" #`pcre-config --cflags` PCRELIB = "C:\Program Files\GnuWin32\lib\libpcre.lib" #`pcre-config --libs` @@ -84,9 +84,6 @@ libivy.lib: $(OBJ) del /f $@ $(LIBTOOL)$@ $(OBJ) - -# TODO this PCREOBJ is a dirty hack - libivy.dll: $(OBJ) $(CC) /dll -o $@ $(OBJ) $(PCRELIB) @@ -7,8 +7,8 @@ * * Main functions * - * Authors: Francois-Regis Colin <fcolin@cena.dgac.fr> - * Stephane Chatty <chatty@cena.dgac.fr> + * Authors: Francois-Regis Colin <fcolin@cena.fr> + * Stephane Chatty <chatty@cena.fr> * * $Id$ * @@ -40,12 +40,13 @@ #include "list.h" #include "ivy.h" -#define VERSION 3 +#define VERSION 4 #define MAX_MATCHING_ARGS 20 -#define ARG_START "\002" -#define ARG_END "\003" +#define ARG_START '\002' +#define ARG_END '\003' +#define MESSAGE_TERMINATOR '\0' #define DEFAULT_DOMAIN 127.255.255.255 @@ -58,15 +59,19 @@ static char* DefaultIvyBus = GenerateIvyBus(DEFAULT_DOMAIN,DEFAULT_BUS); typedef enum { - Bye, /* l'application emettrice se termine */ - AddRegexp, /* expression reguliere d'un client */ - Msg, /* message reel */ - Error, /* error message */ - DelRegexp, /* Remove expression reguliere */ - EndRegexp, /* end of the regexp list */ + Bye, /* l'application emettrice se termine */ + AddRegexp, /* expression reguliere d'un client */ + Msg, /* message reel */ + Error, /* error message */ + DelRegexp, /* Remove expression reguliere */ + EndRegexp, /* end of the regexp list */ StartRegexp, /* debut des expressions */ - DirectMsg, /* message direct a destination de l'appli */ - Die /* demande de terminaison de l'appli */ + DirectMsg, /* message direct a destination de l'appli */ + Die, /* demande de terminaison de l'appli */ + Ping = 9, /* checks the presence of the other */ + Pong = 10, /* checks the presence of the other */ + AddBinding = 11, /* other methods for binding message based on hash table */ + DelBinding = 12, /* other methods for binding message based on hash table */ } MsgType; @@ -145,7 +150,7 @@ static const char *ready_message = 0; /* * function like strok but do not eat consecutive separator * */ -static char * nextArg( char *s, const char *separator ) +static char * nextArg( char *s, const char separator ) { static char *start = NULL; static char *end = NULL; @@ -155,15 +160,15 @@ static char * nextArg( char *s, const char *separator ) } start = end; - while ( *end && *end != *separator ) + while ( *end && *end != separator ) end++; - if ( *end == *separator ) *end++ = '\0'; + if ( *end == separator ) *end++ = '\0'; if ( end == start ) return NULL; return start; } static void MsgSendTo( Client client, MsgType msgtype, int id, const char *message ) { - SocketSend( client, "%d %d" ARG_START "%s\n", msgtype, id, message); + SocketSend( client, "%d %d%c%s%c", msgtype, id, ARG_START, message, MESSAGE_TERMINATOR); } static void IvyCleanup() @@ -210,17 +215,19 @@ MsgCall (const char *message, MsgSndPtr msg, Client client) // il faut essayer d'envoyer le message en une seule fois sur la socket // pour eviter au maximun de passer dans le select plusieur fois par message du protocole Ivy // pour eviter la latence ( PB de perfo detecte par ivyperf ping roudtrip ) - offset += make_message_var( &buffer, &size, offset, "%d %d" ARG_START ,Msg, msg->id); + offset += make_message_var( &buffer, &size, offset, "%d %d%c",Msg, msg->id, ARG_START); #ifdef DEBUG printf( "Send matching args count %ld\n",msg->regexp.re_nsub); #endif index=1; while ( index<rc ) { - offset += make_message_var( &buffer, &size, offset, "%.*s" ARG_END , ovector[2*index+1]- ovector[2*index], - message + ovector[2*index]); + offset += make_message_var( &buffer, &size, offset, "%.*s%c", + ovector[2*index+1]- ovector[2*index], + message + ovector[2*index], + ARG_END); ++index; } - offset += make_message_var( &buffer, &size, offset, "\n"); + offset += make_message_var( &buffer, &size, offset, "%c", MESSAGE_TERMINATOR); SocketSendRaw(client, buffer , offset); return 1; } @@ -229,7 +236,10 @@ MsgCall (const char *message, MsgSndPtr msg, Client client) static int MsgCall (const char *message, MsgSndPtr msg, Client client) { - regmatch_t match[MAX_MATCHING_ARGS+1]; + static char *buffer = NULL; /* Use satic mem to eliminate multiple call to malloc /free */ + static int size = 0; /* donc non reentrant !!!! */ + int offset = 0; + regmatch_t match[MAX_MATCHING_ARGS+1]; #ifdef GNU_REGEXP regmatch_t* p; #else @@ -245,8 +255,8 @@ MsgCall (const char *message, MsgSndPtr msg, Client client) // il faut essayer d'envoyer le message en une seule fois sur la socket // pour eviter au maximun de passer dans le select plusieur fois par message du protocole Ivy // pour eviter la latence ( PB detecte par ivyperf ping roudtrip ) - SocketSendBuffered( client, "%d %d" ARG_START ,Msg, msg->id); - + offset += make_message_var( &buffer, &size, offset, "%d %d%c",Msg, msg->id, ARG_START); + #ifdef DEBUG printf( "Send matching args count %ld\n",msg->regexp.re_nsub); #endif //DEBUG @@ -254,8 +264,10 @@ MsgCall (const char *message, MsgSndPtr msg, Client client) #ifdef GNU_REGEXP p = &match[1]; while ( p->rm_so != -1 ) { - SocketSendBuffered( client, "%.*s" ARG_END , p->rm_eo - p->rm_so, - message + p->rm_so); + offset += make_message_var( &buffer, &size, offset, "%.*s%c", + p->rm_eo - p->rm_so, + message + p->rm_so, + ARG_END); ++p; } #else @@ -266,10 +278,10 @@ MsgCall (const char *message, MsgSndPtr msg, Client client) printf ("Send matching arg%d %.*s\n",i,(int)(match[i].rm_eo - match[i].rm_so), message + match[i].rm_so); #endif - SocketSendBuffered (client, "%.*s" ARG_END ,(int)(match[i].rm_eo - match[i].rm_so), + offset += make_message_var( &buffer, &size, offset, "%.*s" ARG_END ,(int)(match[i].rm_eo - match[i].rm_so), message + match[i].rm_so); } else { - SocketSendBuffered (client, ARG_END); + offset += make_message_var( &buffer, &size, offset, "%c", ARG_END); #ifdef DEBUG printf( "Send matching arg%d VIDE\n",i); #endif //DEBUG @@ -277,8 +289,8 @@ MsgCall (const char *message, MsgSndPtr msg, Client client) } #endif - SocketSendBuffered (client, "\n"); - SocketFlush(client); + offset += make_message_var( &buffer, &size, offset, "%c", MESSAGE_TERMINATOR); + SocketSendRaw(client, buffer , offset); return 1; } #endif /* USE_PCRE_REGEX */ @@ -357,7 +369,7 @@ static void Receive( Client client, void *data, char *line ) #endif err = sscanf( line ,"%d %d", &kind_of_msg, &id ); - arg = strstr( line , ARG_START ); + arg = strchr( line , ARG_START ); if ( (err != 2) || (arg == 0) ) { printf("Quitting bad format %s\n", line); @@ -659,7 +671,7 @@ static void BroadcastReceive( Client client, void *data, char *line ) #endif //DEBUG /* connect to the service and send the regexp */ - app = SocketConnectAddr(SocketGetRemoteAddr(client), serviceport, 0, Receive, ClientDelete ); + app = SocketConnectAddr(SocketGetRemoteAddr(client), serviceport, 0, Receive, MESSAGE_TERMINATOR, ClientDelete ); if (app) { IvyClientPtr clnt; clnt = SendService( app ); @@ -682,6 +694,11 @@ void IvyInit (const char *appname, const char *ready, ready_message = ready; } +void IvyStop() +{ + IvyChannelStop(); +} + void IvySetBindCallback(IvyBindCallback bind_callback, void *bind_data ) { @@ -6,8 +6,8 @@ * * Main functions * - * Authors: François-Régis Colin <fcolin@cena.dgac.fr> - * Stéphane Chatty <chatty@cena.dgac.fr> + * Authors: François-Régis Colin <fcolin@cena.fr> + * Stéphane Chatty <chatty@cena.fr> * * $Id$ * @@ -65,10 +65,10 @@ void IvyInit( void *die_data /* user data */ ); - void IvySetBindCallback( +void IvySetBindCallback( IvyBindCallback bind_callback, void *bind_data ); - void IvyDelBindCallback(); +void IvyDelBindCallback(); void IvyStart (const char*); void IvyStop (); @@ -97,6 +97,10 @@ int IvySendMsg( const char *fmt_message, ... ); /* avec sprintf prealable */ void IvyBindDirectMsg( MsgDirectCallback callback, void *user_data); void IvySendDirectMsg( IvyClientPtr app, int id, char *msg ); +/* boucle principale d'Ivy */ +/* use of internal MainLoop or XtMainLoop, or other MainLoop integration */ +extern void IvyMainLoop(void(*hook)(void)); + #ifdef __cplusplus } #endif diff --git a/src/ivychannel.h b/src/ivychannel.h index fa498b4..b2c3eb2 100644 --- a/src/ivychannel.h +++ b/src/ivychannel.h @@ -6,7 +6,7 @@ * * Basic I/O handling * - * Authors: François-Régis Colin <fcolin@cena.dgac.fr> + * Authors: François-Régis Colin <fcolin@cena.fr> * * $Id$ * @@ -37,10 +37,12 @@ typedef void (*ChannelHandleDelete)( void *data ); typedef void (*ChannelHandleRead)( Channel channel, HANDLE fd, void *data); /* fonction appele par le bus pour initialisation */ -typedef void (*ChannelInit)(void); +extern void IvyChannelInit(void); +/* fonction appele par le bus pour terminaison */ +extern void IvyChannelStop(void); /* fonction appele par le bus pour mise en place des callback sur le canal */ -typedef Channel (*ChannelSetUp)( +extern Channel IvyChannelOpen( HANDLE fd, void *data, ChannelHandleDelete handle_delete, @@ -48,11 +50,7 @@ typedef Channel (*ChannelSetUp)( ); /* fonction appele par le bus pour fermeture du canal */ -typedef void (*ChannelClose)( Channel channel ); - -extern ChannelInit channel_init; -extern ChannelClose channel_close; -extern ChannelSetUp channel_setup; +extern void IvyChannelClose( Channel channel ); #ifdef __cplusplus } diff --git a/src/ivyglibloop.c b/src/ivyglibloop.c index 968824a..438e22d 100644 --- a/src/ivyglibloop.c +++ b/src/ivyglibloop.c @@ -39,9 +39,6 @@ struct _channel { static int channel_initialized = 0; -ChannelInit channel_init = IvyGlibChannelInit; -ChannelSetUp channel_setup = IvyGlibChannelSetUp; -ChannelClose channel_close = IvyGlibChannelClose; static gboolean IvyGlibHandleChannelRead(GIOChannel *source, GIOCondition condition, @@ -52,7 +49,7 @@ static gboolean IvyGlibHandleChannelDelete(GIOChannel *source, gpointer data); -void IvyGlibChannelInit(void) { +void IvyChannelInit(void) { if ( channel_initialized ) return; /* fixes bug when another app coredumps */ #ifndef WIN32 @@ -61,9 +58,13 @@ void IvyGlibChannelInit(void) { channel_initialized = 1; } +void IvyChannelStop( ) +{ + channel_initialized = 0; +} -Channel IvyGlibChannelSetUp(HANDLE fd, void *data, +Channel IvyChannelOpen(HANDLE fd, void *data, ChannelHandleDelete handle_delete, ChannelHandleRead handle_read ) { @@ -88,13 +89,12 @@ Channel IvyGlibChannelSetUp(HANDLE fd, void *data, -void IvyGlibChannelClose( Channel channel ) { +void IvyChannelClose( Channel channel ) { if ( channel->handle_delete ) (*channel->handle_delete)( channel->data ); g_source_remove( channel->id_read ); g_source_remove( channel->id_delete ); } - static gboolean IvyGlibHandleChannelRead(GIOChannel *source, GIOCondition condition, @@ -118,10 +118,8 @@ static gboolean IvyGlibHandleChannelDelete(GIOChannel *source, return TRUE; } - -void -IvyStop () +void IvyMainLoop(void(*hook)(void)) { - /* To be implemented */ + GMainLoop *ml = g_main_loop_new(NULL, FALSE); + g_main_loop_run(ml); } - diff --git a/src/ivyglibloop.h b/src/ivyglibloop.h index 6941069..f5026aa 100644 --- a/src/ivyglibloop.h +++ b/src/ivyglibloop.h @@ -21,28 +21,8 @@ extern "C" { #endif -#define ANYPORT 0 - -#ifdef WIN32 -#include <windows.h> -#define HANDLE SOCKET -#else -#define HANDLE int -#endif - #include "ivychannel.h" -extern void IvyGlibChannelInit(void); - -extern Channel IvyGlibChannelSetUp( - HANDLE fd, - void *data, - ChannelHandleDelete handle_delete, - ChannelHandleRead handle_read - ); - -extern void IvyGlibChannelClose( Channel channel ); - #ifdef __cplusplus } #endif diff --git a/src/ivyglutloop.c b/src/ivyglutloop.c index a777a30..95430e5 100755 --- a/src/ivyglutloop.c +++ b/src/ivyglutloop.c @@ -6,8 +6,8 @@ * * Main loop based on GLUT ( OpenGL ) Toolkit * - * Authors: François-Régis Colin <colin@cenatoulouse.dgac.fr> - * Stéphane Chatty <chatty@cenatoulouse.dgac.fr> + * Authors: François-Régis Colin <colin@cena.fr> + * Stéphane Chatty <chatty@cena.fr> * * $Id$ * @@ -53,12 +53,9 @@ struct _channel { static int channel_initialized = 0; -ChannelInit channel_init = IvyGlutChannelInit; -ChannelSetUp channel_setup = IvyGlutChannelSetUp; -ChannelClose channel_close = IvyGlutChannelClose; -void IvyGlutChannelInit(void) +void IvyChannelInit(void) { if ( channel_initialized ) return; @@ -69,8 +66,11 @@ void IvyGlutChannelInit(void) #endif channel_initialized = 1; } - -void IvyGlutChannelClose( Channel channel ) +void IvyChannelStop(void) +{ + channel_initialized = 0; +} +void IvyChannelClose( Channel channel ) { if ( channel->handle_delete ) @@ -98,7 +98,7 @@ static void IvyGlutHandleChannelDelete( int source, GLUTInputId id, void *data ) (*channel->handle_delete)(channel->data); } -Channel IvyGlutChannelSetUp(HANDLE fd, void *data, +Channel IvyChannelOpen(HANDLE fd, void *data, ChannelHandleDelete handle_delete, ChannelHandleRead handle_read ) @@ -122,10 +122,8 @@ Channel IvyGlutChannelSetUp(HANDLE fd, void *data, return channel; } - -void -IvyStop () +extern void IvyMainLoop(void(*hook)(void)) { - /* To be implemented */ + glutMainLoop(); } diff --git a/src/ivyglutloop.h b/src/ivyglutloop.h index 0819a93..53437d6 100755 --- a/src/ivyglutloop.h +++ b/src/ivyglutloop.h @@ -6,8 +6,8 @@ * * Main loop based on GLUT ( OpenGL ) Toolkit * - * Authors: François-Régis Colin <colin@cenatoulouse.dgac.fr> - * Stéphane Chatty <chatty@cenatoulouse.dgac.fr> + * Authors: François-Régis Colin <colin@cena.fr> + * Stéphane Chatty <chatty@cena.fr> * * $Id$ * @@ -24,30 +24,9 @@ extern "C" { #include <GL/Glut.h> -/* general Handle */ - -#define ANYPORT 0 - -#ifdef WIN32 -#include <windows.h> -#define HANDLE SOCKET -#else -#define HANDLE int -#endif #include "ivychannel.h" -extern void IvyGlutChannelInit(void); - -extern Channel IvyGlutChannelSetUp( - HANDLE fd, - void *data, - ChannelHandleDelete handle_delete, - ChannelHandleRead handle_read -); - -extern void IvyGlutChannelClose( Channel channel ); - #ifdef __cplusplus } #endif diff --git a/src/ivyloop.c b/src/ivyloop.c index 9ccd427..3948605 100644 --- a/src/ivyloop.c +++ b/src/ivyloop.c @@ -6,8 +6,8 @@ * * Main loop based on select * - * Authors: François-Régis Colin <fcolin@cena.dgac.fr> - * Stéphane Chatty <chatty@cena.dgac.fr> + * Authors: François-Régis Colin <fcolin@cena.fr> + * Stéphane Chatty <chatty@cena.fr> * * $Id$ * @@ -49,9 +49,6 @@ struct _channel { ChannelHandleRead handle_read; }; -ChannelInit channel_init = IvyChannelInit; -ChannelSetUp channel_setup = IvyChannelSetUp; -ChannelClose channel_close = IvyChannelClose; static Channel channels_list = NULL; @@ -91,7 +88,7 @@ ChannelDefferedDelete () } } -Channel IvyChannelSetUp (HANDLE fd, void *data, +Channel IvyChannelOpen (HANDLE fd, void *data, ChannelHandleDelete handle_delete, ChannelHandleRead handle_read ) @@ -160,7 +157,7 @@ void IvyChannelInit (void) channel_initialized = 1; } -void IvyStop (void) +void IvyChannelStop (void) { MainLoop = 0; } diff --git a/src/ivyloop.h b/src/ivyloop.h index c4af6eb..1d0b623 100644 --- a/src/ivyloop.h +++ b/src/ivyloop.h @@ -6,8 +6,8 @@ * * Main loop handling around select * - * Authors: François-Régis Colin <fcolin@cena.dgac.fr> - * Stéphane Chatty <chatty@cena.dgac.fr> + * Authors: François-Régis Colin <fcolin@cena.fr> + * Stéphane Chatty <chatty@cena.fr> * * $Id$ * @@ -25,30 +25,9 @@ extern "C" { #include "ivychannel.h" -/* general Handle */ - -#define ANYPORT 0 - -#ifdef WIN32 -#include <windows.h> -#define HANDLE SOCKET -#else -#define HANDLE int -#endif - - extern void IvyMainLoop(void(*hook)(void) ); - - -extern void IvyChannelInit(void); -extern void IvyChannelClose( Channel channel ); -extern Channel IvyChannelSetUp( - HANDLE fd, - void *data, - ChannelHandleDelete handle_delete, - ChannelHandleRead handle_read); - +extern void IvyIdle(); #ifdef __cplusplus diff --git a/src/ivyprobe.c b/src/ivyprobe.c index 10a3b00..4715fd0 100644 --- a/src/ivyprobe.c +++ b/src/ivyprobe.c @@ -54,25 +54,16 @@ extern int optind; #endif -#ifdef XTMAINLOOP -#include "ivyxtloop.h" -#endif -#ifdef GLIBMAINLOOP -#include <glib.h> -#include "ivyglibloop.h" -#endif -#ifdef GLUTMAINLOOP -#include "ivyglutloop.h" -#endif -#ifdef IVYMAINLOOP -#include "ivyloop.h" -#endif + +#include "ivychannel.h" #include "ivysocket.h" #include "ivy.h" #include "timer.h" #ifdef XTMAINLOOP +#include "ivyxtloop.h" #include <X11/Intrinsic.h> XtAppContext cntx; + #endif int app_count = 0; @@ -125,19 +116,8 @@ void HandleStdin (Channel channel, HANDLE fd, void *data) int err; line = fgets(buf, 4096, stdin); if (!line) { -#ifdef XTMAINLOOP - IvyXtChannelClose (channel); -#endif -#ifdef GLIBMAINLOOP - IvyGlibChannelClose(channel); -#endif -#ifdef GLUTMAINLOOP - IvyGlutChannelClose(channel); -#endif -#ifdef IVYMAINLOOP IvyChannelClose (channel); IvyStop(); -#endif return; } if (*line == '.') { @@ -236,8 +216,11 @@ void HandleStdin (Channel channel, HANDLE fd, void *data) } } else { cmd = strtok (buf, "\n"); + if ( cmd ) + { err = IvySendMsg (cmd); printf("-> Sent to %d peer%s\n", err, err == 1 ? "" : "s"); + } } } @@ -259,18 +242,8 @@ void ApplicationCallback (IvyClientPtr app, void *user_data, IvyApplicationEvent printf("%s subscribes to '%s'\n",appname,*msgList++); /* printf("Application(%s): End Messages\n",appname);*/ if (app_count == wait_count) -#ifdef XTMAINLOOP - IvyXtChannelSetUp (0, NULL, NULL, HandleStdin); -#endif -#ifdef GLIBMAINLLOP - IvyGlibChannelSetUp( 0, NULL, NULL, HandleStdin); -#endif -#ifdef GLUTMAINLLOP - IvyGlutChannelSetUp( 0, NULL, NULL, HandleStdin); -#endif -#ifdef IVYMAINLOOP - IvyChannelSetUp (0, NULL, NULL, HandleStdin); -#endif + + IvyChannelOpen (0, NULL, NULL, HandleStdin); break; case IvyApplicationDisconnected: @@ -359,22 +332,12 @@ int main(int argc, char *argv[]) IvyBindMsg (Callback, NULL, argv[optind]); if (wait_count == 0) -#ifdef XTMAINLOOP - IvyXtChannelSetUp (0, NULL, NULL, HandleStdin); -#endif -#ifdef GLIBMAINLOOP - IvyGlibChannelSetUp (0, NULL, NULL, HandleStdin); -#endif -#ifdef GLUTMAINLOOP - IvyGlutChannelSetUp (0, NULL, NULL, HandleStdin); -#endif -#ifdef IVYMAINLOOP #ifndef WIN32 /* Stdin not compatible with select , select only accept socket */ - IvyChannelSetUp (0, NULL, NULL, HandleStdin); -#endif + IvyChannelOpen (0, NULL, NULL, HandleStdin); #endif + IvyStart (bus); if (timer_test) { @@ -387,18 +350,8 @@ int main(int argc, char *argv[]) #ifdef XTMAINLOOP XtAppMainLoop (cntx); #endif -#ifdef GLIBMAINLOOP - { - GMainLoop *ml = g_main_loop_new(NULL, FALSE); - g_main_loop_run(ml); - } -#endif -#ifdef GLUTMAINLOOP - glutMainLoop(); -#endif -#ifdef IVYMAINLOOP IvyMainLoop (0); -#endif + return 0; } diff --git a/src/ivysocket.c b/src/ivysocket.c index 1bb9c62..7161f13 100644 --- a/src/ivysocket.c +++ b/src/ivysocket.c @@ -40,7 +40,6 @@ #include "list.h" #include "ivychannel.h" #include "ivysocket.h" -#include "ivyloop.h" #define BUFFER_SIZE 4096 /* taille buffer initiale on multiple pas deux a chaque realloc */ @@ -52,6 +51,7 @@ struct _server { void *(*create)(Client client); void (*handle_delete)(Client client, void *data); SocketInterpretation interpretation; + char terminator; /* character delimiter of the client message */ }; struct _client { @@ -119,12 +119,7 @@ int make_message_var(char ** buffer, int *size, int offset, const char *fmt, .. void SocketInit() { - if (! channel_init ) - { - fprintf (stderr, "Channel management functions not set, exiting.\n"); - exit(-1); - } - (*channel_init)(); + IvyChannelInit(); } static void DeleteSocket(void *data) @@ -175,11 +170,11 @@ static void HandleSocket (Channel channel, HANDLE fd, void *data) &len); if (nb < 0) { perror(" Read Socket "); - (*channel_close) (client->channel ); + IvyChannelClose(client->channel ); return; } if (nb == 0 ) { - (*channel_close) (client->channel ); + IvyChannelClose(client->channel ); return; } client->ptr += nb; @@ -237,10 +232,10 @@ static void HandleServer(Channel channel, HANDLE fd, void *data) fprintf(stderr,"HandleSocket Buffer Memory Alloc Error\n"); exit(0); } - client->terminator = '\n'; + client->terminator = server->terminator; client->from = remote2; client->fd = ns; - client->channel = (*channel_setup) (ns, client, DeleteSocket, HandleSocket ); + client->channel = IvyChannelOpen (ns, client, DeleteSocket, HandleSocket ); client->interpretation = server->interpretation; client->ptr = client->buffer; client->handle_delete = server->handle_delete; @@ -313,7 +308,7 @@ Server SocketServer(unsigned short port, exit(0); } server->fd = fd; - server->channel = (*channel_setup) (fd, server, DeleteServerSocket, HandleServer ); + server->channel = IvyChannelOpen(fd, server, DeleteServerSocket, HandleServer ); server->create = create; server->handle_delete = handle_delete; server->interpretation = interpretation; @@ -330,7 +325,7 @@ void SocketServerClose (Server server ) { if (!server) return; - (*channel_close) (server->channel ); + IvyChannelClose (server->channel ); } char *SocketGetPeerHost (Client client ) @@ -373,7 +368,7 @@ void SocketGetRemoteHost (Client client, char **host, unsigned short *port ) void SocketClose (Client client ) { if (client) - (*channel_close) (client->channel ); + IvyChannelClose (client->channel ); } void SocketSendRaw (Client client, char *buffer, int len ) @@ -436,6 +431,7 @@ Ouverture d'un canal TCP/IP en mode client Client SocketConnect (char * host, unsigned short port, void *data, SocketInterpretation interpretation, + char terminator, void (*handle_delete)(Client client, void *data) ) { @@ -445,12 +441,13 @@ Client SocketConnect (char * host, unsigned short port, fprintf(stderr, "Erreur %s Calculateur inconnu !\n",host); return NULL; } - return SocketConnectAddr ((struct in_addr*)(rhost->h_addr), port, data, interpretation, handle_delete); + return SocketConnectAddr ((struct in_addr*)(rhost->h_addr), port, data, interpretation, terminator, handle_delete); } Client SocketConnectAddr (struct in_addr * addr, unsigned short port, void *data, SocketInterpretation interpretation, + char terminator, void (*handle_delete)(Client client, void *data) ) { @@ -486,9 +483,9 @@ Client SocketConnectAddr (struct in_addr * addr, unsigned short port, fprintf(stderr,"HandleSocket Buffer Memory Alloc Error\n"); exit(0); } - client->terminator = '\n'; + client->terminator = terminator; client->fd = handle; - client->channel = (*channel_setup) (handle, client, DeleteSocket, HandleSocket ); + client->channel = IvyChannelOpen (handle, client, DeleteSocket, HandleSocket ); client->interpretation = interpretation; client->ptr = client->buffer; client->data = data; @@ -554,7 +551,8 @@ int SocketWaitForReply (Client client, char *buffer, int size, int delai) /* Socket UDP */ -Client SocketBroadcastCreate (unsigned short port, +Client SocketBroadcastCreate ( + unsigned short port, void *data, SocketInterpretation interpretation ) @@ -614,9 +612,9 @@ Client SocketBroadcastCreate (unsigned short port, fprintf(stderr,"HandleSocket Buffer Memory Alloc Error\n"); exit(0); } - client->terminator = '\n'; + client->terminator = '\n'; client->fd = handle; - client->channel = (*channel_setup) (handle, client, DeleteSocket, HandleSocket ); + client->channel = IvyChannelOpen (handle, client, DeleteSocket, HandleSocket ); client->interpretation = interpretation; client->ptr = client->buffer; client->data = data; diff --git a/src/ivysocket.h b/src/ivysocket.h index 4602b64..0d9fddb 100644 --- a/src/ivysocket.h +++ b/src/ivysocket.h @@ -6,7 +6,7 @@ * * Sockets * - * Authors: Francois-Regis Colin <fcolin@cena.dgac.fr> + * Authors: Francois-Regis Colin <fcolin@cena.fr> * * $Id$ * @@ -77,11 +77,13 @@ extern void SocketBroadcast( char *fmt, ... ); extern Client SocketConnect( char * host, unsigned short port, void *data, SocketInterpretation interpretation, + char terminator, void (*handle_delete)(Client client, void *data) ); extern Client SocketConnectAddr( struct in_addr * addr, unsigned short port, void *data, SocketInterpretation interpretation, + char terminator, void (*handle_delete)(Client client, void *data) ); extern int SocketWaitForReply( Client client, char *buffer, int size, int delai); diff --git a/src/ivytcl.c b/src/ivytcl.c index 74ed129..406bbd9 100755 --- a/src/ivytcl.c +++ b/src/ivytcl.c @@ -6,7 +6,7 @@ * * Main loop based on Tcl * - * Authors: François-Régis Colin <fcolin@cena.dgac.fr> + * Authors: François-Régis Colin <fcolin@cena.fr> * * $Id$ * @@ -38,9 +38,6 @@ // mais il y a des problemes sur les socket server // Il n'y a pas de Tcl_MakeTCPserver -ChannelInit channel_init = IvyTclChannelInit; -ChannelSetUp channel_setup = IvyTclChannelSetUp; -ChannelClose channel_close = IvyTclChannelClose; struct _channel { HANDLE fd; @@ -59,7 +56,7 @@ static int channel_initialized = 0; WSADATA WsaData; #endif -void IvyTclChannelInit(void) +void IvyChannelInit(void) { #ifdef WIN32 int error; @@ -78,6 +75,15 @@ void IvyTclChannelInit(void) #endif channel_initialized = 1; } +void IvyChannelStop(void) +{ + channel_initialized = 0; + +#ifndef TCL_CHANNEL_INTEGRATION + Tcl_CancelIdleCall(IvyIdleProc,0); +#endif + +} static void IvyHandleFd(ClientData cd, int mask) @@ -93,7 +99,7 @@ IvyHandleFd(ClientData cd, } } -void IvyTclChannelClose( Channel channel ) +void IvyChannelClose( Channel channel ) { if ( channel->handle_delete ) @@ -103,7 +109,7 @@ void IvyTclChannelClose( Channel channel ) } -Channel IvyTclChannelSetUp(HANDLE fd, void *data, +Channel IvyChannelOpen(HANDLE fd, void *data, ChannelHandleDelete handle_delete, ChannelHandleRead handle_read ) @@ -137,14 +143,6 @@ void IvyIdleProc(ClientData clientData) } #endif -void -TclIvyStop () -{ - /* To be implemented */ -#ifndef TCL_CHANNEL_INTEGRATION - Tcl_CancelIdleCall(IvyIdleProc,0); -#endif -} /* Code from PLC */ #define INTEGER_SPACE 30 diff --git a/src/ivytcl.h b/src/ivytcl.h index 10a13e8..99c05d7 100755 --- a/src/ivytcl.h +++ b/src/ivytcl.h @@ -6,7 +6,7 @@ * * Main loop based on Tcl * - * Authors: François-Régis Colin <fcolin@cena.dgac.fr> + * Authors: François-Régis Colin <fcolin@cena.fr> * * $Id$ * @@ -21,31 +21,9 @@ extern "C" { #endif -/*#include <X11/Intrinsic.h>*/ - -/* general Handle */ - -#define ANYPORT 0 - -#ifdef WIN32 -#include <windows.h> -#define HANDLE SOCKET -#else -#define HANDLE int -#endif #include "ivychannel.h" -extern void IvyTclChannelInit(void); - -extern Channel IvyTclChannelSetUp( - HANDLE fd, - void *data, - ChannelHandleDelete handle_delete, - ChannelHandleRead handle_read -); - -extern void IvyTclChannelClose( Channel channel ); #ifdef __cplusplus } diff --git a/src/ivyxtloop.c b/src/ivyxtloop.c index 2764fe4..32094e9 100644 --- a/src/ivyxtloop.c +++ b/src/ivyxtloop.c @@ -6,8 +6,8 @@ * * Main loop based on the X Toolkit * - * Authors: François-Régis Colin <fcolin@cena.dgac.fr> - * Stéphane Chatty <chatty@cena.dgac.fr> + * Authors: François-Régis Colin <fcolin@cena.fr> + * Stéphane Chatty <chatty@cena.fr> * * $Id$ * @@ -56,12 +56,8 @@ static int channel_initialized = 0; static XtAppContext app = NULL; -ChannelInit channel_init = IvyXtChannelInit; -ChannelSetUp channel_setup = IvyXtChannelSetUp; -ChannelClose channel_close = IvyXtChannelClose; - -void IvyXtChannelInit(void) +void IvyChannelInit(void) { if ( channel_initialized ) return; @@ -79,7 +75,7 @@ void IvyXtChannelInit(void) channel_initialized = 1; } -void IvyXtChannelClose( Channel channel ) +void IvyChannelClose( Channel channel ) { if ( channel->handle_delete ) @@ -87,7 +83,9 @@ void IvyXtChannelClose( Channel channel ) XtRemoveInput( channel->id_read ); XtRemoveInput( channel->id_delete ); } - +void IvyChannelStop() +{ +} static void IvyXtHandleChannelRead( XtPointer closure, int* source, XtInputId* id ) { @@ -113,7 +111,7 @@ void IvyXtChannelAppContext( XtAppContext cntx ) app = cntx; } -Channel IvyXtChannelSetUp(HANDLE fd, void *data, +Channel IvyChannelOpen(HANDLE fd, void *data, ChannelHandleDelete handle_delete, ChannelHandleRead handle_read ) @@ -136,11 +134,7 @@ Channel IvyXtChannelSetUp(HANDLE fd, void *data, return channel; } - - -void -IvyStop () +void IvyMainLoop(void(*hook)(void)) { - /* To be implemented */ -} - + XtAppMainLoop (app); +}
\ No newline at end of file diff --git a/src/ivyxtloop.h b/src/ivyxtloop.h index c482675..162f398 100644 --- a/src/ivyxtloop.h +++ b/src/ivyxtloop.h @@ -6,8 +6,8 @@ * * Main loop based on the X Toolkit * - * Authors: François-Régis Colin <colin@cena.dgac.fr> - * Stéphane Chatty <chatty@cena.dgac.fr> + * Authors: François-Régis Colin <colin@cena.fr> + * Stéphane Chatty <chatty@cena.fr> * * $Id$ * @@ -24,29 +24,9 @@ extern "C" { #include <X11/Intrinsic.h> -/* general Handle */ - -#define ANYPORT 0 - -#ifdef WIN32 -#include <windows.h> -#define HANDLE SOCKET -#else -#define HANDLE int -#endif - #include "ivychannel.h" -extern void IvyXtChannelInit(void); - -extern Channel IvyXtChannelSetUp( - HANDLE fd, - void *data, - ChannelHandleDelete handle_delete, - ChannelHandleRead handle_read -); -extern void IvyXtChannelClose( Channel channel ); extern void IvyXtChannelAppContext( XtAppContext cntx ); @@ -6,7 +6,7 @@ * * Simple lists in C * - * Authors: François-Régis Colin <fcolin@cena.dgac.fr> + * Authors: François-Régis Colin <fcolin@cena.fr> * * $Id$ * diff --git a/src/timer.c b/src/timer.c index f147232..9f13117 100644 --- a/src/timer.c +++ b/src/timer.c @@ -6,7 +6,7 @@ * * Timers used in select based main loop * - * Authors: François-Régis Colin <fcolin@cena.dgac.fr> + * Authors: François-Régis Colin <fcolin@cena.fr> * * $Id$ * diff --git a/src/timer.h b/src/timer.h index f8f21a5..c62b505 100644 --- a/src/timer.h +++ b/src/timer.h @@ -6,7 +6,7 @@ * * Timers for select-based main loop * - * Authors: François-Régis Colin <fcolin@cena.dgac.fr> + * Authors: François-Régis Colin <fcolin@cena.fr> * * $Id$ * diff --git a/src/version.h b/src/version.h index 89fb803..072a2fb 100644 --- a/src/version.h +++ b/src/version.h @@ -4,8 +4,8 @@ * Copyright (C) 1997-2004 * Centre d'Études de la Navigation Aérienne * - * Authors: François-Régis Colin <colin@cena.dgac.fr> - * Stéphane Chatty <chatty@cena.dgac.fr> + * Authors: François-Régis Colin <colin@cena.fr> + * Stéphane Chatty <chatty@cena.fr> * Yannick Jestin <jestin@cena.fr> * * $Id$ @@ -25,5 +25,5 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ -#define IVYMAJOR_VERSION 3 -#define IVYMINOR_VERSION 7 +#define IVYMAJOR_VERSION 4 +#define IVYMINOR_VERSION 0 |