* there, good. If not, well, then there is nothing to flush.. -octo
*/
static int network_flush (int timeout,
- const char __attribute__((unused)) *identifier)
+ const char __attribute__((unused)) *identifier,
+ user_data_t __attribute__((unused)) *user_data)
{
pthread_mutex_lock (&send_buffer_lock);
plugin_register_config ("network", network_config,
config_keys, config_keys_num);
plugin_register_init ("network", network_init);
- plugin_register_flush ("network", network_flush);
+ plugin_register_flush ("network", network_flush,
+ /* user_data = */ NULL);
} /* void module_register */
return pplugin_call_all (aTHX_ PLUGIN_NOTIF, notif);
} /* static int perl_notify (const notification_t *) */
-static int perl_flush (int timeout, const char *identifier)
+static int perl_flush (int timeout, const char *identifier,
+ user_data_t __attribute__((unused)) *user_data)
{
dTHX;
plugin_register_read ("perl", perl_read);
plugin_register_write ("perl", perl_write, /* user_data = */ NULL);
- plugin_register_flush ("perl", perl_flush);
+ plugin_register_flush ("perl", perl_flush, /* user_data = */ NULL);
plugin_register_shutdown ("perl", perl_shutdown);
return 0;
} /* static int init_pi (const char **, const int) */
};
typedef struct write_func_s write_func_t;
+struct flush_func_s
+{
+ plugin_flush_cb callback;
+ user_data_t udata;
+};
+typedef struct flush_func_s flush_func_t;
+
/*
* Private variables
*/
int plugin_register_write (const char *name,
plugin_write_cb callback, user_data_t *user_data)
{
- write_func_t *wr;
+ write_func_t *wf;
- wr = (write_func_t *) malloc (sizeof (*wr));
- if (wr == NULL)
+ wf = (write_func_t *) malloc (sizeof (*wf));
+ if (wf == NULL)
{
ERROR ("plugin_register_write: malloc failed.");
return (-1);
}
- memset (wr, 0, sizeof (*wr));
+ memset (wf, 0, sizeof (*wf));
- wr->callback = callback;
+ wf->callback = callback;
if (user_data == NULL)
{
- wr->udata.data = NULL;
- wr->udata.free_func = NULL;
+ wf->udata.data = NULL;
+ wf->udata.free_func = NULL;
}
else
{
- wr->udata = *user_data;
+ wf->udata = *user_data;
}
- return (register_callback (&list_write, name, (void *) wr));
+ return (register_callback (&list_write, name, (void *) wf));
} /* int plugin_register_write */
int plugin_register_flush (const char *name,
- int (*callback) (const int timeout, const char *identifier))
+ plugin_flush_cb callback, user_data_t *user_data)
{
- return (register_callback (&list_flush, name, (void *) callback));
+ flush_func_t *ff;
+
+ ff = (flush_func_t *) malloc (sizeof (*ff));
+ if (ff == NULL)
+ {
+ ERROR ("plugin_register_flush: malloc failed.");
+ return (-1);
+ }
+ memset (ff, 0, sizeof (*ff));
+
+ ff->callback = callback;
+ if (user_data == NULL)
+ {
+ ff->udata.data = NULL;
+ ff->udata.free_func = NULL;
+ }
+ else
+ {
+ ff->udata = *user_data;
+ }
+
+ return (register_callback (&list_flush, name, (void *) ff));
} /* int plugin_register_flush */
int plugin_register_shutdown (char *name,
int plugin_unregister_flush (const char *name)
{
- return (plugin_unregister (list_flush, name));
+ llentry_t *e;
+ flush_func_t *ff;
+
+ e = llist_search (list_flush, name);
+
+ if (e == NULL)
+ return (-1);
+
+ llist_remove (list_flush, e);
+
+ ff = (flush_func_t *) e->value;
+ plugin_user_data_destroy (&ff->udata);
+ free (ff);
+ free (e->key);
+
+ llentry_destroy (e);
+
+ return (0);
}
int plugin_unregister_shutdown (const char *name)
int plugin_flush (const char *plugin, int timeout, const char *identifier)
{
- int (*callback) (int timeout, const char *identifier);
llentry_t *le;
if (list_flush == NULL)
le = llist_head (list_flush);
while (le != NULL)
{
+ flush_func_t *ff;
+
if ((plugin != NULL)
&& (strcmp (plugin, le->key) != 0))
{
continue;
}
- callback = (int (*) (int, const char *)) le->value;
- (*callback) (timeout, identifier);
+ ff = (flush_func_t *) le->value;
+
+ ff->callback (timeout, identifier, &ff->udata);
le = le->next;
}
typedef int (*plugin_read_cb) (user_data_t *);
typedef int (*plugin_write_cb) (const data_set_t *, const value_list_t *,
user_data_t *);
+typedef int (*plugin_flush_cb) (int timeout, const char *identifier,
+ user_data_t *);
/*
* NAME
int plugin_register_write (const char *name,
plugin_write_cb callback, user_data_t *user_data);
int plugin_register_flush (const char *name,
- int (*callback) (const int timeout, const char *identifier));
+ plugin_flush_cb callback, user_data_t *user_data);
int plugin_register_shutdown (char *name,
int (*callback) (void));
int plugin_register_data_set (const data_set_t *ds);
return (status);
} /* int rrd_write */
-static int rrd_flush (int timeout, const char *identifier)
+static int rrd_flush (int timeout, const char *identifier,
+ user_data_t __attribute__((unused)) *user_data)
{
pthread_mutex_lock (&cache_lock);
config_keys, config_keys_num);
plugin_register_init ("rrdtool", rrd_init);
plugin_register_write ("rrdtool", rrd_write, /* user_data = */ NULL);
- plugin_register_flush ("rrdtool", rrd_flush);
+ plugin_register_flush ("rrdtool", rrd_flush, /* user_data = */ NULL);
plugin_register_shutdown ("rrdtool", rrd_shutdown);
}