[collectd] [PATCH 4/5] perl plugin: bootstrap Collectd when initializing Perl interpreter
Sebastian Harl
sh at tokkee.org
Mon Oct 1 00:10:21 CEST 2007
This automatically makes all symbols available at (Perl) compile time,
thus making the API built into collectd.
Signed-off-by: Sebastian Harl <sh at tokkee.org>
---
bindings/perl/Collectd.pm | 3 -
src/perl.c | 93 ++++++++++++++++++---------------------------
2 files changed, 37 insertions(+), 59 deletions(-)
diff --git a/bindings/perl/Collectd.pm b/bindings/perl/Collectd.pm
index d5d9833..fd5632a 100644
--- a/bindings/perl/Collectd.pm
+++ b/bindings/perl/Collectd.pm
@@ -24,9 +24,6 @@ use warnings;
require Exporter;
-# make all symbols available at compile time
-BEGIN { our $VERSION = '4.1.2'; bootstrap Collectd $VERSION; }
-
our @ISA = qw( Exporter );
our %EXPORT_TAGS = (
diff --git a/src/perl.c b/src/perl.c
index 626b287..c85d288 100644
--- a/src/perl.c
+++ b/src/perl.c
@@ -111,6 +111,27 @@ static struct {
{ "", NULL }
};
+struct {
+ char name[64];
+ int value;
+} constants[] =
+{
+ { "Collectd::TYPE_INIT", PLUGIN_INIT },
+ { "Collectd::TYPE_READ", PLUGIN_READ },
+ { "Collectd::TYPE_WRITE", PLUGIN_WRITE },
+ { "Collectd::TYPE_SHUTDOWN", PLUGIN_SHUTDOWN },
+ { "Collectd::TYPE_LOG", PLUGIN_LOG },
+ { "Collectd::TYPE_DATASET", PLUGIN_DATASET },
+ { "Collectd::DS_TYPE_COUNTER", DS_TYPE_COUNTER },
+ { "Collectd::DS_TYPE_GAUGE", DS_TYPE_GAUGE },
+ { "Collectd::LOG_ERR", LOG_ERR },
+ { "Collectd::LOG_WARNING", LOG_WARNING },
+ { "Collectd::LOG_NOTICE", LOG_NOTICE },
+ { "Collectd::LOG_INFO", LOG_INFO },
+ { "Collectd::LOG_DEBUG", LOG_DEBUG },
+ { "", 0 }
+};
+
/*
* Helper functions for data type conversion.
@@ -731,58 +752,6 @@ static XS (Collectd_plugin_log)
XSRETURN_YES;
} /* static XS (Collectd_plugin_log) */
-/*
- * Collectd::bootstrap ().
- */
-static XS (boot_Collectd)
-{
- HV *stash = NULL;
- char *file = __FILE__;
-
- struct {
- char name[64];
- SV *value;
- } consts[] =
- {
- { "Collectd::TYPE_INIT", Perl_newSViv (perl, PLUGIN_INIT) },
- { "Collectd::TYPE_READ", Perl_newSViv (perl, PLUGIN_READ) },
- { "Collectd::TYPE_WRITE", Perl_newSViv (perl, PLUGIN_WRITE) },
- { "Collectd::TYPE_SHUTDOWN", Perl_newSViv (perl, PLUGIN_SHUTDOWN) },
- { "Collectd::TYPE_LOG", Perl_newSViv (perl, PLUGIN_LOG) },
- { "Collectd::TYPE_DATASET", Perl_newSViv (perl, PLUGIN_DATASET) },
- { "Collectd::DS_TYPE_COUNTER", Perl_newSViv (perl, DS_TYPE_COUNTER) },
- { "Collectd::DS_TYPE_GAUGE", Perl_newSViv (perl, DS_TYPE_GAUGE) },
- { "Collectd::LOG_ERR", Perl_newSViv (perl, LOG_ERR) },
- { "Collectd::LOG_WARNING", Perl_newSViv (perl, LOG_WARNING) },
- { "Collectd::LOG_NOTICE", Perl_newSViv (perl, LOG_NOTICE) },
- { "Collectd::LOG_INFO", Perl_newSViv (perl, LOG_INFO) },
- { "Collectd::LOG_DEBUG", Perl_newSViv (perl, LOG_DEBUG) },
- { "", NULL }
- };
-
- int i = 0;
-
- dXSARGS;
-
- if ((1 > items) || (2 < items)) {
- log_err ("Usage: Collectd::bootstrap(name[, version])");
- XSRETURN_EMPTY;
- }
-
- XS_VERSION_BOOTCHECK;
-
- /* register API */
- for (i = 0; NULL != api[i].f; ++i)
- Perl_newXS (perl, api[i].name, api[i].f, file);
-
- stash = Perl_gv_stashpv (perl, "Collectd", 1);
-
- /* export "constants" */
- for (i = 0; NULL != consts[i].value; ++i)
- Perl_newCONSTSUB (perl, stash, consts[i].name, consts[i].value);
- XSRETURN_YES;
-} /* static XS (boot_Collectd) */
-
/*
* Interface to collectd.
@@ -867,17 +836,29 @@ static int perl_shutdown (void)
return ret;
} /* static void perl_shutdown (void) */
+/* bootstrap the Collectd module */
static void xs_init (pTHX)
{
- char *file = __FILE__;
+ HV *stash = NULL;
+ char *file = __FILE__;
- dXSUB_SYS;
+ int i = 0;
- /* build the Collectd module into the perl interpreter */
- Perl_newXS (perl, "Collectd::bootstrap", boot_Collectd, file);
+ dXSUB_SYS;
/* enable usage of Perl modules using shared libraries */
Perl_newXS (perl, "DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
+
+ /* register API */
+ for (i = 0; NULL != api[i].f; ++i)
+ Perl_newXS (perl, api[i].name, api[i].f, file);
+
+ stash = Perl_gv_stashpv (perl, "Collectd", 1);
+
+ /* export "constants" */
+ for (i = 0; '\0' != constants[i].name[0]; ++i)
+ Perl_newCONSTSUB (perl, stash, constants[i].name,
+ Perl_newSViv (perl, constants[i].value));
return;
} /* static void xs_init (pTHX) */
--
1.5.2.1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20071001/dc779b1e/attachment.pgp
More information about the collectd
mailing list