-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinfluxdb_wrapper_int.cpp
69 lines (54 loc) · 1.34 KB
/
influxdb_wrapper_int.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "influxdb_wrapper.hpp"
#include "influxdb_wrapper_int.h"
/* declared in magic_interface.h but defined here */
struct MHandler {
void *obj;
};
MHandler_t *create_influxdb(const char *uri)
{
InfluxDBWrapper *obj;
MHandler_t *h;
h = (typeof(h))malloc(sizeof(*h));
if (!h)
return NULL;
try {
obj = new InfluxDBWrapper(uri);
} catch(...) {
/* an exception occurred during wrapper creation */
free(h);
return NULL;
}
h->obj = obj;
return h;
}
void show_databases_influxdb(MHandler_t *h)
{
InfluxDBWrapper *obj;
obj = static_cast<InfluxDBWrapper *>(h->obj);
obj->showDatabases();
}
void destroy_influxdb(MHandler_t *h)
{
InfluxDBWrapper *obj;
obj = static_cast<InfluxDBWrapper *>(h->obj);
/* Delete the obj instance */
delete obj;
/* destroy the opaque handler */
free(h);
}
int write_temp_influxdb(MHandler_t *h, const char *city, double temp)
{
InfluxDBWrapper *obj;
obj = static_cast<InfluxDBWrapper *>(h->obj);
return obj->writeTemperature(city, temp);
}
int write_temp_influxdb_struct(MHandler_t *h, const struct data_point *dp)
{
/* we could have reused the write_temp_influxdb but we prefer to
* implement a new C++ function accepting the data structure
* @data_point.
*/
InfluxDBWrapper *obj;
obj = static_cast<InfluxDBWrapper *>(h->obj);
return obj->writeTemperatureDataPoint(dp);
}