From 1c524fbb574196b00a07589e559bf64de359ef00 Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Sat, 1 Jun 2013 17:13:50 +0000 Subject: [PATCH] Making regexp in Client-List of iodevs work in Dispatch git-svn-id: https://svn.fhem.de/fhem/trunk@3236 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/fhem.pl | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/fhem/fhem.pl b/fhem/fhem.pl index f26bd2555..1d9c1931a 100755 --- a/fhem/fhem.pl +++ b/fhem/fhem.pl @@ -1388,6 +1388,7 @@ AssignIoPort($) my @fnd = grep { $hash->{TYPE} =~ m/^$_$/; } split(":", $cl); if(@fnd) { $hash->{IODev} = $defs{$p}; + delete($defs{$p}{".clientArray"}); # Force a recompute last; } } @@ -2582,21 +2583,19 @@ Dispatch($$$) my @found; - my $cl = $hash->{Clients}; - $cl = $iohash->{Clients} if(!$cl); - foreach my $m (sort { $modules{$a}{ORDER} cmp $modules{$b}{ORDER} } - grep {defined($modules{$_}{ORDER})} keys %modules) { - - next if(!(defined($cl) && $cl =~ m/:$m:/)); + my $clientArray = $hash->{".clientArray"}; + $clientArray = computeClientArray($hash, $iohash) if(!$clientArray); + foreach my $m (@{$clientArray}) { # Module is not loaded or the message is not for this module - next if(!$modules{$m}{Match} || $dmsg !~ m/$modules{$m}{Match}/i); + next if($dmsg !~ m/$modules{$m}{Match}/i); no strict "refs"; $readingsUpdateDelayTrigger = 1; @found = &{$modules{$m}{ParseFn}}($hash,$dmsg); use strict "refs"; $readingsUpdateDelayTrigger = 0; last if(int(@found)); } + if(!int(@found)) { my $h = $hash->{MatchList}; $h = $iohash->{MatchList} if(!$h); if(defined($h)) { @@ -3339,4 +3338,25 @@ fhemTimeLocal($$$$$$) { return $t-fhemTzOffset($t); } +sub +computeClientArray($$) +{ + my ($hash, $iohash) = @_; + my @a = (); + my @mRe = split(":", $hash->{Clients} ? $hash->{Clients}:$iohash->{Clients}); + + foreach my $m (sort { $modules{$a}{ORDER} cmp $modules{$b}{ORDER} } + grep { defined($modules{$_}{ORDER}) } keys %modules) { + foreach my $re (@mRe) { + if($m =~ m/^$re$/) { + push @a, $m if($modules{$m}{Match}); + last; + } + } + } + + $hash->{".clientArray"} = \@a; + return \@a; +} + 1;