Code

core: Introduced the concept of time-series.
[sysdb.git] / src / core / plugin.c
index 32966deabcf8042dbf58e120016419833a05dde0..85dd76f410dbccfdb27f6bbf9fff3c0ee4653f27 100644 (file)
 
 #include <pthread.h>
 
+/* helper to access info attributes */
+#define INFO_GET(i, attr) \
+       ((i)->attr ? (i)->attr : #attr" not set")
+
 /*
  * private data types
  */
 
-struct sdb_plugin_info {
-       char *plugin_name;
-       char *filename;
-
-       /* public attributes */
-       char *name;
-
-       char *description;
-       char *copyright;
-       char *license;
-
-       int   version;
-       int   plugin_version;
-};
-#define SDB_PLUGIN_INFO_INIT { \
-       /* plugin_name */ NULL, /* filename */ NULL, \
-       /* name */ NULL, /* desc */ NULL, \
-       /* copyright */ NULL, /* license */ NULL, \
-       /* version */ -1, /* plugin_version */ -1 }
-#define INFO_GET(i, attr) \
-       ((i)->attr ? (i)->attr : #attr" not set")
-
 typedef struct {
        sdb_object_t super;
        sdb_plugin_ctx_t public;
@@ -136,6 +118,7 @@ static sdb_llist_t      *collector_list = NULL;
 static sdb_llist_t      *cname_list = NULL;
 static sdb_llist_t      *shutdown_list = NULL;
 static sdb_llist_t      *log_list = NULL;
+static sdb_llist_t      *ts_fetcher_list = NULL;
 
 static struct {
        const char   *type;
@@ -165,8 +148,6 @@ plugin_info_clear(sdb_plugin_info_t *info)
        if (info->filename)
                free(info->filename);
 
-       if (info->name)
-               free(info->name);
        if (info->description)
                free(info->description);
        if (info->copyright)
@@ -525,9 +506,11 @@ module_load(const char *basedir, const char *name,
        sdb_llist_append(all_plugins, SDB_OBJ(ctx));
 
        sdb_log(SDB_LOG_INFO, "core: Successfully loaded "
-                       "plugin '%s' v%i (%s)\n\t%s\n\tLicense: %s",
-                       INFO_GET(&ctx->info, name), ctx->info.plugin_version,
-                       INFO_GET(&ctx->info, description),
+                       "plugin %s v%i (%s)", ctx->info.plugin_name,
+                       ctx->info.plugin_version,
+                       INFO_GET(&ctx->info, description));
+       sdb_log(SDB_LOG_INFO, "core: Plugin %s: %s, License: %s",
+                       ctx->info.plugin_name,
                        INFO_GET(&ctx->info, copyright),
                        INFO_GET(&ctx->info, license));
 
@@ -620,7 +603,7 @@ sdb_plugin_load(const char *basedir, const char *name,
                                return status;
 
                        sdb_log(SDB_LOG_INFO, "core: Successfully reloaded plugin "
-                                       "'%s' (%s)", INFO_GET(&ctx->info, name),
+                                       "'%s' (%s)", ctx->info.plugin_name,
                                        INFO_GET(&ctx->info, description));
                        ctx_set(old_ctx);
                }
@@ -642,16 +625,6 @@ sdb_plugin_set_info(sdb_plugin_info_t *info, int type, ...)
        va_start(ap, type);
 
        switch (type) {
-               case SDB_PLUGIN_INFO_NAME:
-                       {
-                               char *name = va_arg(ap, char *);
-                               if (name) {
-                                       if (info->name)
-                                               free(info->name);
-                                       info->name = strdup(name);
-                               }
-                       }
-                       break;
                case SDB_PLUGIN_INFO_DESC:
                        {
                                char *desc = va_arg(ap, char *);
@@ -779,12 +752,16 @@ sdb_plugin_register_collector(const char *name, sdb_plugin_collector_cb callback
        if (interval)
                SDB_PLUGIN_CCB(obj)->ccb_interval = *interval;
        else {
-               sdb_time_t tmp = sdb_plugin_get_ctx().interval;
+               ctx_t *ctx = ctx_get();
 
-               if (tmp > 0)
-                       SDB_PLUGIN_CCB(obj)->ccb_interval = tmp;
-               else
-                       SDB_PLUGIN_CCB(obj)->ccb_interval = 0;
+               if (! ctx) {
+                       sdb_log(SDB_LOG_ERR, "core: Cannot determine interval "
+                                       "for collector %s; none specified and no plugin "
+                                       "context found", cb_name);
+                       return -1;
+               }
+
+               SDB_PLUGIN_CCB(obj)->ccb_interval = ctx->public.interval;
        }
 
        if (! (SDB_PLUGIN_CCB(obj)->ccb_next_update = sdb_gettime())) {
@@ -810,6 +787,14 @@ sdb_plugin_register_collector(const char *name, sdb_plugin_collector_cb callback
        return 0;
 } /* sdb_plugin_register_collector */
 
+int
+sdb_plugin_register_ts_fetcher(const char *name,
+               sdb_plugin_fetch_ts_cb callback, sdb_object_t *user_data)
+{
+       return plugin_add_callback(&ts_fetcher_list, "time-series fetcher",
+                       name, callback, user_data);
+} /* sdb_plugin_register_ts_fetcher */
+
 sdb_plugin_ctx_t
 sdb_plugin_get_ctx(void)
 {
@@ -842,6 +827,16 @@ sdb_plugin_set_ctx(sdb_plugin_ctx_t ctx, sdb_plugin_ctx_t *old)
        return 0;
 } /* sdb_plugin_set_ctx */
 
+const sdb_plugin_info_t *
+sdb_plugin_current(void)
+{
+       ctx_t *ctx = ctx_get();
+
+       if (! ctx)
+               return NULL;
+       return &ctx->info;
+} /* sdb_plugin_current */
+
 int
 sdb_plugin_configure(const char *name, oconfig_item_t *ci)
 {