2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

updateInBackground global attribute

git-svn-id: https://svn.fhem.de/fhem/trunk@3373 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2013-06-30 19:42:31 +00:00
parent 5b114fcb11
commit 5d7984eb3c
10 changed files with 144 additions and 32 deletions

View File

@ -1,8 +1,9 @@
# Add changes at the top of the list. Keep it in ASCII # Add changes at the top of the list. Keep it in ASCII
- SVN - SVN
- feature: updateInBackground global attribute
- feature: SYSSTAT: allow stateFormat - feature: SYSSTAT: allow stateFormat
- feature: Module 70_VIERA supports now module 95_remotecontrol with own layout - feature: Module 70_VIERA supports now module 95_remotecontrol with own
for VIERA TV layout for VIERA TV
- feature: InternalVal function added (like ReadingsVal) - feature: InternalVal function added (like ReadingsVal)
- feature: new module speedtest to monitor internet connection speed with - feature: new module speedtest to monitor internet connection speed with
speedtest-cli speedtest-cli

View File

@ -75,6 +75,7 @@ use vars qw(%FW_webArgs); # all arguments specified in the GET
my $FW_zlib_checked; my $FW_zlib_checked;
my $FW_use_zlib = 1; my $FW_use_zlib = 1;
my $FW_activateInform = 0;
######################### #########################
# As we are _not_ multithreaded, it is safe to use global variables. # As we are _not_ multithreaded, it is safe to use global variables.
@ -113,6 +114,7 @@ FHEMWEB_Initialize($)
$hash->{DefFn} = "FW_Define"; $hash->{DefFn} = "FW_Define";
$hash->{UndefFn} = "FW_Undef"; $hash->{UndefFn} = "FW_Undef";
$hash->{NotifyFn}= "FW_SecurityCheck"; $hash->{NotifyFn}= "FW_SecurityCheck";
$hash->{ActivateInformFn} = "FW_ActivateInform";
$hash->{AttrList}= $hash->{AttrList}=
"loglevel:0,1,2,3,4,5,6 webname fwcompress:0,1 ". "loglevel:0,1,2,3,4,5,6 webname fwcompress:0,1 ".
"plotmode:gnuplot,gnuplot-scroll,SVG plotsize endPlotToday:1,0 plotfork ". "plotmode:gnuplot,gnuplot-scroll,SVG plotsize endPlotToday:1,0 plotfork ".
@ -554,6 +556,11 @@ FW_answerCall($)
"onload=\"FW_delayedStart()\"" : ""; "onload=\"FW_delayedStart()\"" : "";
FW_pO "</head>\n<body name=\"$t\" $onload>"; FW_pO "</head>\n<body name=\"$t\" $onload>";
if($FW_activateInform) {
$FW_cmdret = $FW_activateInform = "";
$cmd = "style eventMonitor";
}
if($FW_cmdret) { if($FW_cmdret) {
$FW_detail = ""; $FW_detail = "";
$FW_room = ""; $FW_room = "";
@ -2406,7 +2413,11 @@ FW_Notify($$)
# Collect multiple changes (e.g. from noties) into one message # Collect multiple changes (e.g. from noties) into one message
$ntfy->{INFORMBUF} .= $data; $ntfy->{INFORMBUF} .= $data;
RemoveInternalTimer($ln); RemoveInternalTimer($ln);
InternalTimer(gettimeofday()+0.1, "FW_FlushInform", $ln, 0); if(length($ntfy->{INFORMBUF}) > 1024) {
FW_FlushInform($ln);
} else {
InternalTimer(gettimeofday()+0.1, "FW_FlushInform", $ln, 0);
}
} }
return undef; return undef;
@ -2674,6 +2685,12 @@ FW_dropdownFn()
return undef; return undef;
} }
sub
FW_ActivateInform()
{
$FW_activateInform = 1;
}
1; 1;
=pod =pod

View File

