2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-16 10:46:03 +00:00

update: Minimize CHANGED-file output, filter events in background mode (Forum #26329)

git-svn-id: https://svn.fhem.de/fhem/trunk@6611 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2014-09-24 07:48:32 +00:00
parent 433c752cb5
commit 91744d09be
4 changed files with 68 additions and 24 deletions

View File

@ -689,8 +689,8 @@ FW_answerCall($)
FW_pO "</head>\n<body name=\"$t\" $csrf $onload>";
if($FW_activateInform) {
$cmd = "style eventMonitor $FW_activateInform";
$FW_cmdret = $FW_activateInform = "";
$cmd = "style eventMonitor";
}
FW_roomOverview($cmd);
@ -1740,8 +1740,13 @@ FW_style($$)
FW_pO "<script type=\"text/javascript\" src=\"$FW_ME/pgm2/console.js\">".
"</script>";
FW_pO "<div id=\"content\">";
FW_pO "<div id=\"console\">";
FW_pO "Events:<br>\n";
if($a[2] && $a[2] ne "1") {
FW_pO "<div id=\"console\" filter=\"$a[2]\">";
FW_pO "Events ($a[2] only):<br>\n";
} else {
FW_pO "<div id=\"console\">";
FW_pO "Events:<br>\n";
}
FW_pO "</div>";
FW_pO "</div>";
@ -2184,7 +2189,11 @@ FW_Notify($$)
return undef if(!$h);
my $dn = $dev->{NAME};
return undef if(!$h->{devices}{$dn} && $h->{type} !~ m/raw/);
if($h->{type} eq "raw") {
return undef if($dn !~ m/$h->{filter}/);
} else { # Status
return undef if(!$h->{devices}{$dn});
}
my @data;
my %extPage;
@ -2558,9 +2567,10 @@ FW_visibleDevices(;$)
}
sub
FW_ActivateInform()
FW_ActivateInform($;$)
{
$FW_activateInform = 1;
my ($cl, $arg) = @_;
$FW_activateInform = ($arg ? $arg : 1);
}
sub

View File

@ -324,11 +324,12 @@ telnet_Undef($$)
}
sub
telnet_ActivateInform($)
telnet_ActivateInform($;$)
{
my ($cl) = @_;
my ($cl, $arg) = @_;
my $name = $cl->{NAME};
CommandInform($cl, "timer") if(!$inform{$name});
$arg = "" if(!defined($arg));
CommandInform($cl, "timer $arg") if(!$inform{$name});
}

View File

@ -51,7 +51,7 @@ CommandUpdate($$)
$updateInBackground = 0 if($arg ne "all");
$updArg = $arg;
if($updateInBackground) {
CallFn($cl->{NAME}, "ActivateInformFn", $cl);
CallFn($cl->{NAME}, "ActivateInformFn", $cl, "global");
BlockingCall("doUpdateInBackground", {src=>$src,arg=>$arg});
return "Executing the update the background.";
@ -150,8 +150,7 @@ doUpdate($$)
my @excl = split(" ", AttrVal("global", "exclude_from_update", ""));
uLog 1, "List of new / modified files since last update:"
if($arg eq "check");
my @rl = upd_getChanges($root, $basePath);
###########################
# process the remote controlfile
my $nChanged = 0;
@ -194,6 +193,8 @@ doUpdate($$)
}
uLog 1, "List of new / modified files since last update:"
if($arg eq "check" && $nChanged == 0);
uLog 1, "$r[0] $fName";
$nChanged++;
next if($arg eq "check");
@ -222,17 +223,12 @@ doUpdate($$)
return;
}
if($arg eq "check") {
my @lines = split(/[\r\n]/,upd_getUrl("$basePath/CHANGED"));
my $ret = "";
foreach my $line (@lines) {
next if($line =~ m/^#/);
last if($line eq "");
$ret .= $line."\n";
}
uLog 1, "\nList of last changes:\n".$ret;
return;
if(@rl) {
uLog(1, "");
uLog 1, "New entries in the CHANGED file:";
map { uLog 1, $_ } @rl;
}
return if($arg eq "check");
if($arg eq "all" || $arg eq "force") { # store the controlfile
return if(!upd_writeFile($root, $restoreDir,
@ -272,6 +268,35 @@ upd_mkDir($$$)
}
}
sub
upd_getChanges($$)
{
my ($root, $basePath) = @_;
my $lFile = "";
if(open(FH, "$root/CHANGED")) {
foreach my $l (<FH>) { # first non-comment line
next if($l =~ m/^#/);
chomp $l;
$lFile = $l;
last;
}
close(FH);
}
my @lines = split(/[\r\n]/,upd_getUrl("$basePath/CHANGED"));
my $maxLines = 25;
my @ret;
foreach my $line (@lines) {
next if($line =~ m/^#/);
last if($line eq "" || $line eq $lFile);
push @ret, $line;
if($maxLines-- < 1) {
push @ret, "... rest of lines skipped.";
last;
}
}
return @ret;
}
sub
upd_getUrl($)
{

View File

@ -1,6 +1,7 @@
var consConn;
var isFF = (navigator.userAgent.toLowerCase().indexOf('firefox') > -1);
var consFilter, consTxt;
log("Console is opening");
@ -18,7 +19,7 @@ consUpdate()
var el = document.getElementById("console");
if(el) {
el.innerHTML="Events:<br>"+consConn.responseText;
el.innerHTML=consTxt+consConn.responseText;
el.scrollTop = el.scrollHeight;
}
}
@ -27,9 +28,10 @@ function
consFill()
{
FW_errmsg("");
consConn = new XMLHttpRequest();
var query = document.location.pathname+"?XHR=1"+
"&inform=type=raw;filter=.*"+
"&inform=type=raw;filter="+consFilter+
"&timestamp="+new Date().getTime();
query = addcsrf(query);
consConn.open("GET", query, true);
@ -40,6 +42,12 @@ consFill()
function
consStart()
{
var el = document.getElementById("console");
consFilter = el.getAttribute("filter");
if(consFilter == undefined)
consFilter = ".*";
consTxt = el.innerHTML;
setTimeout("consFill()", 1000);
}