2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 12:49:34 +00:00

98_update.pm: simplify updateInBackground logging (Forum #47203)

git-svn-id: https://svn.fhem.de/fhem/trunk@10551 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2016-01-17 11:03:44 +00:00
parent 5af31be6bc
commit d966db1a4c
8 changed files with 86 additions and 66 deletions

View File

@ -1,12 +1,11 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it.
- feature: update is executed per default in the background
- bugfix: FB_CALLLIST: fix "Use of uninitialized value" warnings on startup
- feature: 2016-01-17 - ***
*** Do not worry about a lot of updates. Many
*** modules were modified only to support the
*** new commandref mechanism for automatic
*** classification of helper and command modules.
***
- feature: *** 2016-01-17
*** Do not worry about a lot of updates. Many modules were
*** modified only to support the new commandref mechanism for
*** automatic classification of helper and command modules.
- change: 49_SSCam: Change of define-string related to rectime.
Note: see all changes of rectime usage in commandref
or in Forum:

View File

@ -2001,10 +2001,11 @@ FW_style($$)
FW_pO "<script type=\"text/javascript\" src=\"$FW_ME/pgm2/console.js\">".
"</script>";
FW_pO "<div id=\"content\">";
my $filter = ($a[2] && $a[2] ne "1") ? $a[2] : ".*";
my $filter = ($a[2] && $a[2] ne "log") ? $a[2] : ".*";
FW_pO "Events (Filter: <a href=\"#\" id=\"eventFilter\">$filter</a>) ".
"&nbsp;&nbsp;<span class='changed'>FHEM log ".
"<input id='eventWithLog' type='checkbox'></span>".
"&nbsp;&nbsp;<span class='fhemlog'>FHEM log ".
"<input id='eventWithLog' type='checkbox'".
($a[2] && $a[2] eq "log" ? " checked":"")."></span>".
"&nbsp;&nbsp;<button id='eventReset'>Reset</button><br><br>\n";
FW_pO "<div id=\"console\"></div>";
FW_pO "</div>";
@ -2482,7 +2483,7 @@ FW_logInform($$)
return;
}
$msg = FW_htmlEscape($msg);
if(!addToWritebuffer($ntfy, "<div class='changed'>$msg</div>") ){
if(!addToWritebuffer($ntfy, "<div class='fhemlog'>$msg</div>") ){
TcpServer_Close($ntfy);
delete $logInform{$me};
delete $defs{$me};

View File

@ -26,11 +26,14 @@ telnet_Initialize($)
"encoding:utf8,latin1 sslVersion";
$hash->{ActivateInformFn} = "telnet_ActivateInform";
my %lhash = ( Fn=>"CommandTelnetEncoding",
ClientFilter => "telnet",
Hlp=>"[utf8|latin1],query and set the character encoding ".
"for the current telnet session" );
$cmds{encoding} = \%lhash;
$cmds{encoding} = { Fn=>"CommandTelnetEncoding",
ClientFilter => "telnet",
Hlp=>"[utf8|latin1],query and set the character encoding ".
"for the current telnet session" };
$cmds{inform} = { Fn=>"CommandTelnetInform",
ClientFilter => "telnet",
Hlp=>"{on|off|log|raw|timer|status},echo all events to this client" };
}
sub
@ -348,16 +351,59 @@ sub
telnet_Undef($$)
{
my ($hash, $arg) = @_;
delete($logInform{$hash->{NAME}});
delete($inform{$hash->{NAME}});
return TcpServer_Close($hash);
}
#####################################
sub
telnet_ActivateInform($;$)
CommandTelnetInform($$)
{
my ($cl, $arg) = @_;
my ($cl, $param) = @_;
return if(!$cl);
my $name = $cl->{NAME};
$arg = "" if(!defined($arg));
CommandInform($cl, "timer $arg") if(!$inform{$name});
return "Usage: inform {on|off|raw|timer|log|status} [regexp]"
if($param !~ m/^(on|off|raw|timer|log|status)/);
if($param eq "status") {
my $i = $inform{$name};
return $i ? ($i->{type} . ($i->{regexp} ? " ".$i->{regexp} : "")) : "off";
}
if($param eq "off") {
delete($logInform{$name});
delete($inform{$name});
} elsif($param eq "log") {
$logInform{$name} = sub($$){
my ($me, $msg) = @_; # _NO_ Log3 here!
telnet_Output($defs{$me}, $msg."\n");
}
} elsif($param ne "off") {
my ($type, $regexp) = split(" ", $param);
$inform{$name}{NR} = $cl->{NR};
$inform{$name}{type} = $type;
if($regexp) {
eval { "Hallo" =~ m/$regexp/ };
return "Bad regexp: $@" if($@);
$inform{$name}{regexp} = $regexp;
}
Log 4, "Setting inform to $param";
}
return undef;
}
sub
telnet_ActivateInform($)
{
my ($cl) = @_;
CommandTelnetInform($cl, "log");
}

View File

@ -25,6 +25,7 @@ my $updArg;
my $mainPgm = "/fhem.pl\$";
my %upd_connecthash;
my $upd_needJoin;
my $upd_nChanged;
########################################
@ -64,11 +65,11 @@ CommandUpdate($$)
if($arg =~ m/^[-\?\*]/ || $ret);
$arg = lc($arg) if($arg =~ m/^(check|all|force)$/i);
$updateInBackground = AttrVal("global","updateInBackground",undef);
$updateInBackground = AttrVal("global","updateInBackground",1);
$updateInBackground = 0 if($arg ne "all");
$updArg = $arg;
if($updateInBackground) {
CallFn($cl->{NAME}, "ActivateInformFn", $cl, "global");
CallFn($cl->{NAME}, "ActivateInformFn", $cl, "log");
BlockingCall("doUpdateInBackground", {src=>$src,arg=>$arg});
return "Executing the update the background.";
@ -167,7 +168,6 @@ update_Log2Event($$)
return if($inLog || $level > $attr{global}{verbose});
$inLog = 1;
$text =~ s/\n/ /g; # Multiline text causes havoc in Analyze
BlockingInformParent("DoTrigger", ["global", $text, 1], 0);
BlockingInformParent("Log", [$level, $text], 0);
$inLog = 0;
}
@ -189,6 +189,7 @@ doUpdateLoop($$)
my ($src, $arg) = @_;
$upd_needJoin = 0;
$upd_nChanged = 0;
if($src =~ m/^http.*/) {
doUpdate(1,1, $src, $arg);
HttpUtils_Close(\%upd_connecthash);
@ -233,7 +234,8 @@ doUpdate($$$$)
$ctrlFileName =~ m/controls_(.*).txt/;
my $srcName = $1;
if(AttrVal("global", "backup_before_update", 0) && $arg ne "check" && $curr==1) {
if(AttrVal("global", "backup_before_update", 0) &&
$arg ne "check" && $curr==1) {
my $cmdret = AnalyzeCommand(undef, "backup");
if ($cmdret !~ m/backup done.*/) {
uLog 1, "Something went wrong during backup: $cmdret";
@ -391,7 +393,8 @@ doUpdate($$$$)
}
}
return "" if(!$nChanged);
$upd_nChanged += $nChanged;
return "" if(!$upd_nChanged);
uLog(1, "");
if($curr == $max) {
@ -658,7 +661,7 @@ upd_initRestoreDirs($)
If this attribute is set (to 1), the update will be executed in a
background process. The return message is communicated via events, and
in telnet the inform command is activated, in FHEMWEB the Event
Monitor.
Monitor. Default is set. Set it to 0 to switch it off.
</li><br>
<a name="updateNoFileCheck"></a>
@ -760,7 +763,8 @@ upd_initRestoreDirs($)
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.
das Event Monitor aktiviert. Die Voreinstellung ist an, zum
Deaktivieren bitte Attribut auf 0 setzen.
</li><br>
<a name="updateNoFileCheck"></a>

View File

@ -139,7 +139,6 @@ sub CommandDisplayAttr($$);
sub CommandGet($$);
sub CommandIOWrite($$);
sub CommandInclude($$);
sub CommandInform($$);
sub CommandList($$);
sub CommandModify($$);
sub CommandQuit($$);
@ -333,9 +332,6 @@ $readingFnAttributes = "event-on-change-reading event-on-update-reading ".
Hlp=>"<devspec> <type dependent>,request data from <devspec>" },
"include" => { Fn=>"CommandInclude",
Hlp=>"<filename>,read the commands from <filenname>" },
"inform" => { Fn=>"CommandInform",
ClientFilter => "telnet",
Hlp=>"{on|off|raw|timer|status},echo all events to this client" },
"iowrite" => { Fn=>"CommandIOWrite",
Hlp=>"<iodev> <data>,write raw data with iodev" },
"list" => { Fn=>"CommandList",
@ -498,7 +494,7 @@ if(time() < 2*3600) {
require RTypes;
RTypes_Initialize();
my $cfgErrMsg = "Error messages while initializing FHEM:";
my $cfgErrMsg = "Messages collected while initializing FHEM:";
my $cfgRet="";
if(configDBUsed()) {
my $ret = cfgDB_ReadAll(undef);
@ -838,7 +834,11 @@ Log3($$$)
no strict "refs";
foreach my $li (keys %logInform) {
&{$logInform{$li}}($li, "$tim $loglevel : $text");
if($defs{$li}) {
&{$logInform{$li}}($li, "$tim $loglevel : $text");
} else {
delete $logInform{$li};
}
}
use strict "refs";
@ -2637,40 +2637,6 @@ CommandTrigger($$)
return join("\n", @rets);
}
#####################################
sub
CommandInform($$)
{
my ($cl, $param) = @_;
return if(!$cl);
my $name = $cl->{NAME};
return "Usage: inform {on|timer|raw|off} [regexp]"
if($param !~ m/^(on|off|raw|timer|status)/);
if($param eq "status") {
my $i = $inform{$name};
return $i ? ($i->{type} . ($i->{regexp} ? " ".$i->{regexp} : "")) : "off";
}
delete($inform{$name});
if($param !~ m/^off/) {
my ($type, $regexp) = split(" ", $param);
$inform{$name}{NR} = $cl->{NR};
$inform{$name}{type} = $type;
if($regexp) {
eval { "Hallo" =~ m/$regexp/ };
return "Bad regexp: $@" if($@);
$inform{$name}{regexp} = $regexp;
}
Log 4, "Setting inform to $param";
}
return undef;
}
#####################################
sub
WakeUpFn($)

View File

@ -65,6 +65,7 @@ consStart()
if(consFilter == undefined)
consFilter = ".*";
oldFilter = consFilter;
withLog = ($("#eventWithLog").is(':checked') ? 1 : 0);
setTimeout(consFill, 1000);
$("#eventReset").click(function(evt){ // Event Monitor Reset

View File

@ -11,3 +11,5 @@ div.ui-widget-content a {color: #CCCCCC!important; text-decoration: none!importa
.ui-button-text { font-weight:normal!important; color:#555!important; }
div.detLink { display:inline-block; margin-right:0.5em; }
.fhemlog { color:#FFFFFF; }

View File

@ -21,6 +21,7 @@ table.room { border:1px solid gray; width: 100%; background: #D7FFFF; }
table.room tr.sel { background: #A0FFFF; }
tr.column > td { padding:0; vertical-align:top;}
.changed a, .changed { color:red; }
.fhemlog { color:#278727; }
.col2 { text-align:center; }
/* Documentation */