summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e3a2581)
raw | patch | inline | side by side (parent: e3a2581)
author | Sebastian Harl <sh@tokkee.org> | |
Wed, 24 Mar 2010 22:31:59 +0000 (23:31 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Wed, 24 Mar 2010 22:31:59 +0000 (23:31 +0100) |
Using a new parameter added to plugin_register_complex_read(), it's now
possible to specify a group name for the registered callback. This name may
later be used to unregister *all* callbacks belonging to that group using the
newly added function plugin_unregister_read_group().
This might come in handy for plugins that register multiple read callbacks but
do not want to keep track of all of them in order to be able to unregister
them.
possible to specify a group name for the registered callback. This name may
later be used to unregister *all* callbacks belonging to that group using the
newly added function plugin_unregister_read_group().
This might come in handy for plugins that register multiple read callbacks but
do not want to keep track of all of them in order to be able to unregister
them.
12 files changed:
src/apache.c | patch | blob | history | |
src/curl_json.c | patch | blob | history | |
src/curl_xml.c | patch | blob | history | |
src/java.c | patch | blob | history | |
src/mysql.c | patch | blob | history | |
src/netapp.c | patch | blob | history | |
src/onewire.c | patch | blob | history | |
src/plugin.c | patch | blob | history | |
src/plugin.h | patch | blob | history | |
src/python.c | patch | blob | history | |
src/routeros.c | patch | blob | history | |
src/snmp.c | patch | blob | history |
diff --git a/src/apache.c b/src/apache.c
index 39849e6e05d6ebdc7699103957ecbaf2c351211b..3d6d957c5c2a721a3ce328fd19e27c2439e39a8c 100644 (file)
--- a/src/apache.c
+++ b/src/apache.c
(st->host != NULL) ? st->host : hostname_g,
(st->name != NULL) ? st->name : "default"),
- status = plugin_register_complex_read (callback_name,
+ status = plugin_register_complex_read (/* group = */ NULL,
+ /* name = */ callback_name,
/* callback = */ apache_read_host,
/* interval = */ NULL,
/* user_data = */ &ud);
diff --git a/src/curl_json.c b/src/curl_json.c
index 53e8abda1bfeeb4aafe8196c202215a6ce8fab71..03ef6a341a5d971c78956034ec0b388d44a0f3fc 100644 (file)
--- a/src/curl_json.c
+++ b/src/curl_json.c
ssnprintf (cb_name, sizeof (cb_name), "curl_json-%s-%s",
db->instance, db->url);
- plugin_register_complex_read (cb_name, cj_read,
+ plugin_register_complex_read (/* group = */ NULL, cb_name, cj_read,
/* interval = */ NULL, &ud);
}
else
diff --git a/src/curl_xml.c b/src/curl_xml.c
index 240be6628bc4a258b88d6d1308e746693c036e1b..c10955cb973a803902968781cdc73573d32f46b4 100644 (file)
--- a/src/curl_xml.c
+++ b/src/curl_xml.c
ssnprintf (cb_name, sizeof (cb_name), "curl_xml-%s-%s",
db->instance, db->url);
- plugin_register_complex_read (cb_name, cx_read,
+ plugin_register_complex_read (/* group = */ NULL, cb_name, cx_read,
/* interval = */ NULL, &ud);
}
else
diff --git a/src/java.c b/src/java.c
index 87b189fa1d6f647174dc3f813f80bdf4f4dc8886..528ec9c475656140b4572bf30361c1c082fbd46b 100644 (file)
--- a/src/java.c
+++ b/src/java.c
ud.data = (void *) cbi;
ud.free_func = cjni_callback_info_destroy;
- plugin_register_complex_read (cbi->name, cjni_read,
+ plugin_register_complex_read (/* group = */ NULL, cbi->name, cjni_read,
/* interval = */ NULL, &ud);
(*jvm_env)->DeleteLocalRef (jvm_env, o_read);
diff --git a/src/mysql.c b/src/mysql.c
index 30f5504a028d3a5bda49ceea927e82ee46c1dc84..c7b796b18d79d5c92dcc34cacba287c4a0db26ea 100644 (file)
--- a/src/mysql.c
+++ b/src/mysql.c
else
sstrncpy (cb_name, "mysql", sizeof (cb_name));
- plugin_register_complex_read (cb_name, mysql_read,
+ plugin_register_complex_read (/* group = */ NULL, cb_name,
+ mysql_read,
/* interval = */ NULL, &ud);
}
else
diff --git a/src/netapp.c b/src/netapp.c
index fc65358264f31856e7d14817be7d0c23ae8db529..317b0fe40d51936e924244a23321f7b7f4b29e68 100644 (file)
--- a/src/netapp.c
+++ b/src/netapp.c
ud.data = host;
ud.free_func = (void (*) (void *)) free_host_config;
- plugin_register_complex_read (cb_name,
+ plugin_register_complex_read (/* group = */ NULL, cb_name,
/* callback = */ cna_read,
/* interval = */ (host->interval > 0) ? &interval : NULL,
/* user data = */ &ud);
diff --git a/src/onewire.c b/src/onewire.c
index cae0d63d4c22f529aab642a3e3f6dd37e8195fb4..462458c73d626d097915501ce1c08221daa5245c 100644 (file)
--- a/src/onewire.c
+++ b/src/onewire.c
if (ow_interval > 0)
cb_interval.tv_sec = (time_t) ow_interval;
- plugin_register_complex_read ("onewire", cow_read,
+ plugin_register_complex_read (/* group = */ NULL, "onewire", cow_read,
&cb_interval, /* user data = */ NULL);
plugin_register_shutdown ("onewire", cow_shutdown);
diff --git a/src/plugin.c b/src/plugin.c
index 1eed532c1c510553d7026111d6489fccea30360a..a134446ba24d36a4b33f1f0f7e122641a2819fb3 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
#define rf_callback rf_super.cf_callback
#define rf_udata rf_super.cf_udata
callback_func_t rf_super;
+ char rf_group[DATA_MAX_NAME_LEN];
char rf_name[DATA_MAX_NAME_LEN];
int rf_type;
struct timespec rf_interval;
rf->rf_callback = (void *) callback;
rf->rf_udata.data = NULL;
rf->rf_udata.free_func = NULL;
+ rf->rf_group[0] = '\0';
sstrncpy (rf->rf_name, name, sizeof (rf->rf_name));
rf->rf_type = RF_SIMPLE;
rf->rf_interval.tv_sec = 0;
return (plugin_insert_read (rf));
} /* int plugin_register_read */
-int plugin_register_complex_read (const char *name,
+int plugin_register_complex_read (const char *group, const char *name,
plugin_read_cb callback,
const struct timespec *interval,
user_data_t *user_data)
memset (rf, 0, sizeof (read_func_t));
rf->rf_callback = (void *) callback;
+ if (group != NULL)
+ sstrncpy (rf->rf_group, group, sizeof (rf->rf_group));
+ else
+ rf->rf_group[0] = '\0';
sstrncpy (rf->rf_name, name, sizeof (rf->rf_name));
rf->rf_type = RF_COMPLEX;
if (interval != NULL)
return (0);
} /* }}} int plugin_unregister_read */
+static int compare_read_func_group (llentry_t *e, void *ud) /* {{{ */
+{
+ read_func_t *rf = e->value;
+ char *group = ud;
+
+ return strcmp (rf->rf_group, (const char *)group);
+} /* }}} int compare_read_func_group */
+
+int plugin_unregister_read_group (const char *group) /* {{{ */
+{
+ llentry_t *le;
+ read_func_t *rf;
+
+ int found = 0;
+
+ if (group == NULL)
+ return (-ENOENT);
+
+ pthread_mutex_lock (&read_lock);
+
+ if (read_list == NULL)
+ {
+ pthread_mutex_unlock (&read_lock);
+ return (-ENOENT);
+ }
+
+ while (42)
+ {
+ le = llist_search_custom (read_list,
+ compare_read_func_group, (void *)group);
+
+ if (le == NULL)
+ break;
+
+ ++found;
+
+ llist_remove (read_list, le);
+
+ rf = le->value;
+ assert (rf != NULL);
+ rf->rf_type = RF_REMOVE;
+
+ llentry_destroy (le);
+
+ DEBUG ("plugin_unregister_read_group: "
+ "Marked `%s' (group `%s') for removal.",
+ rf->rf_name, group);
+ }
+
+ pthread_mutex_unlock (&read_lock);
+
+ if (found == 0)
+ {
+ WARNING ("plugin_unregister_read_group: No such "
+ "group of read function: %s", group);
+ return (-ENOENT);
+ }
+
+ return (0);
+} /* }}} int plugin_unregister_read_group */
+
int plugin_unregister_write (const char *name)
{
return (plugin_unregister (list_write, name));
diff --git a/src/plugin.h b/src/plugin.h
index 868f44aba41d81f46fd384de7805ffa92f1a09fe..8b9449ee1dd64ec76436446bbbbaa9edd38a898b 100644 (file)
--- a/src/plugin.h
+++ b/src/plugin.h
plugin_init_cb callback);
int plugin_register_read (const char *name,
int (*callback) (void));
-int plugin_register_complex_read (const char *name,
+int plugin_register_complex_read (const char *group, const char *name,
plugin_read_cb callback,
const struct timespec *interval,
user_data_t *user_data);
int plugin_unregister_complex_config (const char *name);
int plugin_unregister_init (const char *name);
int plugin_unregister_read (const char *name);
+int plugin_unregister_read_group (const char *group);
int plugin_unregister_write (const char *name);
int plugin_unregister_flush (const char *name);
int plugin_unregister_shutdown (const char *name);
diff --git a/src/python.c b/src/python.c
index 5664b0c6390095072abcba72faf249e090a1b36d..2f4f01e1e08b7e00777a969136dd67dd93fff7b0 100644 (file)
--- a/src/python.c
+++ b/src/python.c
@@ -568,7 +568,8 @@ static PyObject *cpy_register_read(PyObject *self, PyObject *args, PyObject *kwd
user_data->data = c;
ts.tv_sec = interval;
ts.tv_nsec = (interval - ts.tv_sec) * 1000000000;
- plugin_register_complex_read(buf, cpy_read_callback, &ts, user_data);
+ plugin_register_complex_read(/* group = */ NULL, buf,
+ cpy_read_callback, &ts, user_data);
return cpy_string_to_unicode_or_bytes(buf);
}
diff --git a/src/routeros.c b/src/routeros.c
index 2512613cd19436f74b3550341366b268c8baa853..a020692e4b1b5a1a26dd906a42fc2050fac4c96d 100644 (file)
--- a/src/routeros.c
+++ b/src/routeros.c
user_data.data = router_data;
user_data.free_func = (void *) cr_free_data;
if (status == 0)
- status = plugin_register_complex_read (read_name, cr_read,
- /* interval = */ NULL, &user_data);
+ status = plugin_register_complex_read (/* group = */ NULL, read_name,
+ cr_read, /* interval = */ NULL, &user_data);
if (status != 0)
cr_free_data (router_data);
diff --git a/src/snmp.c b/src/snmp.c
index 00df3779bb52907c001de892b5ffae6ce9c5a442..2470761143ed7dc0ecbb33de17998e478f64d8db 100644 (file)
--- a/src/snmp.c
+++ b/src/snmp.c
if (hd->interval != 0)
cb_interval.tv_sec = (time_t) hd->interval;
- status = plugin_register_complex_read (cb_name, csnmp_read_host,
- /* interval = */ &cb_interval, /* user_data = */ &cb_data);
+ status = plugin_register_complex_read (/* group = */ NULL, cb_name,
+ csnmp_read_host, /* interval = */ &cb_interval,
+ /* user_data = */ &cb_data);
if (status != 0)
{
ERROR ("snmp plugin: Registering complex read function failed.");