summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: fcb0810)
raw | patch | inline | side by side (parent: fcb0810)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Mon, 28 May 2007 19:43:31 +0000 (21:43 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sat, 2 Jun 2007 10:07:40 +0000 (12:07 +0200) |
src/configfile.c | patch | blob | history | |
src/configfile.h | patch | blob | history | |
src/plugin.c | patch | blob | history | |
src/plugin.h | patch | blob | history |
diff --git a/src/configfile.c b/src/configfile.c
index 4b6803ed68a398cbdff4881ad9e599b2ad9d3639..f4e9c604fe26cafd75ee04620158b11f5aed6726 100644 (file)
--- a/src/configfile.c
+++ b/src/configfile.c
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;
diff --git a/src/configfile.h b/src/configfile.h
index 0ee8f33cb19dfd1230846e5a5b05e0f930b52358..3952c180d9949f08bc42a94899d23a9c19a5db70 100644 (file)
--- a/src/configfile.h
+++ b/src/configfile.h
+#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
diff --git a/src/plugin.c b/src/plugin.c
index da662040cecedc916b5709fefdeae6b8ae6a5b49..6272581f7bc5ef476c4b424decd8753230bca38f 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
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));
diff --git a/src/plugin.h b/src/plugin.h
index 83c21094eee789112d9eca42fceb7b4dca2dbedc..72d8adb67953d944bab02d08d61901088247588f 100644 (file)
--- a/src/plugin.h
+++ b/src/plugin.h
#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