|
7 | 7 | // |
8 | 8 |
|
9 | 9 | #include "influx_c_rest_async.h" |
| 10 | +#include "influx_c_rest_config.h" |
| 11 | +#include "influx_c_rest_lines.h" |
10 | 12 |
|
11 | 13 | #include "../influxdb-cpp-rest/influxdb_simple_api.h" |
12 | 14 | #include "../influxdb-cpp-rest/influxdb_simple_async_api.h" |
13 | 15 | #include "../influxdb-cpp-rest/influxdb_line.h" |
| 16 | +#include "../influxdb-cpp-rest/influxdb_config.h" |
14 | 17 |
|
15 | 18 | #include <memory> |
16 | 19 | #include <cassert> |
@@ -52,6 +55,37 @@ extern "C" { |
52 | 55 | return res; |
53 | 56 | } |
54 | 57 |
|
| 58 | + extern "C" INFLUX_C_REST influx_c_rest_async_t *influx_c_rest_async_new_config(const char* url, const char* name, influx_c_rest_config_t * config) { |
| 59 | + assert(url); |
| 60 | + assert(name); |
| 61 | + assert(config); |
| 62 | + |
| 63 | + try { |
| 64 | + void* config_ptr = influx_c_rest_config_get_internal(config); |
| 65 | + influxdb::api::db_config* cpp_config = static_cast<influxdb::api::db_config*>(config_ptr); |
| 66 | + influx_c_rest_async_t *res = new influx_c_rest_async_t { |
| 67 | + std::make_unique<influxdb::async_api::simple_db>(url, name, *cpp_config) |
| 68 | + }; |
| 69 | + |
| 70 | + assert(res); |
| 71 | + return res; |
| 72 | + } catch (std::exception& e) { |
| 73 | + std::cerr << e.what() << std::endl; |
| 74 | + return nullptr; |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + extern "C" INFLUX_C_REST influx_c_rest_async_t *influx_c_rest_async_new_auth_config(const char* url, const char* name, const char* username, const char* password, influx_c_rest_config_t * config) { |
| 79 | + assert(username); |
| 80 | + assert(password); |
| 81 | + assert(config); |
| 82 | + auto res = influx_c_rest_async_new_config(url, name, config); |
| 83 | + if (res) { |
| 84 | + res->asyncdb->with_authentication(username, password); |
| 85 | + } |
| 86 | + return res; |
| 87 | + } |
| 88 | + |
55 | 89 | extern "C" INFLUX_C_REST int influx_c_rest_async_drop(influx_c_rest_async_t * self) { |
56 | 90 | assert(self); |
57 | 91 | assert(self->asyncdb.get()); |
@@ -93,4 +127,33 @@ extern "C" { |
93 | 127 | assert(line); |
94 | 128 | self->asyncdb->insert(influxdb::api::line(std::string(line), self->timestamp)); |
95 | 129 | } |
| 130 | + |
| 131 | + extern "C" INFLUX_C_REST void influx_c_rest_async_insert_lines(influx_c_rest_async_t * self, influx_c_rest_lines_t * lines) { |
| 132 | + assert(self); |
| 133 | + assert(self->asyncdb.get()); |
| 134 | + assert(lines); |
| 135 | + void* line_ptr = influx_c_rest_lines_get_internal(lines); |
| 136 | + influxdb::api::line* line_obj = static_cast<influxdb::api::line*>(line_ptr); |
| 137 | + self->asyncdb->insert(*line_obj); |
| 138 | + } |
| 139 | + |
| 140 | + extern "C" INFLUX_C_REST void influx_c_rest_async_insert_lines_default_timestamp(influx_c_rest_async_t * self, influx_c_rest_lines_t * lines) { |
| 141 | + assert(self); |
| 142 | + assert(self->asyncdb.get()); |
| 143 | + assert(lines); |
| 144 | + void* line_ptr = influx_c_rest_lines_get_internal(lines); |
| 145 | + influxdb::api::line* line_obj = static_cast<influxdb::api::line*>(line_ptr); |
| 146 | + influxdb::api::line line_with_timestamp(line_obj->get(), self->timestamp); |
| 147 | + self->asyncdb->insert(line_with_timestamp); |
| 148 | + } |
| 149 | + |
| 150 | + extern "C" INFLUX_C_REST void influx_c_rest_async_wait_quiet_ms(influx_c_rest_async_t * self, unsigned quiet_period_ms) { |
| 151 | + assert(self); |
| 152 | + assert(self->asyncdb.get()); |
| 153 | + try { |
| 154 | + self->asyncdb->wait_for_submission(std::chrono::milliseconds(quiet_period_ms)); |
| 155 | + } catch (std::exception& e) { |
| 156 | + std::cerr << e.what() << std::endl; |
| 157 | + } |
| 158 | + } |
96 | 159 | } |
0 commit comments