From: Florian Forster Date: Sat, 21 Feb 2009 17:35:45 +0000 (+0100) Subject: src/plugin.c: Change the write callbacks to receive a user_data_t pointer. X-Git-Tag: collectd-4.7.0~127^2~35 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=fc69836ae64498f00574090ada2e677435da9d77;p=collectd.git src/plugin.c: Change the write callbacks to receive a user_data_t pointer. There are by far not as many write callbacks, so I've just changed the callback in general rather than introducing a `complex write' callback. --- diff --git a/src/csv.c b/src/csv.c index 352557a8..d01f47de 100644 --- a/src/csv.c +++ b/src/csv.c @@ -249,7 +249,8 @@ static int csv_config (const char *key, const char *value) return (0); } /* int csv_config */ -static int csv_write (const data_set_t *ds, const value_list_t *vl) +static int csv_write (const data_set_t *ds, const value_list_t *vl, + user_data_t __attribute__((unused)) *user_data) { struct stat statbuf; char filename[512]; @@ -356,5 +357,5 @@ void module_register (void) { plugin_register_config ("csv", csv_config, config_keys, config_keys_num); - plugin_register_write ("csv", csv_write); + plugin_register_write ("csv", csv_write, /* user_data = */ NULL); } /* void module_register */ diff --git a/src/network.c b/src/network.c index 66f04380..3b2c25b1 100644 --- a/src/network.c +++ b/src/network.c @@ -1507,7 +1507,8 @@ static void flush_buffer (void) memset (&send_buffer_vl, 0, sizeof (send_buffer_vl)); } -static int network_write (const data_set_t *ds, const value_list_t *vl) +static int network_write (const data_set_t *ds, const value_list_t *vl, + user_data_t __attribute__((unused)) *user_data) { int status; @@ -1767,7 +1768,8 @@ static int network_init (void) /* setup socket(s) and so on */ if (sending_sockets != NULL) { - plugin_register_write ("network", network_write); + plugin_register_write ("network", network_write, + /* user_data = */ NULL); plugin_register_notification ("network", network_notification); } diff --git a/src/perl.c b/src/perl.c index 142e9c0e..9ef9cfc9 100644 --- a/src/perl.c +++ b/src/perl.c @@ -1907,7 +1907,8 @@ static int perl_read (void) return pplugin_call_all (aTHX_ PLUGIN_READ); } /* static int perl_read (void) */ -static int perl_write (const data_set_t *ds, const value_list_t *vl) +static int perl_write (const data_set_t *ds, const value_list_t *vl, + user_data_t __attribute__((unused)) *user_data) { dTHX; @@ -2221,7 +2222,7 @@ static int init_pi (int argc, char **argv) plugin_register_read ("perl", perl_read); - plugin_register_write ("perl", perl_write); + plugin_register_write ("perl", perl_write, /* user_data = */ NULL); plugin_register_flush ("perl", perl_flush); plugin_register_shutdown ("perl", perl_shutdown); return 0; diff --git a/src/plugin.c b/src/plugin.c index ee39bd3a..9bcea3cd 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -58,6 +58,13 @@ struct read_func_s }; typedef struct read_func_s read_func_t; +struct write_func_s +{ + plugin_write_cb callback; + user_data_t udata; +}; +typedef struct write_func_s write_func_t; + /* * Private variables */ @@ -636,7 +643,24 @@ int plugin_unregister_read (const char *name) int plugin_unregister_write (const char *name) { - return (plugin_unregister (list_write, name)); + llentry_t *e; + write_func_t *wf; + + e = llist_search (list_write, name); + + if (e == NULL) + return (-1); + + llist_remove (list_write, e); + + wf = (write_func_t *) e->value; + plugin_user_data_destroy (&wf->udata); + free (wf); + free (e->key); + + llentry_destroy (e); + + return (0); } int plugin_unregister_flush (const char *name) @@ -815,7 +839,6 @@ int plugin_read_all_once (void) int plugin_write (const char *plugin, /* {{{ */ const data_set_t *ds, const value_list_t *vl) { - int (*callback) (const data_set_t *ds, const value_list_t *vl); llentry_t *le; int status; @@ -843,8 +866,10 @@ int plugin_write (const char *plugin, /* {{{ */ le = llist_head (list_write); while (le != NULL) { - callback = le->value; - status = (*callback) (ds, vl); + write_func_t *wf = le->value; + + DEBUG ("plugin: plugin_write: Writing values via %s.", le->key); + status = wf->callback (ds, vl, &wf->udata); if (status != 0) failure++; else @@ -860,6 +885,7 @@ int plugin_write (const char *plugin, /* {{{ */ } else /* plugin != NULL */ { + write_func_t *wf; le = llist_head (list_write); while (le != NULL) { @@ -872,8 +898,10 @@ int plugin_write (const char *plugin, /* {{{ */ if (le == NULL) return (ENOENT); - callback = le->value; - status = (*callback) (ds, vl); + wf = le->value; + + DEBUG ("plugin: plugin_write: Writing values via %s.", le->key); + status = wf->callback (ds, vl, &wf->udata); } return (status); diff --git a/src/plugin.h b/src/plugin.h index 1eb9feca..e58444ff 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -147,6 +147,8 @@ typedef struct user_data_s user_data_t; * Callback types */ typedef int (*plugin_read_cb) (user_data_t *); +typedef int (*plugin_write_cb) (const data_set_t *, const value_list_t *, + user_data_t *); /* * NAME @@ -240,7 +242,7 @@ int plugin_register_read (const char *name, int plugin_register_complex_read (const char *name, plugin_read_cb callback, user_data_t *user_data); int plugin_register_write (const char *name, - int (*callback) (const data_set_t *ds, const value_list_t *vl)); + plugin_write_cb callback, user_data_t *user_data); int plugin_register_flush (const char *name, int (*callback) (const int timeout, const char *identifier)); int plugin_register_shutdown (char *name, diff --git a/src/rrdcached.c b/src/rrdcached.c index 31c63524..326a8898 100644 --- a/src/rrdcached.c +++ b/src/rrdcached.c @@ -314,7 +314,8 @@ static int rc_init (void) return (0); } /* int rc_init */ -static int rc_write (const data_set_t *ds, const value_list_t *vl) +static int rc_write (const data_set_t *ds, const value_list_t *vl, + user_data_t __attribute__((unused)) *user_data) { char filename[512]; char values[512]; @@ -405,7 +406,7 @@ void module_register (void) plugin_register_config ("rrdcached", rc_config, config_keys, config_keys_num); plugin_register_init ("rrdcached", rc_init); - plugin_register_write ("rrdcached", rc_write); + plugin_register_write ("rrdcached", rc_write, /* user_data = */ NULL); plugin_register_shutdown ("rrdcached", rc_shutdown); } /* void module_register */ diff --git a/src/rrdtool.c b/src/rrdtool.c index debb7bd4..698f89fd 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -746,7 +746,8 @@ static int rrd_compare_numeric (const void *a_ptr, const void *b_ptr) return (0); } /* int rrd_compare_numeric */ -static int rrd_write (const data_set_t *ds, const value_list_t *vl) +static int rrd_write (const data_set_t *ds, const value_list_t *vl, + user_data_t __attribute__((unused)) *user_data) { struct stat statbuf; char filename[512]; @@ -1046,7 +1047,7 @@ void module_register (void) plugin_register_config ("rrdtool", rrd_config, config_keys, config_keys_num); plugin_register_init ("rrdtool", rrd_init); - plugin_register_write ("rrdtool", rrd_write); + plugin_register_write ("rrdtool", rrd_write, /* user_data = */ NULL); plugin_register_flush ("rrdtool", rrd_flush); plugin_register_shutdown ("rrdtool", rrd_shutdown); }