From 53f1cd3c774bc45c09a1fe90f9d27a5c5feee785 Mon Sep 17 00:00:00 2001 From: fcolin Date: Wed, 28 Jun 2006 09:05:30 +0000 Subject: Modification API Hook sur IvyMainLoop --- src/ivyloop.c | 32 +++++++++++++++++++++++++++----- src/ivyloop.h | 6 +++++- src/ivyperf.c | 2 +- src/ivyprobe.c | 4 ++-- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/ivyloop.c b/src/ivyloop.c index a407fae..897267b 100644 --- a/src/ivyloop.c +++ b/src/ivyloop.c @@ -56,6 +56,13 @@ static int channel_initialized = 0; static fd_set open_fds; static int MainLoop = 1; +/* Hook callback & data */ +static IvyHookPtr BeforeSelect = NULL; +static IvyHookPtr AfterSelect = NULL; + +static void *BeforeSelectData = NULL; +static void *AfterSelectData = NULL; + #ifdef WIN32 WSADATA WsaData; #endif @@ -158,7 +165,7 @@ void IvyChannelStop (void) MainLoop = 0; } -void IvyMainLoop(void(*BeforeSelect)(void),void(*AfterSelect)(void)) +void IvyMainLoop() { fd_set rdset; @@ -166,20 +173,24 @@ void IvyMainLoop(void(*BeforeSelect)(void),void(*AfterSelect)(void)) int ready; while (MainLoop) { + ChannelDefferedDelete(); - if (BeforeSelect) (*BeforeSelect)(); + + if (BeforeSelect) + (*BeforeSelect)(BeforeSelectData); rdset = open_fds; exset = open_fds; ready = select(64, &rdset, 0, &exset, TimerGetSmallestTimeout()); - /* for compatibility with older version we test also the first parameter */ - if (BeforeSelect && AfterSelect) (*AfterSelect)(); + + if (AfterSelect) + (*AfterSelect)(AfterSelectData); if (ready < 0 && (errno != EINTR)) { fprintf (stderr, "select error %d\n",errno); perror("select"); return; } - TimerScan(); + TimerScan(); /* should be spliited in two part ( next timeout & callbacks */ if (ready > 0) { IvyChannelHandleExcpt(&exset); IvyChannelHandleRead(&rdset); @@ -212,3 +223,14 @@ void IvyIdle() } + +void IvySetBeforeSelectHook(IvyHookPtr before, void *data ) +{ + BeforeSelect = before; + BeforeSelectData = data; +} +void IvySetAfterSelectHook(IvyHookPtr after, void *data ) +{ + AfterSelect = after; + AfterSelectData = data; +} diff --git a/src/ivyloop.h b/src/ivyloop.h index df99e41..f272212 100644 --- a/src/ivyloop.h +++ b/src/ivyloop.h @@ -52,8 +52,12 @@ de la maniere suivante: !!!! Attention donc l'appel des callbacks ivy se fait avec l'acces verrouille ! */ -extern void IvyMainLoop(void(*BeforeSelect)(void),void(*AfterSelect)(void) ); +extern void IvyMainLoop(void); +typedef void ( *IvyHookPtr) ( void *data ); + +extern void IvySetBeforeSelectHook(IvyHookPtr before, void *data ); +extern void IvySetAfterSelectHook(IvyHookPtr after, void *data ); #ifdef __cplusplus } diff --git a/src/ivyperf.c b/src/ivyperf.c index 05a9754..07453e3 100755 --- a/src/ivyperf.c +++ b/src/ivyperf.c @@ -111,6 +111,6 @@ int main(int argc, char *argv[]) TimerRepeatAfter (TIMER_LOOP, time, TimerCall, (void*)1); - IvyMainLoop (0,0); + IvyMainLoop (); return 0; } diff --git a/src/ivyprobe.c b/src/ivyprobe.c index 536447e..bdf3b9a 100644 --- a/src/ivyprobe.c +++ b/src/ivyprobe.c @@ -217,7 +217,7 @@ void ApplicationCallback (IvyClientPtr app, void *user_data, IvyApplicationEvent { char *appname; char *host; - char **msgList; +/* char **msgList;*/ appname = IvyGetApplicationName (app); host = IvyGetApplicationHost (app); switch (event) { @@ -430,7 +430,7 @@ int main(int argc, char *argv[]) #endif #ifdef IVYMAINLOOP - IvyMainLoop (0,0); + IvyMainLoop (); #endif return 0; } -- cgit v1.1