@ -163,6 +163,7 @@ createArchiv($)
$dateTime =~ s/ /_/g; $dateTime =~ s/ /_/g;
$dateTime =~ s/(:|-)//g; $dateTime =~ s/(:|-)//g;
my $cmd="";
if (!defined($backupcmd)) { if (!defined($backupcmd)) {
if (lc($symlink) eq "no") { if (lc($symlink) eq "no") {
$tarOpts = "cf"; $tarOpts = "cf";
@ -171,10 +172,13 @@ createArchiv($)
} }
# prevents tar's output of "Removing leading /" and return total bytes of archive # prevents tar's output of "Removing leading /" and return total bytes of archive
$ret = `(tar -$tarOpts - @pathname | gzip > $backupdir/FHEM-$dateTime.tar.gz) 2>&1`; $cmd = "tar -$tarOpts - @pathname |gzip > $backupdir/FHEM-$dateTime.tar.gz";
} else { } else {
$ret = `($backupcmd "@pathname") 2>&1`; $ret = "$backupcmd \"@pathname\"";
} }
Log 2, "Backup with command: $cmd";
$ret = `($cmd) 2>&1`;
if($ret) { if($ret) {
chomp $ret; chomp $ret;
Log 1, "backup $ret"; Log 1, "backup $ret";

View File

@ -22,6 +22,10 @@ telnet_Initialize($)
$hash->{NotifyFn}= "telnet_SecurityCheck"; $hash->{NotifyFn}= "telnet_SecurityCheck";
$hash->{AttrList} = "loglevel:0,1,2,3,4,5,6 globalpassword password ". $hash->{AttrList} = "loglevel:0,1,2,3,4,5,6 globalpassword password ".
"allowfrom SSL connectTimeout connectInterval"; "allowfrom SSL connectTimeout connectInterval";
$hash->{AttrList} = "loglevel:0,1,2,3,4,5,6 globalpassword password ".
"allowfrom SSL connectTimeout connectInterval";
$hash->{ActivateInformFn} = "telnet_ActivateInform";
} }
##################################### #####################################
@ -292,6 +296,15 @@ telnet_Undef($$)
return TcpServer_Close($hash); return TcpServer_Close($hash);
} }
sub
telnet_ActivateInform($)
{
my ($cl) = @_;
my $name = $cl->{NAME};
CommandInform($cl, "timer") if(!$inform{$name});
}
1; 1;
=pod =pod

View File

@ -27,6 +27,7 @@ use strict;
use warnings; use warnings;
use HttpUtils; use HttpUtils;
use File::Copy qw(cp mv); use File::Copy qw(cp mv);
use Blocking;
sub CommandUpdate($$); sub CommandUpdate($$);
sub update_CheckFhemRelease($$$); sub update_CheckFhemRelease($$$);
@ -192,19 +193,61 @@ CommandUpdate($$)
($notice,$unconfirmed) = update_CheckNotice($BRANCH,$update,"before"); ($notice,$unconfirmed) = update_CheckNotice($BRANCH,$update,"before");
$ret .= $notice if(defined($notice)); $ret .= $notice if(defined($notice));
return $ret if($unconfirmed); return $ret if($unconfirmed);
$ret .= update_DoUpdate($srcdir,$BRANCH,$update,$force,$cl);
($notice,$unconfirmed) = update_CheckNotice($BRANCH,$update,"after"); if(AttrVal("global","updateInBackground",undef)) {
$ret .= $notice if(defined($notice)); CallFn($cl->{NAME}, "ActivateInformFn", $cl);
my $sendStatistics = AttrVal("global","sendStatistics",undef); BlockingCall("update_DoUpdateInBackground", {srcdir=>$srcdir,
if(defined($sendStatistics) && lc($sendStatistics) eq "onupdate") { BRANCH=>$BRANCH, update=>$update, force=>$force,cl=>$cl});
$ret .= "\n\n"; $ret = "Executing the update the background.";
$ret .= AnalyzeCommandChain(undef, "fheminfo send");
} else {
$ret .= update_DoUpdate($srcdir,$BRANCH,$update,$force,$cl);
($notice,$unconfirmed) = update_CheckNotice($BRANCH,$update,"after");
$ret .= $notice if(defined($notice));
my $sendStatistics = AttrVal("global","sendStatistics",undef);
if(defined($sendStatistics) && lc($sendStatistics) eq "onupdate") {
$ret .= "\n\n";
$ret .= AnalyzeCommandChain(undef, "fheminfo send");
}
} }
} }
return $ret; return $ret;
} }
my $inLog = 0;
sub
update_Log2Event($$)
{
my ($level, $text) = @_;
return if($inLog || $level > $attr{global}{verbose});
$inLog = 1;
BlockingInformParent("DoTrigger", ["global", $text, 1], 0);
BlockingInformParent("Log", [$level, $text], 0);
$inLog = 0;
}
sub
update_DoUpdateInBackground($)
{
my ($h) = @_;
no warnings 'redefine'; # The main process is not affected
*Log = \&update_Log2Event;
sleep(2); # Give time for ActivateInform / FHEMWEB / JavaScript
my $ret = update_DoUpdate($h->{srcdir}, $h->{BRANCH}, $h->{update},
$h->{force}, $h->{cl});
my ($notice,$unconfirmed) =
update_CheckNotice($h->{BRANCH}, $h->{update}, "after");
$ret .= $notice if(defined($notice));
if(lc(AttrVal("global","sendStatistics","")) eq "onupdate") {
$ret .= "\n\n";
$ret .= AnalyzeCommandChain(undef, "fheminfo send");
}
}
######################################## ########################################
sub sub
update_CheckNotice($$$) update_CheckNotice($$$)

