2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-20 13:26:02 +00:00

preventing multiple ctlmgr_ctl calls in mode fritzbox

git-svn-id: https://svn.fhem.de/fhem/trunk@3198 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
markusbloch 2013-05-19 16:47:50 +00:00
parent 4e59df9289
commit 81da85e68a

View File

@ -540,6 +540,31 @@ PRESENCE_DoLocalPingScan($)
} }
sub
PRESENCE_ExecuteFritzBoxCMD($$)
{
my ($name, $cmd) = @_;
my $status;
my $wait;
while(-e "/var/tmp/fhem-PRESENCE-cmd-lock.tmp")
{
$wait = int(rand(4))+2;
Log GetLogLevel($name, 5), "PRESENCE_ExecuteFritzBoxCMD: ($name) - ctlmgr_ctl is locked. waiting $wait seconds...";
sleep $wait;
}
qx(touch /var/tmp/fhem-PRESENCE-cmd-lock.tmp);
$status = qx($cmd);
qx(rm /var/tmp/fhem-PRESENCE-cmd-lock.tmp);
return $status;
}
sub sub
PRESENCE_DoLocalFritzBoxScan($) PRESENCE_DoLocalFritzBoxScan($)
{ {
@ -558,16 +583,16 @@ PRESENCE_DoLocalFritzBoxScan($)
{ {
$number = $defs{$name}{helper}{cachednr}; $number = $defs{$name}{helper}{cachednr};
Log GetLogLevel($name, 5), "PRESENCE_DoLocalFritzBoxScan: name=$name device=$device cachednr=$number"; Log GetLogLevel($name, 5), "PRESENCE_DoLocalFritzBoxScan: try checking $name as device $device with cached number $number";
my $cached_name = qx(/usr/bin/ctlmgr_ctl r landevice settings/landevice$number/name); my $cached_name = PRESENCE_ExecuteFritzBoxCMD($name, "/usr/bin/ctlmgr_ctl r landevice settings/landevice$number/name");
chomp $cached_name; chomp $cached_name;
# only use the cached $number if it has still the correct device name # only use the cached $number if it has still the correct device name
if($cached_name eq $device) if($cached_name eq $device)
{ {
Log GetLogLevel($name, 5), "PRESENCE ($name) - checking with cached number the $check_command state ($number)"; Log GetLogLevel($name, 5), "PRESENCE ($name) - checking with cached number the $check_command state ($number)";
$status = qx(/usr/bin/ctlmgr_ctl r landevice settings/landevice$number/$check_command); $status = PRESENCE_ExecuteFritzBoxCMD($name, "/usr/bin/ctlmgr_ctl r landevice settings/landevice$number/$check_command");
chomp $status; chomp $status;
@ -585,7 +610,7 @@ PRESENCE_DoLocalFritzBoxScan($)
} }
} }
my $max = qx(/usr/bin/ctlmgr_ctl r landevice settings/landevice/count); my $max = PRESENCE_ExecuteFritzBoxCMD($name, "/usr/bin/ctlmgr_ctl r landevice settings/landevice/count");
chomp $max; chomp $max;
@ -604,14 +629,14 @@ PRESENCE_DoLocalFritzBoxScan($)
while($number <= $max) while($number <= $max)
{ {
$net_device=qx(/usr/bin/ctlmgr_ctl r landevice settings/landevice$number/name); $net_device = PRESENCE_ExecuteFritzBoxCMD($name, "/usr/bin/ctlmgr_ctl r landevice settings/landevice$number/name");
chomp $net_device; chomp $net_device;
Log GetLogLevel($name, 5), "PRESENCE ($name) - checking with device number $number the $check_command state ($net_device)"; Log GetLogLevel($name, 5), "PRESENCE ($name) - checking with device number $number the $check_command state ($net_device)";
if($net_device eq $device) if($net_device eq $device)
{ {
$status=qx(/usr/bin/ctlmgr_ctl r landevice settings/landevice$number/$check_command); $status = PRESENCE_ExecuteFritzBoxCMD($name, "/usr/bin/ctlmgr_ctl r landevice settings/landevice$number/$check_command");
chomp $status; chomp $status;
@ -626,6 +651,7 @@ PRESENCE_DoLocalFritzBoxScan($)
return ($status == 0 ? "$name|$local|absent" : "$name|$local|present").($number <= $max ? "|$number" : ""); return ($status == 0 ? "$name|$local|absent" : "$name|$local|present").($number <= $max ? "|$number" : "");
} }
sub sub
PRESENCE_DoLocalBluetoothScan($) PRESENCE_DoLocalBluetoothScan($)
{ {