summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 332cf19)
raw | patch | inline | side by side (parent: 332cf19)
author | Sebastian Harl <sh@tokkee.org> | |
Wed, 15 Oct 2008 07:28:15 +0000 (09:28 +0200) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Thu, 16 Oct 2008 07:57:28 +0000 (09:57 +0200) |
This type of callback is very similar to write callbacks:
int (*) (const data_set_t *, value_list_t *)
The return value of that callback indicates what further actions are to be
taken. It may be a bitwise OR of any of the following new flags:
FILTER_NOWRITE or FILTER_NOTHRESHOLD_CHECK. If both flags are used (which
equals the flag FILTER_IGNORE), the value list is ignored completely.
If more than one such callback is available, the respective return values are
bitwise OR'ed. If they "sum" up to FILTER_IGNORE, no further callbacks are
executed (lazy evaluation).
This type of callback may be used for the following purposes:
* rewrite information included in the value list (e.g. the instance
name)
* discard certain information on a fine-grained level based on the
information provided by the data set and value list
Signed-off-by: Sebastian Harl <sh@tokkee.org>
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
int (*) (const data_set_t *, value_list_t *)
The return value of that callback indicates what further actions are to be
taken. It may be a bitwise OR of any of the following new flags:
FILTER_NOWRITE or FILTER_NOTHRESHOLD_CHECK. If both flags are used (which
equals the flag FILTER_IGNORE), the value list is ignored completely.
If more than one such callback is available, the respective return values are
bitwise OR'ed. If they "sum" up to FILTER_IGNORE, no further callbacks are
executed (lazy evaluation).
This type of callback may be used for the following purposes:
* rewrite information included in the value list (e.g. the instance
name)
* discard certain information on a fine-grained level based on the
information provided by the data set and value list
Signed-off-by: Sebastian Harl <sh@tokkee.org>
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
src/plugin.c | patch | blob | history | |
src/plugin.h | patch | blob | history |
diff --git a/src/plugin.c b/src/plugin.c
index 0ae6e44a7f401cf293958d1f7951be684d26e339..4d503f7c457196493cdb1ce5c9e852d9f44cc8a5 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
static llist_t *list_init;
static llist_t *list_read;
static llist_t *list_write;
+static llist_t *list_filter;
static llist_t *list_flush;
static llist_t *list_shutdown;
static llist_t *list_log;
return (register_callback (&list_write, name, (void *) callback));
} /* int plugin_register_write */
+int plugin_register_filter (const char *name,
+ int (*callback) (const data_set_t *ds, value_list_t *vl))
+{
+ return (register_callback (&list_filter, name, (void *) callback));
+} /* int plugin_register_filter */
+
int plugin_register_flush (const char *name,
int (*callback) (const int timeout, const char *identifier))
{
return (plugin_unregister (list_write, name));
}
+int plugin_unregister_filter (const char *name)
+{
+ return (plugin_unregister (list_filter, name));
+}
+
int plugin_unregister_flush (const char *name)
{
return (plugin_unregister (list_flush, name));
{
static c_complain_t no_write_complaint = C_COMPLAIN_INIT_STATIC;
- int (*callback) (const data_set_t *, const value_list_t *);
data_set_t *ds;
llentry_t *le;
+ int filter = 0;
+
if ((vl == NULL) || (*vl->type == '\0')) {
ERROR ("plugin_dispatch_values: Invalid value list.");
return (-1);
escape_slashes (vl->type, sizeof (vl->type));
escape_slashes (vl->type_instance, sizeof (vl->type_instance));
+ le = llist_head (list_filter);
+ while (le != NULL)
+ {
+ int (*filter_callback) (const data_set_t *, value_list_t *) =
+ (int (*) (const data_set_t *, value_list_t *)) le->value;
+
+ filter |= (*filter_callback) (ds, vl);
+
+ if (filter == FILTER_IGNORE)
+ return (-1);
+
+ le = le->next;
+ }
+
/* Update the value cache */
uc_update (ds, vl);
- ut_check_threshold (ds, vl);
+
+ if ((filter & FILTER_NOTHRESHOLD_CHECK) == 0)
+ ut_check_threshold (ds, vl);
+
+ if (filter & FILTER_NOWRITE)
+ return (0);
le = llist_head (list_write);
while (le != NULL)
{
- callback = (int (*) (const data_set_t *, const value_list_t *)) le->value;
- (*callback) (ds, vl);
+ int (*write_callback) (const data_set_t *, const value_list_t *) =
+ (int (*) (const data_set_t *, const value_list_t *)) le->value;
+
+ (*write_callback) (ds, vl);
le = le->next;
}
diff --git a/src/plugin.h b/src/plugin.h
index 3ffde461b07da1baf684a2189bf0f6eba90e6214..b90811cf93cc5c98e99fc090e588a28bce18dc63 100644 (file)
--- a/src/plugin.h
+++ b/src/plugin.h
#define NOTIF_WARNING 2
#define NOTIF_OKAY 4
+#define FILTER_NOWRITE 1
+#define FILTER_NOTHRESHOLD_CHECK 2
+/* FILTER_IGNORE has to equal the bitwise or of all other filter flags */
+#define FILTER_IGNORE (FILTER_NOWRITE | FILTER_NOTHRESHOLD_CHECK)
+
/*
* Public data types
*/
int (*callback) (void));
int plugin_register_write (const char *name,
int (*callback) (const data_set_t *ds, const value_list_t *vl));
+int plugin_register_filter (const char *name,
+ int (*callback) (const data_set_t *ds, value_list_t *vl));
int plugin_register_flush (const char *name,
int (*callback) (const int timeout, const char *identifier));
int plugin_register_shutdown (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_filter (const char *name);
int plugin_unregister_flush (const char *name);
int plugin_unregister_shutdown (const char *name);
int plugin_unregister_data_set (const char *name);