From bda2a9a8be5214bd0454f700bcdbcb087b0ce089 Mon Sep 17 00:00:00 2001 From: bustico Date: Thu, 21 Sep 2006 09:57:53 +0000 Subject: Ajout de la methode changeRegexp qui permet de changer la regexp d'un abonnement precedemment fait avec bindRegexp de manière atomique. --- Ivy.pm | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 14 deletions(-) (limited to 'Ivy.pm') diff --git a/Ivy.pm b/Ivy.pm index 5918ba7..0441d4e 100644 --- a/Ivy.pm +++ b/Ivy.pm @@ -88,6 +88,9 @@ sub DESTROY ($); # - envoie un BYE et cl sub bindRegexp ($$$;$) ; # permet d'associer une regexp avec un callBack # ou d'annuler une precedente association +sub changeRegexp ($$$); # permet de changer une regexp d'un abonnement + # precedemment fait avec bindRegexp + sub bindDirect; # permet d'associer un identifiant de msg direct # avec une fonction de callBack, ou de l'annuler @@ -882,8 +885,39 @@ sub bindRegexp ($$$;$) return ($id); } # end bindRegexp +############### PROCEDURE BIND REGEXP +sub changeRegexp ($$$) +{ + my $self = ref($_[0]) eq __PACKAGE__ ? shift : $globalIvy; + my ($regexpId, $regexp) = @_; + + $regexp =~ s| + \(\?I # l'extension (?I + ([\d-]+) # la borne inférieure + \# # l'operateur d'intervalle + ([\d-]+) # la borne supérieure + ([if]?) # le caractère de codage f pour flottant, i pour integer, flottant par defaut + \) # la parenthèse fermante + | + _regexpGen ($1, $2, $3); + |xge; + + # print ("DBG> regexp = $regexp\n"); + if ($^W) { + eval {my $test = "a" =~ /$regexp/ } ; # testing the regexp for avoiding + if ($@) { + carp "Warning in Ivy::changeRegexp, ill-formed regexp: '$regexp'" ; + return; + }; + } + + $self->[recCbList][$regexpId]->[0] = $regexp; + _sendLastRegexpToAllreadyConnected ($self, $regexpId) ; + return ($regexpId); +} # end changeRegexp + ############### METHODE BIND REGEXP -sub bindDirect +sub bindDirect { my $self = ref($_[0]) eq __PACKAGE__ ? shift : $globalIvy; my ($id, $cb) = @_; @@ -1462,12 +1496,10 @@ sub _getMessages ($$) &_scanConnStatus ($self, $senderName, 'subscribing', join (':', _getHostByAddr ($addr), $peerPort), $valeurs); } - unless (defined $self->[sendRegList]{$appSock}->[$id]) { - # si l'id de regexp n'etait pas utilisee c'est tout bon - # on affecte la nouvelle regexp a un id - $self->[sendRegListSrc]{$appSock}->[$id] = $valeurs; - $self->[sendRegList]{$appSock}->[$id] = - eval ('sub {@{$_[1]} = ${$_[0]} =~ /($valeurs)/io;}'); + # on affecte la nouvelle regexp a un id + $self->[sendRegListSrc]{$appSock}->[$id] = $valeurs; + $self->[sendRegList]{$appSock}->[$id] = + eval ('sub {@{$_[1]} = ${$_[0]} =~ /($valeurs)/io;}'); # $self->[sendRegList]{$appSock}->[$id] = eval <<'_EOL_'; @@ -1492,12 +1524,6 @@ sub _getMessages ($$) # return 1; # } # _EOL_ - } else { - # l'id de la regexp etait deja utilise, - # et n'a pas ete libere par un message delregexp, - # on renvoie donc un message d'erreur - $self->_sendErrorTo($appSock, "ID $id deja utilisee"); - } } elsif ($type == ERROR) { # E R R O R carp ("Warning in Ivy::_getMessages, error message received from ". @@ -2112,7 +2138,7 @@ sub _regexpGen ($$$) { my ($min, $max, $withDecimal) = @_; - print ("DBG> min=$min max=$max withDecimal=$withDecimal\n"); +# print ("DBG> min=$min max=$max withDecimal=$withDecimal\n"); ($min, $max) = ($max, $min) if $min > $max; @@ -2646,6 +2672,19 @@ Return value : regexpId # to unbind: $ivyobject->bindRegexp("\w+ (\d+)"); +=item B + + $regexpId = $ivyobject->bindRegexp("initialRegexp", [\&callback, @cb_parameters]); + $ivyobject->changeRegexp($regexpId, "newRegexp"); + or + Ivy::changeRegexp($regexpId, "newRegexp"); + +This allow you to change the regexp of a previously made bindRegexp, the callback +will remain the same. This is equivalent to unbinding current regexp and binding the new regexp, +but in this last case the 2 op are not done in atomic manner, and you can miss a message +or receive it twice. + + =item B $ivyobj->sendDirectMsgs($to, $id, @msgs); -- cgit v1.1