diff --git a/src/core/plugin.c b/src/core/plugin.c
index 7404b036392ecd5c76899009dd7f515ff9d87d8e..f581eb1629fbe3f043c02e13f6a4f3799de9b6d4 100644 (file)
--- a/src/core/plugin.c
+++ b/src/core/plugin.c
#define SDB_CONST_PLUGIN_CCB(obj) ((const sdb_plugin_collector_cb_t *)(obj))
typedef struct {
#define SDB_CONST_PLUGIN_CCB(obj) ((const sdb_plugin_collector_cb_t *)(obj))
typedef struct {
- sdb_object_t super;
+ sdb_plugin_cb_t super; /* cb_callback will always be NULL */
+#define w_user_data super.cb_user_data
+#define w_ctx super.cb_ctx
sdb_store_writer_t impl;
sdb_store_writer_t impl;
- sdb_object_t *user_data;
- ctx_t *ctx;
} sdb_plugin_writer_t;
#define SDB_PLUGIN_WRITER(obj) ((sdb_plugin_writer_t *)(obj))
} sdb_plugin_writer_t;
#define SDB_PLUGIN_WRITER(obj) ((sdb_plugin_writer_t *)(obj))
/* else: other callbacks still reference it */
} /* plugin_unregister_by_name */
/* else: other callbacks still reference it */
} /* plugin_unregister_by_name */
-static void
-plugin_unregister_all(void)
-{
- size_t i;
-
- for (i = 0; i < SDB_STATIC_ARRAY_LEN(all_lists); ++i) {
- const char *type = all_lists[i].type;
- sdb_llist_t *list = *all_lists[i].list;
-
- size_t len = sdb_llist_len(list);
-
- if (! len)
- continue;
-
- sdb_llist_clear(list);
- sdb_log(SDB_LOG_INFO, "core: Unregistered %zu %s callback%s",
- len, type, len == 1 ? "" : "s");
- }
-} /* plugin_unregister_all */
-
/*
* private types
*/
/*
* private types
*/
/* ctx may be NULL if the plugin was not registered by a plugin */
SDB_PLUGIN_WRITER(obj)->impl = *impl;
/* ctx may be NULL if the plugin was not registered by a plugin */
SDB_PLUGIN_WRITER(obj)->impl = *impl;
- SDB_PLUGIN_WRITER(obj)->ctx = ctx_get();
- sdb_object_ref(SDB_OBJ(SDB_PLUGIN_WRITER(obj)->ctx));
+ SDB_PLUGIN_WRITER(obj)->w_ctx = ctx_get();
+ sdb_object_ref(SDB_OBJ(SDB_PLUGIN_WRITER(obj)->w_ctx));
sdb_object_ref(ud);
sdb_object_ref(ud);
- SDB_PLUGIN_WRITER(obj)->user_data = ud;
+ SDB_PLUGIN_WRITER(obj)->w_user_data = ud;
return 0;
} /* plugin_writer_init */
return 0;
} /* plugin_writer_init */
plugin_writer_destroy(sdb_object_t *obj)
{
assert(obj);
plugin_writer_destroy(sdb_object_t *obj)
{
assert(obj);
- sdb_object_deref(SDB_PLUGIN_WRITER(obj)->user_data);
- sdb_object_deref(SDB_OBJ(SDB_PLUGIN_WRITER(obj)->ctx));
+ sdb_object_deref(SDB_PLUGIN_WRITER(obj)->w_user_data);
+ sdb_object_deref(SDB_OBJ(SDB_PLUGIN_WRITER(obj)->w_ctx));
} /* plugin_writer_destroy */
static sdb_type_t sdb_plugin_writer_type = {
} /* plugin_writer_destroy */
static sdb_type_t sdb_plugin_writer_type = {
"config callback from outside a plugin");
return -1;
}
"config callback from outside a plugin");
return -1;
}
- return plugin_add_callback(&config_list, "init", ctx->info.plugin_name,
+ return plugin_add_callback(&config_list, "config", ctx->info.plugin_name,
(void *)callback, NULL);
} /* sdb_plugin_register_config */
(void *)callback, NULL);
} /* sdb_plugin_register_config */
return 0;
} /* sdb_store_register_writer */
return 0;
} /* sdb_store_register_writer */
+void
+sdb_plugin_unregister_all(void)
+{
+ size_t i;
+
+ for (i = 0; i < SDB_STATIC_ARRAY_LEN(all_lists); ++i) {
+ const char *type = all_lists[i].type;
+ sdb_llist_t *list = *all_lists[i].list;
+
+ size_t len = sdb_llist_len(list);
+
+ if (! len)
+ continue;
+
+ sdb_llist_clear(list);
+ sdb_log(SDB_LOG_INFO, "core: Unregistered %zu %s callback%s",
+ len, type, len == 1 ? "" : "s");
+ }
+} /* sdb_plugin_unregister_all */
+
sdb_plugin_ctx_t
sdb_plugin_get_ctx(void)
{
sdb_plugin_ctx_t
sdb_plugin_get_ctx(void)
{
CTX(sdb_llist_iter_get_next(iter))->use_cnt = 0;
sdb_llist_iter_destroy(iter);
CTX(sdb_llist_iter_get_next(iter))->use_cnt = 0;
sdb_llist_iter_destroy(iter);
- plugin_unregister_all();
+ sdb_plugin_unregister_all();
return 0;
} /* sdb_plugin_reconfigure_init */
return 0;
} /* sdb_plugin_reconfigure_init */
sdb_plugin_writer_t *writer;
writer = SDB_PLUGIN_WRITER(sdb_llist_iter_get_next(iter));
assert(writer);
sdb_plugin_writer_t *writer;
writer = SDB_PLUGIN_WRITER(sdb_llist_iter_get_next(iter));
assert(writer);
- if (writer->impl.store_host(name, last_update, writer->user_data))
+ if (writer->impl.store_host(name, last_update, writer->w_user_data))
status = -1;
}
sdb_llist_iter_destroy(iter);
status = -1;
}
sdb_llist_iter_destroy(iter);
writer = SDB_PLUGIN_WRITER(sdb_llist_iter_get_next(iter));
assert(writer);
if (writer->impl.store_service(hostname, name, last_update,
writer = SDB_PLUGIN_WRITER(sdb_llist_iter_get_next(iter));
assert(writer);
if (writer->impl.store_service(hostname, name, last_update,
- writer->user_data))
+ writer->w_user_data))
status = -1;
}
sdb_llist_iter_destroy(iter);
status = -1;
}
sdb_llist_iter_destroy(iter);
if ((! hostname) || (! name))
return -1;
if ((! hostname) || (! name))
return -1;
- if ((! store->type) || (! store->id))
+ if (store && ((! store->type) || (! store->id)))
store = NULL;
iter = sdb_llist_get_iter(writer_list);
store = NULL;
iter = sdb_llist_get_iter(writer_list);
writer = SDB_PLUGIN_WRITER(sdb_llist_iter_get_next(iter));
assert(writer);
if (writer->impl.store_metric(hostname, name, store, last_update,
writer = SDB_PLUGIN_WRITER(sdb_llist_iter_get_next(iter));
assert(writer);
if (writer->impl.store_metric(hostname, name, store, last_update,
- writer->user_data))
+ writer->w_user_data))
status = -1;
}
sdb_llist_iter_destroy(iter);
status = -1;
}
sdb_llist_iter_destroy(iter);
writer = SDB_PLUGIN_WRITER(sdb_llist_iter_get_next(iter));
assert(writer);
if (writer->impl.store_attribute(hostname, key, value, last_update,
writer = SDB_PLUGIN_WRITER(sdb_llist_iter_get_next(iter));
assert(writer);
if (writer->impl.store_attribute(hostname, key, value, last_update,
- writer->user_data))
+ writer->w_user_data))
status = -1;
}
sdb_llist_iter_destroy(iter);
status = -1;
}
sdb_llist_iter_destroy(iter);
writer = SDB_PLUGIN_WRITER(sdb_llist_iter_get_next(iter));
assert(writer);
if (writer->impl.store_service_attr(hostname, service,
writer = SDB_PLUGIN_WRITER(sdb_llist_iter_get_next(iter));
assert(writer);
if (writer->impl.store_service_attr(hostname, service,
- key, value, last_update, writer->user_data))
+ key, value, last_update, writer->w_user_data))
status = -1;
}
sdb_llist_iter_destroy(iter);
status = -1;
}
sdb_llist_iter_destroy(iter);
writer = SDB_PLUGIN_WRITER(sdb_llist_iter_get_next(iter));
assert(writer);
if (writer->impl.store_metric_attr(hostname, metric,
writer = SDB_PLUGIN_WRITER(sdb_llist_iter_get_next(iter));
assert(writer);
if (writer->impl.store_metric_attr(hostname, metric,
- key, value, last_update, writer->user_data))
+ key, value, last_update, writer->w_user_data))
status = -1;
}
sdb_llist_iter_destroy(iter);
status = -1;
}
sdb_llist_iter_destroy(iter);