View File

@ -22,6 +22,7 @@ sub BlockingKill($);
sub BlockingInformParent($;$$); sub BlockingInformParent($;$$);
my $telnetDevice; my $telnetDevice;
my $telnetClient;
sub sub
BlockingCall($$@) BlockingCall($$@)
@ -102,30 +103,36 @@ BlockingInformParent($;$$)
$waitForRead = 1 if (!defined($waitForRead)); $waitForRead = 1 if (!defined($waitForRead));
# Write the data back, calling the function # Write the data back, calling the function
my $addr = "localhost:$defs{$telnetDevice}{PORT}"; if(!$telnetClient) {
my $client = IO::Socket::INET->new(PeerAddr => $addr); my $addr = "localhost:$defs{$telnetDevice}{PORT}";
Log 1, "CallBlockingFn: Can't connect to $addr\n" if(!$client); $telnetClient = IO::Socket::INET->new(PeerAddr => $addr);
Log 1, "CallBlockingFn: Can't connect to $addr\n" if(!$telnetClient);
if (defined($param)) {
$param =~ s/'/\\'/g;
$param = "'$param'"
} else {
$param = "";
} }
syswrite($client, "{$informFn($param)}\n"); if(defined($param)) {
if(ref($param) eq "ARRAY") {
$param = join(",", map { $_ =~ s/'/\\'/g; "'$_'" } @{$param});
} else {
$param =~ s/'/\\'/g;
$param = "'$param'"
}
} else {
$param = "";
}
syswrite($telnetClient, "{$informFn($param)}\n");
if ($waitForRead) { if ($waitForRead) {
my $len = sysread($client, $ret, 4096); my $len = sysread($telnetClient, $ret, 4096);
chop($ret); chop($ret);
$ret = undef if(!defined($len)); $ret = undef if(!defined($len));
} }
close($client) if($client);
return $ret; return $ret;
} }
# Parent
sub sub
BlockingKill($) BlockingKill($)
{ {
@ -148,9 +155,11 @@ BlockingKill($)
} }
} }
# Child
sub sub
BlockingExit() BlockingExit()
{ {
close($telnetClient) if($telnetClient);
if($^O =~ m/Win/) { if($^O =~ m/Win/) {
eval "require threads;"; eval "require threads;";

View File

@ -982,6 +982,13 @@ A line ending with \ will be concatenated with the next one, so long lines
receiving a corresponding message. receiving a corresponding message.
</li><br> </li><br>
<a name="updateInBackground"></a>
<li>updateInBackground<br>
If this attribute is set to 1, the update will be executed in the
backgrund process. The return message is communicated via events, and
in telnet the inform command is activated, in FHEMWEB the Event
Monitor.
</li><br>
<a name="backup_before_update"></a> <a name="backup_before_update"></a>
<li>backup_before_update<br> <li>backup_before_update<br>

View File

@ -1019,12 +1019,20 @@ Zeilen erstreckende Befehle, indem man keine \ am Zeilenende eingeben muss.</p>
<a name="autoload_undefined_devices"></a> <a name="autoload_undefined_devices"></a>
<li>autoload_undefined_devices<br> <li>autoload_undefined_devices<br>
wenn dieses Attribut gesetzt ist, werden die zu einer neu empfangenen wenn dieses Attribut gesetzt ist, werden die zu einer neu empfangenen
Nachricht zugeh&ouml;rigen Module automatisch geladen.&nbsp; Dies erfolgt vom <a href="#autocreate"> Nachricht zugeh&ouml;rigen Module automatisch geladen.&nbsp; Dies
autocreate</a> Ger&auml;t, um so automatisch ein FHEM-Ger&auml;t bei erreichen erfolgt vom <a href="#autocreate"> autocreate</a> Ger&auml;t, um so
einer entsprechenden Nachricht zu erstellen. automatisch ein FHEM-Ger&auml;t bei erreichen einer entsprechenden
Nachricht zu erstellen.
</li><br> </li><br>
<a name="updateInBackground"></a>
<li>updateInBackground<br>
wenn dieses Attribut gesetzt ist, wird das update Befehl in einem
separaten Prozess ausgef&uuml;hrt, und alle Meldungen werden per Event
&uuml;bermittelt. In der telnet Sitzung wird inform, in FHEMWEB wird
das Event Monitor aktiviert.
</li><br>
<a name="backup_before_update"></a> <a name="backup_before_update"></a>
<li>backup_before_update<br> <li>backup_before_update<br>

View File

@ -167,6 +167,7 @@ use vars qw(%data); # Hash for user data
use vars qw($devcount); # To sort the devices use vars qw($devcount); # To sort the devices
use vars qw(%defaultattr); # Default attributes, used by FHEM2FHEM use vars qw(%defaultattr); # Default attributes, used by FHEM2FHEM
use vars qw(%addNotifyCB); # Used by event enhancers (e.g. avarage) use vars qw(%addNotifyCB); # Used by event enhancers (e.g. avarage)
use vars qw(%inform); # Used by telnet_ActivateInform
use vars qw($reread_active); use vars qw($reread_active);
@ -177,7 +178,6 @@ my $ipv6; # Using IPV6
my $currlogfile; # logfile, without wildcards my $currlogfile; # logfile, without wildcards
my $currcfgfile=""; # current config/include file my $currcfgfile=""; # current config/include file
my $logopened = 0; # logfile opened or using stdout my $logopened = 0; # logfile opened or using stdout
my %inform; # Inform hash
my $rcvdquit; # Used for quit handling in init files my $rcvdquit; # Used for quit handling in init files
my $sig_term = 0; # if set to 1, terminate (saving the state) my $sig_term = 0; # if set to 1, terminate (saving the state)
my %intAt; # Internal at timer hash. my %intAt; # Internal at timer hash.
@ -207,7 +207,7 @@ $modules{Global}{AttrList} =
"autoload_undefined_devices:1,0 dupTimeout latitude longitude " . "autoload_undefined_devices:1,0 dupTimeout latitude longitude " .
"backupcmd backupdir backupsymlink backup_before_update " . "backupcmd backupdir backupsymlink backup_before_update " .
"exclude_from_update motd updatebranch uniqueID ". "exclude_from_update motd updatebranch uniqueID ".
"sendStatistics:onUpdate,manually,never ". "sendStatistics:onUpdate,manually,never updateInBackground:1,0".
"showInternalValues:1,0 "; "showInternalValues:1,0 ";
$modules{Global}{AttrFn} = "GlobalAttr"; $modules{Global}{AttrFn} = "GlobalAttr";

View File

@ -1,5 +1,7 @@
var consConn; var consConn;
var isFF = (navigator.userAgent.toLowerCase().indexOf('firefox') > -1);
function function
consUpdate() consUpdate()
{ {
@ -15,8 +17,16 @@ consUpdate()
return; return;
var el = document.getElementById("console"); var el = document.getElementById("console");
if(el) if(el) {
el.innerHTML="Events:<br>"+consConn.responseText; el.innerHTML="Events:<br>"+consConn.responseText;
// Scroll to bottom. FF is different from Safari/Chrome
var p = el.parentElement; // content div
if(isFF)
p.parentElement.parentElement.scrollTop = p.scrollHeight; // html tag
else
p.parentElement.scrollTop = p.scrollHeight; // body tag
console.log("P4:"+p.scrollHeight);
}
} }
function function