From 2c8f2dd2c27c20cc03d9b7e3b4a3b8b60cadebe5 Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Mon, 19 Mar 2007 15:34:34 +0000 Subject: [PATCH] Rename added, rereadcfg bugfix git-svn-id: https://svn.fhem.de/fhem/trunk@31 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 6 ++-- fhem/FHEM/00_FHZ.pm | 4 +-- fhem/HISTORY | 15 ++++----- fhem/fhem.pl | 77 +++++++++++++++++++++++++++++++++++---------- 4 files changed, 73 insertions(+), 29 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index dcee17da4..f2524b017 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -294,7 +294,7 @@ - bugfix: empty FHT battery is not reported (by Holger) - feature: new FHT codes, e.g. month/day/hour/minute setting (by Holger) -- ==DATE== (3.4) +- ==DATE== (4.0) - bugfix: deny at +{3}... (only +*{3} allowed), reported by Bernd, 25.01 - bugfix: allow numbers greater then 9 in at +{} - feature: new 50_WS300.pm from Martin (bugfix + rain statistics, 26.01) @@ -315,6 +315,6 @@ - list/xmllist format changed - disable attribute for at/notify/filelog See HISTORY for details and reasoning - - TODO: bugfix: more thorough serial line initialization + - added rename command -- RENAME + - TODO: bugfix: more thorough serial line initialization diff --git a/fhem/FHEM/00_FHZ.pm b/fhem/FHEM/00_FHZ.pm index 615dbb446..1ca4908ff 100755 --- a/fhem/FHEM/00_FHZ.pm +++ b/fhem/FHEM/00_FHZ.pm @@ -236,7 +236,7 @@ FHZ_Undef($$) my ($hash, $arg) = @_; my $name = $hash->{NAME}; - foreach my $d (keys %defs) { + foreach my $d (sort keys %defs) { if(defined($defs{$d}) && defined($defs{$d}{IODev}) && $defs{$d}{IODev} == $hash) @@ -245,7 +245,7 @@ FHZ_Undef($$) delete $defs{$d}{IODev}; } } - $hash->{PortObj}->close(); + $hash->{PortObj}->close() if($hash->{PortObj}); return undef; } diff --git a/fhem/HISTORY b/fhem/HISTORY index 5e98b6d36..b64744389 100644 --- a/fhem/HISTORY +++ b/fhem/HISTORY @@ -15,7 +15,13 @@ - Added doc/linux.html (multiple USDB devices, udev links) - Linked fhem.html and commandref.html to linux.html -- rudi, Sun Mar 4 11:18:10 MET 2007 +- Martin Haas, Fri Feb 23 10:18 MET 2007 + - ARM-Section (NSLU2) added to doc/linux.html + +- Pest, Sat Feb 24 18:30 MET 2007 + - doc/linux.html: Module build re-written. + +- Rudi, Sun Mar 4 11:18:10 MET 2007 Reorganization. Goal: making attribute adding/deleting more uniform ("at/notify" and other device differences), and making web-configuration possible (i.e. saving the configfile, list of possible devices etc). @@ -48,9 +54,4 @@ - "define/set/get/attr name ?" returns a list of possible arguments in the same format. This data is contained in the xmllist. - disable attribute for at/notify/filelog - -- Martin Haas, Fri Feb 23 10:18 MET 2007 - - ARM-Section (NSLU2) added to doc/linux.html - -- Pest, Sat Feb 24 18:30 MET 2007 - - doc/linux.html: Module build re-written. + - rename added diff --git a/fhem/fhem.pl b/fhem/fhem.pl index 6990c9225..726687ebb 100755 --- a/fhem/fhem.pl +++ b/fhem/fhem.pl @@ -60,6 +60,7 @@ sub TimeNow(); sub WriteStatefile(); sub XmlEscape($); sub fhem($); +sub doGlobalDef($); sub CommandAttr($$); sub CommandDefAttr($$); @@ -72,6 +73,7 @@ sub CommandInclude($$); sub CommandInform($$); sub CommandList($$); sub CommandRereadCfg($$); +sub CommandRename($$); sub CommandQuit($$); sub CommandSave($$); sub CommandSet($$); @@ -129,6 +131,7 @@ my %defattr; # Default attributes my %intAt; # Internal at timer hash. my $intAtCnt=0; my $init_done = 0; +my $reread_active = 0; my $AttrList = "room"; @@ -136,15 +139,7 @@ $modules{Internal}{ORDER} = -1; $modules{Internal}{AttrList} = "configfile logfile modpath " . "pidfilename port statefile userattr verbose:1,2,3,4,5 version"; -$defs{global}{NR} = $devcount++; -$defs{global}{TYPE} = "Internal"; -$defs{global}{STATE} = "Internal"; -$defs{global}{DEF} = ""; - -CommandAttr(undef, "global verbose 3"); -CommandAttr(undef, "global configfile $ARGV[0]"); -CommandAttr(undef, "global logfile -"); -CommandAttr(undef, "global version =VERS= from =DATE="); +doGlobalDef($ARGV[0]); my %cmds = ( "?" => { Fn=>"CommandHelp", @@ -173,6 +168,8 @@ my %cmds = ( Hlp=>",end the client session" }, "reload" => { Fn=>"CommandReload", Hlp=>",reload the given module (e.g. 99_PRIV)" }, + "rename" => { Fn=>"CommandRename", + Hlp=>" ,rename a definition" }, "rereadcfg" => { Fn=>"CommandRereadCfg", Hlp=>",reread the config file" }, "save" => { Fn=>"CommandSave", @@ -604,14 +601,20 @@ CommandRereadCfg($$) return $ret if($ret); } + my $cfgfile = $attr{global}{configfile}; %defs = (); %attr = (); + doGlobalDef($cfgfile); - my $ret; - $ret = CommandInclude($cl, $attr{global}{configfile}); - return $ret if($ret); - $ret = CommandInclude($cl, $attr{global}{statefile}) - if($attr{global}{statefile} && -r $attr{global}{statefile}); + + $reread_active=1; + + my $ret = CommandInclude($cl, $cfgfile); + if(!$ret && $attr{global}{statefile} && -r $attr{global}{statefile}) { + $ret = CommandInclude($cl, $attr{global}{statefile}); + } + + $reread_active=0; return $ret; } @@ -916,6 +919,7 @@ CommandDelete($$) { my ($cl, $def) = @_; + return "Please define $def first" if(!defined($defs{$def})); my $ret = CallFn($def, "UndefFn", $defs{$def}, $def); return $ret if($ret); @@ -1107,6 +1111,26 @@ CommandReload($$) return undef; } +##################################### +sub +CommandRename($$) +{ + my ($cl, $param) = @_; + my ($old, $new) = split(" ", $param); + + return "Please define $old first" if(!defined($defs{$old})); + return "Invalid characters in name (not A-Za-z0-9.:-): $new" + if($new !~ m/^[a-z0-9.:_-]*$/i); + return "Cannot rename global" if($old eq "global"); + + $defs{$new} = $defs{$old}; + delete($defs{$old}); + + $attr{$new} = $attr{$old}; + delete($attr{$old}); + + return undef; +} ##################################### sub @@ -1163,6 +1187,8 @@ CommandAttr($$) ################ elsif($a[1] eq "port") { + + return undef if($reread_active); my ($port, $global) = split(" ", $a[2]); if($global && $global ne "global") { return "Bad syntax, usage: attr global port [global]"; @@ -1174,9 +1200,10 @@ CommandAttr($$) LocalPort => $port, Listen => 10, ReuseAddr => 1); - if($ret) { - return $ret if($init_done); - die "Can't open server port at $port\n"; + if(!$server2) { + Log 1, "Can't open server port at $port: $!\n"; + return "$!" if($init_done); + die "Can't open server port at $port: $!\n"; } close($server) if($server); $server = $server2; @@ -1550,3 +1577,19 @@ fhem($) return AnalyzeCommandChain($global_cl, $param); } +sub +doGlobalDef($) +{ + my ($arg) = @_; + + $devcount = 0; + $defs{global}{NR} = $devcount++; + $defs{global}{TYPE} = "Internal"; + $defs{global}{STATE} = "Internal"; + $defs{global}{DEF} = ""; + + CommandAttr(undef, "global verbose 3"); + CommandAttr(undef, "global configfile $arg"); + CommandAttr(undef, "global logfile -"); + CommandAttr(undef, "global version =VERS= from =DATE="); +}