From e761e4e47ad5da0036d4fec4e70319afacd10fd6 Mon Sep 17 00:00:00 2001 From: bustico Date: Fri, 22 Sep 2006 09:41:53 +0000 Subject: ajout du message IvyChangeMessage pour changer la regexp d'un abonnement déjà établi --- src/ivy.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++---------- src/ivy.h | 4 +++- src/ivyprobe.c | 10 ++++++++-- 3 files changed, 63 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/ivy.c b/src/ivy.c index 270711c..5231f0d 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -320,16 +320,28 @@ static void Receive( Client client, void *data, char *line ) bind = IvyBindingCompile( arg, & erroffset, & errbuf ); if ( bind != NULL ) { - IVY_LIST_ADD_START( clnt->msg_send, snd ) - snd->id = id; - snd->str_regexp = strdup( arg ); - snd->binding = bind; - if ( application_bind_callback ) - { - (*application_bind_callback)( clnt, application_bind_data, id, snd->str_regexp, IvyAddBind ); - } - IVY_LIST_ADD_END( clnt->msg_send, snd ) - + // On teste si c'est un change regexp : changement de regexp d'une id existante + IVY_LIST_ITER( clnt->msg_send, snd, ( id != snd->id )); + if ( snd ) { + free (snd->str_regexp); + snd->str_regexp = strdup( arg ); + snd->binding = bind; + if ( application_bind_callback ) + { + (*application_bind_callback)( clnt, application_bind_data, id, snd->str_regexp, IvyChangeBind ); + } + } else { + IVY_LIST_ADD_START( clnt->msg_send, snd ) + snd->id = id; + snd->str_regexp = strdup( arg ); + snd->binding = bind; + if ( application_bind_callback ) + { + (*application_bind_callback)( clnt, application_bind_data, id, snd->str_regexp, IvyAddBind ); + } + IVY_LIST_ADD_END( clnt->msg_send, snd ) + + } } else { @@ -771,6 +783,32 @@ IvyBindMsg (MsgCallback callback, void *user_data, const char *fmt_regex, ... ) } return msg; } + +/* changement de regexp d'un bind existant precedement fait avec IvyBindMsg */ +MsgRcvPtr +IvyChangeMsg (MsgRcvPtr msg, const char *fmt_regex, ... ) +{ + static IvyBuffer buffer = { NULL, 0, 0}; + va_list ap; + IvyClientPtr clnt; + + va_start (ap, fmt_regex ); + buffer.offset = 0; + make_message( &buffer, fmt_regex, ap ); + va_end (ap ); + + substituteInterval (&buffer); + + /* change Msg in the query list */ + msg->regexp = strdup(buffer.data); + + /* Send to already connected clients */ + /* recherche dans la liste des requetes recues de mes clients */ + IVY_LIST_EACH( clients, clnt ) { + MsgSendTo( clnt->client, AddRegexp,msg->id,msg->regexp); + } + return msg; +} /* emmission d'un message avec formatage a la printf */ int IvySendMsg(const char *fmt, ...) { @@ -866,6 +904,10 @@ void IvyDefaultBindCallback( IvyClientPtr app, void *user_data, int id, char* re case IvyFilterBind: printf("Application: %s on %s as been filtred regexp %d :%s\n", IvyGetApplicationName( app ), IvyGetApplicationHost(app), id, regexp); break; + case IvyChangeBind: + printf("Application: %s on %s change regexp %d : %s\n", IvyGetApplicationName( app ), IvyGetApplicationHost(app), id, regexp); + break; + break; default: printf("Application: %s unkown event %d\n",IvyGetApplicationName( app ), event); break; diff --git a/src/ivy.h b/src/ivy.h index e892070..0ee4542 100644 --- a/src/ivy.h +++ b/src/ivy.h @@ -29,7 +29,7 @@ extern "C" { typedef struct _clnt_lst *IvyClientPtr; typedef enum { IvyApplicationConnected, IvyApplicationDisconnected } IvyApplicationEvent; -typedef enum { IvyAddBind, IvyRemoveBind, IvyFilterBind } IvyBindEvent; +typedef enum { IvyAddBind, IvyRemoveBind, IvyFilterBind, IvyChangeBind } IvyBindEvent; extern void IvyDefaultApplicationCallback( IvyClientPtr app, void *user_data, IvyApplicationEvent event ) ; extern void IvyDefaultBindCallback( IvyClientPtr app, void *user_data, int id, char* regexp, IvyBindEvent event ) ; @@ -80,6 +80,8 @@ char *IvyGetApplicationList(const char *sep); char **IvyGetApplicationMessages( IvyClientPtr app); /* demande de reception d'un message */ MsgRcvPtr IvyBindMsg( MsgCallback callback, void *user_data, const char *fmt_regexp, ... ); /* avec sprintf prealable */ +MsgRcvPtr IvyChangeMsg (MsgRcvPtr msg, const char *fmt_regex, ... ); /* avec sprintf prealable */ + void IvyUnbindMsg( MsgRcvPtr id ); /* emission d'un message d'erreur */ diff --git a/src/ivyprobe.c b/src/ivyprobe.c index bdf3b9a..b6d9607 100644 --- a/src/ivyprobe.c +++ b/src/ivyprobe.c @@ -266,6 +266,11 @@ void IvyPrintBindCallback( IvyClientPtr app, void *user_data, int id, char* rege printf("Application: %s on %s as been filtred regexp %d :%s\n", IvyGetApplicationName( app ), IvyGetApplicationHost(app), id, regexp); break; + case IvyChangeBind: + if ( fbindcallback ) + printf("Application: %s on %s change regexp %d : %s\n", + IvyGetApplicationName( app ), IvyGetApplicationHost(app), id, regexp); + break; default: printf("Application: %s unkown event %d\n",IvyGetApplicationName( app ), event); break; @@ -276,8 +281,8 @@ void IvyPrintBindCallback( IvyClientPtr app, void *user_data, int id, char* rege #ifdef IVYMAINLOOP void TimerCall(TimerId id, void *user_data, unsigned long delta) { - printf("Timer callback: %d delta %lu ms\n", (int)user_data, delta); - IvySendMsg ("TEST TIMER %d", (int)user_data); + printf("Timer callback: %ld delta %lu ms\n", (long)user_data, delta); + IvySendMsg ("TEST TIMER %d", (long)user_data); /*if ((int)user_data == 5) TimerModify (id, 2000);*/ } #endif @@ -434,3 +439,4 @@ int main(int argc, char *argv[]) #endif return 0; } + -- cgit v1.1