From: Florian Forster Date: Thu, 5 Feb 2009 19:21:20 +0000 (+0100) Subject: src/utils_db_query.[ch]: Allow a callback function to be passed to udb_query_create. X-Git-Tag: collectd-4.6.0~54^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=9b38f5f412d6b33cd0e5be812d830f09bef72647;p=collectd.git src/utils_db_query.[ch]: Allow a callback function to be passed to udb_query_create. This allows plugins to handle custom options in the blocks. --- diff --git a/src/dbi.c b/src/dbi.c index a542df32..d970938e 100644 --- a/src/dbi.c +++ b/src/dbi.c @@ -356,7 +356,8 @@ static int cdbi_config (oconfig_item_t *ci) /* {{{ */ { oconfig_item_t *child = ci->children + i; if (strcasecmp ("Query", child->key) == 0) - udb_query_create (&queries, &queries_num, child); + udb_query_create (&queries, &queries_num, child, + /* callback = */ NULL); else if (strcasecmp ("Database", child->key) == 0) cdbi_config_add_database (child); else diff --git a/src/oracle.c b/src/oracle.c index accaee35..b008e5c5 100644 --- a/src/oracle.c +++ b/src/oracle.c @@ -294,7 +294,8 @@ static int o_config (oconfig_item_t *ci) /* {{{ */ { oconfig_item_t *child = ci->children + i; if (strcasecmp ("Query", child->key) == 0) - udb_query_create (&queries, &queries_num, child); + udb_query_create (&queries, &queries_num, child, + /* callback = */ NULL); else if (strcasecmp ("Database", child->key) == 0) o_config_add_database (child); else diff --git a/src/utils_db_query.c b/src/utils_db_query.c index 868b53bf..3229d64e 100644 --- a/src/utils_db_query.c +++ b/src/utils_db_query.c @@ -540,7 +540,8 @@ void udb_query_free_one (udb_query_t *q) /* {{{ */ * Query public functions */ int udb_query_create (udb_query_t ***ret_query_list, /* {{{ */ - size_t *ret_query_list_len, oconfig_item_t *ci) + size_t *ret_query_list_len, oconfig_item_t *ci, + udb_query_create_callback_t cb) { udb_query_t **query_list; size_t query_list_len; @@ -607,6 +608,15 @@ int udb_query_create (udb_query_t ***ret_query_list, /* {{{ */ q->name); status = udb_config_set_uint (&q->max_version, child); } + else if (cb != NULL) + { + status = (*cb) (q, child); + if (status != 0) + { + WARNING ("db query utils: The configuration callback failed " + "to handle `%s'.", child->key); + } + } else { WARNING ("db query utils: Query `%s': Option `%s' not allowed here.", diff --git a/src/utils_db_query.h b/src/utils_db_query.h index 4e12cedd..3959e882 100644 --- a/src/utils_db_query.h +++ b/src/utils_db_query.h @@ -30,11 +30,15 @@ struct udb_query_s; typedef struct udb_query_s udb_query_t; +typedef int (*udb_query_create_callback_t) (udb_query_t *q, + oconfig_item_t *ci); + /* * Public functions */ int udb_query_create (udb_query_t ***ret_query_list, - size_t *ret_query_list_len, oconfig_item_t *ci); + size_t *ret_query_list_len, oconfig_item_t *ci, + udb_query_create_callback_t cb); void udb_query_free (udb_query_t **query_list, size_t query_list_len); int udb_query_pick_from_list (oconfig_item_t *ci,