diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2019-03-29 15:56:10 +0100 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2019-04-01 11:44:53 +0200 |
commit | f6e6432ed03ff76868efe57396036d3124881069 (patch) | |
tree | f69013eeb924ce7350de2ceab9b6ae03b1e4f80e /src/plugins/influxdb-reader.c | |
parent | fb1f28adcf1cf90606ac31425e9370edfa9e70c2 (diff) |
Git submodule migration to separated libraries
- Replace controller binder functions definition with the binder ones.
and remove the last used submodules to use the separated libraries.
Bug-AGL: SPEC-2139
Change-Id: I0e354757dec692c13b49f02226fcf891953667f5
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src/plugins/influxdb-reader.c')
-rw-r--r-- | src/plugins/influxdb-reader.c | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/src/plugins/influxdb-reader.c b/src/plugins/influxdb-reader.c index 7b184dd..d7ddac7 100644 --- a/src/plugins/influxdb-reader.c +++ b/src/plugins/influxdb-reader.c @@ -29,7 +29,7 @@ struct metrics_list { struct series_t serie; json_object *metricsJ; - AFB_ApiT api; + afb_api_t api; }; static void fill_n_send_values(void *c, json_object *valuesJ) @@ -45,7 +45,7 @@ static void fill_n_send_values(void *c, json_object *valuesJ) else { if(set_value(m_list->serie.serie_columns.tags, valuesJ, i)) { if(set_value(m_list->serie.serie_columns.fields, valuesJ, j)) { - AFB_ApiError(m_list->api, "No tags nor fields fits."); + AFB_API_ERROR(m_list->api, "No tags nor fields fits."); } j++; } @@ -86,7 +86,7 @@ static void unpack_metric_from_db(void *ml, json_object *metricJ) "name", &m_list->serie.name, "columns", &columnsJ, "values", &valuesJ)) { - AFB_ApiError(m_list->api, "Unpacking metric goes wrong"); + AFB_API_ERROR(m_list->api, "Unpacking metric goes wrong"); return; } @@ -94,7 +94,7 @@ static void unpack_metric_from_db(void *ml, json_object *metricJ) wrap_json_array_for_all(valuesJ, fill_n_send_values, m_list); } -static json_object *unpack_series(AFB_ApiT apiHandle, json_object *seriesJ) +static json_object *unpack_series(afb_api_t apiHandle, json_object *seriesJ) { struct metrics_list m_list = { .serie = { @@ -114,7 +114,7 @@ static json_object *unpack_series(AFB_ApiT apiHandle, json_object *seriesJ) return m_list.metricsJ; } -static void forward_to_garner(AFB_ApiT apiHandle, const char *result, size_t size) +static void forward_to_garner(afb_api_t apiHandle, const char *result, size_t size) { int id = 0; json_object *resultsJ = NULL, @@ -135,13 +135,13 @@ static void forward_to_garner(AFB_ApiT apiHandle, const char *result, size_t siz if(seriesJ) { metrics2send = unpack_series(apiHandle, seriesJ); if(json_object_array_length(metrics2send)) { - if(AFB_ServiceSync(apiHandle, "garner", "write", metrics2send, &call_resultJ)) { - AFB_ApiError(apiHandle, "Metrics were sent but not done, an error happens. Details: %s", json_object_to_json_string(call_resultJ)); + if(afb_api_call_sync_legacy(apiHandle, "garner", "write", metrics2send, &call_resultJ)) { + AFB_API_ERROR(apiHandle, "Metrics were sent but not done, an error happens. Details: %s", json_object_to_json_string(call_resultJ)); } } } else { - AFB_ApiError(apiHandle, "Empty response. Request results was:\n%s", result); + AFB_API_ERROR(apiHandle, "Empty response. Request results was:\n%s", result); } } @@ -149,26 +149,26 @@ static void influxdb_read_curl_cb(void *closure, int status, CURL *curl, const c { if(!closure) return; - AFB_ApiT apiHandle = (AFB_ApiT)closure; + afb_api_t apiHandle = (afb_api_t)closure; long rep_code = curl_wrap_response_code_get(curl); switch(rep_code) { case 200: - AFB_ApiDebug(apiHandle, "Read correctly done"); + AFB_API_DEBUG(apiHandle, "Read correctly done"); forward_to_garner(apiHandle, result, size); break; case 400: - AFB_ApiError(apiHandle, "Unacceptable request. %s", result); + AFB_API_ERROR(apiHandle, "Unacceptable request. %s", result); break; case 401: - AFB_ApiError(apiHandle, "Invalid authentication. %s", result); + AFB_API_ERROR(apiHandle, "Invalid authentication. %s", result); break; default: - AFB_ApiError(apiHandle, "Unexptected behavior. %s", result); + AFB_API_ERROR(apiHandle, "Unexptected behavior. %s", result); break; } } -static CURL *make_curl_query_get(AFB_ApiT apiHandle, const char *url) +static CURL *make_curl_query_get(afb_api_t apiHandle, const char *url) { CURL *curl; char *args[5]; @@ -184,7 +184,7 @@ static CURL *make_curl_query_get(AFB_ApiT apiHandle, const char *url) args[4] = NULL; length_now = asprintf(&now, "%lu", get_ts()); - int rootdir_fd = AFB_RootDirGetFD(apiHandle); + int rootdir_fd = afb_api_rootdir_get_fd(apiHandle); int fd_last_read = openat(rootdir_fd, "last_db_read", O_CREAT | O_RDWR, S_IRWXU); if (fd_last_read < 0) return NULL; @@ -193,7 +193,7 @@ static CURL *make_curl_query_get(AFB_ApiT apiHandle, const char *url) else write the last timestamp */ if(read(fd_last_read, last_ts, sizeof(last_ts)) == 0) { if(write(fd_last_read, now, length_now) != length_now) - AFB_ApiError(apiHandle, "Error writing last_db_read file: %s\n", strerror( errno )); + AFB_API_ERROR(apiHandle, "Error writing last_db_read file: %s\n", strerror( errno )); } else { strcat(query, " WHERE time >= "); @@ -201,7 +201,7 @@ static CURL *make_curl_query_get(AFB_ApiT apiHandle, const char *url) close(fd_last_read); fd_last_read = openat(rootdir_fd, "last_db_read", O_TRUNC | O_RDWR); if (write(fd_last_read, now, length_now) != length_now) - AFB_ApiError(apiHandle, "Error writing last_db_read file: %s", strerror( errno )); + AFB_API_ERROR(apiHandle, "Error writing last_db_read file: %s", strerror( errno )); } args[3] = query; @@ -245,8 +245,8 @@ CTLP_CAPI(read_from_influxdb, source, argsJ, eventJ) struct sd_event_source *evtSource = NULL; /* Set a cyclic cb call each 1s to call the read callback */ - sd_event_now(AFB_GetEventLoop(source->api), CLOCK_MONOTONIC, &usec); - err = sd_event_add_time(AFB_GetEventLoop(source->api), &evtSource, CLOCK_MONOTONIC, usec+1000000, 250, influxdb_read, (void*)source); + sd_event_now(afb_api_get_event_loop(source->api), CLOCK_MONOTONIC, &usec); + err = sd_event_add_time(afb_api_get_event_loop(source->api), &evtSource, CLOCK_MONOTONIC, usec+1000000, 250, influxdb_read, (void*)source); if(!err) err = sd_event_source_set_enabled(evtSource, SD_EVENT_ON); |