struct cf_callback *next;
} cf_callback_t;
+typedef struct cf_complex_callback_s
+{
+ char *type;
+ int (*callback) (oconfig_item_t *);
+ struct cf_complex_callback_s *next;
+} cf_complex_callback_t;
+
typedef struct cf_value_map_s
{
char *key;
* Private variables
*/
static cf_callback_t *first_callback = NULL;
+static cf_complex_callback_t *complex_callback_head = NULL;
static cf_value_map_t cf_value_map[] =
{
int i;
char *name;
+ cf_complex_callback_t *cb;
+
if (strcasecmp (ci->key, "Plugin") != 0)
return (-1);
- if (ci->values_num != 1)
+ if (ci->values_num < 1)
return (-1);
if (ci->values[0].type != OCONFIG_TYPE_STRING)
return (-1);
name = ci->values[0].value.string;
+ /* Check for a complex callback first */
+ for (cb = complex_callback_head; cb != NULL; cb = cb->next)
+ if (strcasecmp (name, cb->type) == 0)
+ return (cb->callback (ci));
+
+ /* Hm, no complex plugin found. Dispatch the values one by one */
for (i = 0; i < ci->children_num; i++)
{
if (ci->children[i].children == NULL)
dispatch_value_plugin (name, ci->children + i);
else
- {DEBUG ("No nested config blocks allow for plugins. Yet.");}
+ {DEBUG ("No nested config blocks allow for this plugin.");}
}
return (0);
}
} /* void cf_unregister */
+void cf_unregister_complex (const char *type)
+{
+ cf_complex_callback_t *this, *prev;
+
+ for (prev = NULL, this = complex_callback_head;
+ this != NULL;
+ prev = this, this = this->next)
+ if (strcasecmp (this->type, type) == 0)
+ {
+ if (prev == NULL)
+ complex_callback_head = this->next;
+ else
+ prev->next = this->next;
+
+ sfree (this->type);
+ sfree (this);
+ break;
+ }
+} /* void cf_unregister */
+
void cf_register (const char *type,
int (*callback) (const char *, const char *),
const char **keys, int keys_num)
first_callback = cf_cb;
} /* void cf_register */
+int cf_register_complex (const char *type, int (*callback) (oconfig_item_t *))
+{
+ cf_complex_callback_t *new;
+
+ new = (cf_complex_callback_t *) malloc (sizeof (cf_complex_callback_t));
+ if (new == NULL)
+ return (-1);
+
+ new->type = strdup (type);
+ if (new->type == NULL)
+ {
+ sfree (new);
+ return (-1);
+ }
+
+ new->callback = callback;
+ new->next = NULL;
+
+ if (complex_callback_head == NULL)
+ {
+ complex_callback_head = new;
+ }
+ else
+ {
+ cf_complex_callback_t *last = complex_callback_head;
+ while (last->next != NULL)
+ last = last->next;
+ last->next = new;
+ }
+
+ return (0);
+} /* int cf_register_complex */
+
int cf_read (char *filename)
{
oconfig_item_t *conf;
+#ifndef CONFIGFILE_H
+#define CONFIGFILE_H
/**
* collectd - src/configfile.h
* Copyright (C) 2005,2006 Florian octo Forster
* Florian octo Forster <octo at verplant.org>
**/
-#ifndef CONFIGFILE_H
-#define CONFIGFILE_H
+#include "collectd.h"
+#include "liboconfig/oconfig.h"
/*
* DESCRIPTION
* `plugin_register'
*/
void cf_unregister (const char *type);
+void cf_unregister_complex (const char *type);
/*
* DESCRIPTION
int (*callback) (const char *, const char *),
const char **keys, int keys_num);
+int cf_register_complex (const char *type, int (*callback) (oconfig_item_t *));
+
/*
* DESCRIPTION
* `cf_read' reads the config file `filename' and dispatches the read
return (0);
} /* int plugin_register_config */
+int plugin_register_complex_config (const char *type,
+ int (*callback) (oconfig_item_t *))
+{
+ return (cf_register_complex (type, callback));
+} /* int plugin_register_complex_config */
+
int plugin_register_init (const char *name,
int (*callback) (void))
{
return (0);
} /* int plugin_unregister_config */
+int plugin_unregister_complex_config (const char *name)
+{
+ cf_unregister_complex (name);
+ return (0);
+} /* int plugin_unregister_complex_config */
+
int plugin_unregister_init (const char *name)
{
return (plugin_unregister (list_init, name));
#ifndef PLUGIN_H
#define PLUGIN_H
-
/**
* collectd - src/plugin.h
- * Copyright (C) 2005,2006 Florian octo Forster
+ * Copyright (C) 2005-2007 Florian octo Forster
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Florian octo Forster <octo at verplant.org>
**/
+#include "collectd.h"
+#include "configfile.h"
+
#define DATA_MAX_NAME_LEN 64
#define DS_TYPE_COUNTER 0
int plugin_register_config (const char *name,
int (*callback) (const char *key, const char *val),
const char **keys, int keys_num);
+int plugin_register_complex_config (const char *type,
+ int (*callback) (oconfig_item_t *));
int plugin_register_init (const char *name,
int (*callback) (void));
int plugin_register_read (const char *name,
void (*callback) (int, const char *));
int plugin_unregister_config (const char *name);
+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_write (const char *name);
int plugin_unregister_data_set (const char *name);
int plugin_unregister_log (const char *name);
+
/*
* NAME
* plugin_dispatch_values