X-Git-Url: https://git.camperquake.de/gitweb.cgi?p=videosite.git;a=blobdiff_plain;f=libvideosite.pm;h=f9959bfc5602ac7072f7c49398ca4ef8cef928d7;hp=01fa7d9f2e15429311bdf7f0df02d7044a942b9f;hb=HEAD;hpb=2fa89b83b1a48165bf56feda84801715c19fd239 diff --git a/libvideosite.pm b/libvideosite.pm index 01fa7d9..f9959bf 100644 --- a/libvideosite.pm +++ b/libvideosite.pm @@ -34,6 +34,8 @@ my $getter; my %builtin_config = (); my $builtin_config_path; my $builtin_config_default; +my $config_cache = 1; +my %config_cache = (); our $error; # @@ -50,7 +52,12 @@ my $defaultconfig = { 'name' => 'direct', '_immutable' => '1', 'schemas' => {}, - } + }, + 'environment' => { + 'name' => 'environment', + '_immutable' => '1', + 'schemas' => {}, + }, }, 'config-version' => '2', }; @@ -71,6 +78,7 @@ my $remote_api = { module_path => sub { return dirname(realpath($0)) }, quote => sub { return $_ }, reload => sub {}, + wait_for_child => sub {}, }; # @@ -84,7 +92,7 @@ my $videosite_commands = { 'set' => sub { _cmd_set(@_); }, - + 'show' => sub { _cmd_show(@_); }, @@ -124,6 +132,10 @@ my $videosite_commands = { 'nodebug' => sub { _cmd_nodebug(@_); }, + + 'service' => sub { + _cmd_service(@_); + }, }; # @@ -153,7 +165,7 @@ sub _io { # @text = map { defined($_)?$remote_api->{quote}->($_):'(undef)' } @text; - $outputstack[0]->{ewpf}->(sprintf($format, @text)); + $outputstack[0]->{io}->(sprintf($format, @text)); } # @@ -265,6 +277,7 @@ sub _ploader { config_get => \&_config_get, config_set => \&_config_set, config_has => \&_config_has, + wait_for_child => $remote_api->{wait_for_child}, }); } else { _io('%s has wrong type (got %s, expected %s)', $p, $g->{'TYPE'}, $type); @@ -273,7 +286,7 @@ sub _ploader { } _debug("Loaded %d plugins", $#g+1); - + return @g; } @@ -301,36 +314,53 @@ sub _load_modules($) { # sub _config_get { my $path = shift; + my $dotpath = join('.', @{$path}); my $value; - $value = $remote_api->{config_get}->($path); - _debug("config: getting %s=%s", join('.', @{$path}), $value); + if ($config_cache && exists($config_cache{$dotpath}) && exists($config_cache{$dotpath}->{value})) { + $value = $config_cache{$dotpath}->{value}; + } else { + $value = $remote_api->{config_get}->($path); + $config_cache{$dotpath} = {value => $value, has => 1}; + + } + _debug("config: getting %s=%s", $dotpath, $value); return $value; } sub _config_set { my $path = shift; + my $dotpath = join('.', @{$path}); my $value = shift; - _debug("config: setting %s=%s", join('.', @{$path}), $value); + _debug("config: setting %s=%s", $dotpath, $value); + $config_cache{$dotpath} = {value => $value, has => 1}; return $remote_api->{config_set}->($path, $value); } sub _config_has { my $path = shift; + my $dotpath = join('.', @{$path}); my $b; - $b = $remote_api->{config_has}->($path); - _debug("config: testing %s (%s)", join('.', @{$path}), $b?'true':'false'); + if ($config_cache && exists($config_cache{$dotpath}) && exists($config_cache{$dotpath}->{has})) { + $b = $config_cache{$dotpath}->{has}; + } else { + $b = $remote_api->{config_has}->($path); + $config_cache{$dotpath}->{has} = $b; + } + _debug("config: testing %s (%s)", $dotpath, $b?'true':'false'); return $b; } sub _config_del { my $path = shift; + my $dotpath = join('.', @{$path}); - _debug("config: removing %s", join('.', @{$path})); + _debug("config: removing %s", $dotpath); + delete($config_cache{$dotpath}); $remote_api->{config_del}->($path); } @@ -362,7 +392,7 @@ sub _config_list_add { _config_set($path, join(',', @c)); } -# +# # Remove an item from the list # sub _config_list_del { @@ -907,6 +937,46 @@ sub _cmd_nodebug { } } +# +# Handle generic service commands +# +sub _cmd_service { + my $event = shift; + my $subcmd = shift || ''; + + $subcmd = lc($subcmd); + + if ($subcmd eq 'cache') { + _cmd_service_cache($event, @_); + } +} + + +# +# Display or clear the content of the config cache +# +sub _cmd_service_cache { + my $event = shift; + my $subcmd = shift; + + $subcmd = 'list' unless defined($subcmd); + $subcmd = lc($subcmd); + + if ($subcmd eq 'list') { + _io("Content of config cache:"); + foreach (sort(keys(%config_cache))) { + if (exists($config_cache{$_}->{value})) { + _io(" %s => %s", $_, $config_cache{$_}->{value}); + } else { + _io(" %s present", $_); + } + } + } elsif ($subcmd eq 'clear') { + %config_cache = (); + _io("Cache cleared"); + } +} + # # Return the list of loaded grabbers. @@ -1086,7 +1156,11 @@ sub register_api { $builtin_config_default = $a->{_config_default}->(); } - @outputstack = ({ewpf => $remote_api->{'io'}, window => ""}); + if (exists($a->{_config_cache})) { + $config_cache = $a->{_config_cache}->(); + } + + @outputstack = ({io => $remote_api->{'io'}, window => ""}); return 1; }