[collectd] [RFC] Pass user-data to callback functions

Sebastian Harl sh at tokkee.org
Sun Apr 27 21:25:23 CEST 2008


Hi,

While I was implementing the flush-callback support in the "perl"
plugin, I stumbled across the following problem: If a Perl plugin
registers a flush-callback, there is no way to flush this plugin only,
because the flush callback registered by the "perl" plugin (which
forwards the call to all registered Perl callbacks) cannot know which
Perl plugin is supposed to be flushed.

This could be solved by introducing a user-pointer which is registered
along with the callback function. This user-pointer is then passed as an
additional parameter to the callback. A simple example could look like
this:

  int my_callback(..., void *user_data) {
    my_meta_data_t *data = (my_meta_data_t *)user_data;

    /* ... */
  }

  int my_shutdown(...) {
    my_meta_data_t *data;

    plugin_unregister_XXX("my_plugin", &data);
    free(data);
  }

  some_other_function(...) {
    my_meta_data_t *data = (my_meta_data_t *)malloc(sizeof(*data));

    /* initialize 'data' with whatever meta-data is required to
     * correctly execute the callback */

    plugin_register_XXX("my_plugin", my_callback, data);
  }

Right now, this would probably only be useful for the "perl" plugin.
However, I think this would be a powerful and generic solution to be
able to (dynamically!) register "different flavors" of the same
callback which, in the future, could be used in a variety of ways.

As this is a rather big change (each plugin would have to be modified),
I'd like to hear some comments about it before I implement it.

Cheers,
Sebastian

-- 
Sebastian "tokkee" Harl +++ GnuPG-ID: 0x8501C7FC +++ http://tokkee.org/

Those who would give up Essential Liberty to purchase a little Temporary
Safety, deserve neither Liberty nor Safety.         -- Benjamin Franklin

-------------- 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/20080427/0e5ad276/attachment.pgp 


More information about the collectd mailing list