summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 16baafe)
raw | patch | inline | side by side (parent: 16baafe)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sat, 21 Feb 2009 17:35:45 +0000 (18:35 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sat, 21 Feb 2009 17:35:45 +0000 (18:35 +0100) |
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.
callback in general rather than introducing a `complex write' callback.
src/csv.c | patch | blob | history | |
src/network.c | patch | blob | history | |
src/perl.c | patch | blob | history | |
src/plugin.c | patch | blob | history | |
src/plugin.h | patch | blob | history | |
src/rrdcached.c | patch | blob | history | |
src/rrdtool.c | patch | blob | history |
diff --git a/src/csv.c b/src/csv.c
index 352557a8046de0021681d3f6cf0b578f11a23f36..d01f47de605de0fc8a8da4650ee23c1683901836 100644 (file)
--- a/src/csv.c
+++ b/src/csv.c
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];
{
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 66f04380388fc3ad20d56d3f95333567e55bebfe..3b2c25b10aac86491be6605a622cdcf5323e3ab2 100644 (file)
--- a/src/network.c
+++ b/src/network.c
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;
/* 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 142e9c0eb34aaf4524d40f85ed5cc4d14d89222c..9ef9cfc9f39d16508168c1168111ec97f41be860 100644 (file)
--- a/src/perl.c
+++ b/src/perl.c
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;
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 ee39bd3a87001f491b4dc6a3cbca2aa0227c461c..9bcea3cd7e4a5d401085b7d52e3bd2c8dcf01e28 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
};
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
*/
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)
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;
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
}
else /* plugin != NULL */
{
+ write_func_t *wf;
le = llist_head (list_write);
while (le != NULL)
{
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 1eb9feca0731d27e76d985fc29a26903b1457645..e58444ff40fd39a2f65eda384ddeea5a97a9574a 100644 (file)
--- a/src/plugin.h
+++ b/src/plugin.h
* 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
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 31c6352411fc4481deb584f37e9f07c59bf321e2..326a8898622179c1ca741ba3d0f710f3a828d161 100644 (file)
--- a/src/rrdcached.c
+++ b/src/rrdcached.c
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];
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 debb7bd4ff4416386d5881ec814e1dbd63f7313a..698f89fdb50970a451dfa2b1c9def70cbbb1fcfa 100644 (file)
--- a/src/rrdtool.c
+++ b/src/rrdtool.c
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];
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);
}