X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=bindings%2Fperl%2FCollectd.pm;h=738206bbbd9f581173befdbab8a8b9413ee00375;hb=068ae14b916aa298995433da83302032c5e57c76;hp=bfc30805d3cb86204a8ef7a10bb43f2cf4ee6f64;hpb=910e3379457143781e814d64ea8251a61e6675ef;p=collectd.git diff --git a/bindings/perl/Collectd.pm b/bindings/perl/Collectd.pm index bfc30805..738206bb 100644 --- a/bindings/perl/Collectd.pm +++ b/bindings/perl/Collectd.pm @@ -56,6 +56,7 @@ our %EXPORT_TAGS = ( TYPE_LOG TYPE_NOTIF TYPE_FLUSH + TYPE_CONFIG TYPE_DATASET ) ], 'ds_types' => [ qw( @@ -98,6 +99,7 @@ our $interval_g; Exporter::export_ok_tags ('all'); my @plugins : shared = (); +my %cf_callbacks : shared = (); my %types = ( TYPE_INIT, "init", @@ -244,7 +246,8 @@ sub plugin_register { return; } - if ((! defined $plugins[$type]) && (TYPE_DATASET != $type)) { + if ((! defined $plugins[$type]) && (TYPE_DATASET != $type) + && (TYPE_CONFIG != $type)) { ERROR ("Collectd::plugin_register: Invalid type \"$type\""); return; } @@ -252,6 +255,16 @@ sub plugin_register { if ((TYPE_DATASET == $type) && ("ARRAY" eq ref $data)) { return plugin_register_data_set ($name, $data); } + elsif ((TYPE_CONFIG == $type) && (! ref $data)) { + my $pkg = scalar caller; + + if ($data !~ m/^$pkg\:\:/) { + $data = $pkg . "::" . $data; + } + + lock %cf_callbacks; + $cf_callbacks{$name} = $data; + } elsif ((TYPE_DATASET != $type) && (! ref $data)) { my $pkg = scalar caller; @@ -291,6 +304,10 @@ sub plugin_unregister { if (TYPE_DATASET == $type) { return plugin_unregister_data_set ($name); } + elsif (TYPE_CONFIG == $type) { + lock %cf_callbacks; + delete $cf_callbacks{$name}; + } elsif (defined $plugins[$type]) { lock %{$plugins[$type]}; delete $plugins[$type]->{$name}; @@ -378,6 +395,30 @@ sub plugin_flush_all { plugin_flush (timeout => $timeout); } +sub _plugin_dispatch_config { + my $plugin = shift; + my $config = shift; + + our $cb_name = undef; + + if (! (defined ($plugin) && defined ($config))) { + return; + } + + if (! defined $cf_callbacks{$plugin}) { + WARNING ("Found a configuration for the \"$plugin\" plugin, but " + . "the plugin isn't loaded or didn't register " + . "a configuration callback."); + return; + } + + { + lock %cf_callbacks; + $cb_name = $cf_callbacks{$plugin}; + } + call_by_name ($config); +} + 1; # vim: set sw=4 ts=4 tw=78 noexpandtab :