Read time config from config file

This commit is contained in:
PolynomialDivision 2017-10-04 23:49:57 +02:00
parent de5fbef9d9
commit 54ce3b02c8
7 changed files with 85 additions and 11 deletions

View file

@ -13,6 +13,56 @@ dawn.metric.freq
*/
/*
config settings times
option update_client '50'
option remove_client '120'
option remove_probe '120'
*/
struct time_config_s uci_get_time_config()
{
struct time_config_s ret;
struct uci_context *c;
struct uci_ptr ptr;
c = uci_alloc_context ();
printf("Loading TImes!");
char tmp_update_client[] = "dawn.times.update_client";
if (uci_lookup_ptr (c, &ptr, tmp_update_client, 1) != UCI_OK) {
uci_perror(c, "uci_get_daw_metric Error");
return ret;
}
if(ptr.o->type == UCI_TYPE_STRING)
ret.update_client = atoi(ptr.o->v.string);
char tmp_remove_client[] = "dawn.times.remove_client";
if (uci_lookup_ptr (c, &ptr, tmp_remove_client, 1) != UCI_OK) {
uci_perror(c, "uci_get_daw_metric Error");
return ret;
}
if(ptr.o->type == UCI_TYPE_STRING)
ret.remove_client = atoi(ptr.o->v.string);
char tmp_remove_probe[] = "dawn.times.remove_probe";
if (uci_lookup_ptr (c, &ptr, tmp_remove_probe, 1) != UCI_OK) {
uci_perror(c, "uci_get_daw_metric Error");
return ret;
}
if(ptr.o->type == UCI_TYPE_STRING)
ret.remove_probe = atoi(ptr.o->v.string);
printf("Times: %lu, %lu, %lu\n", ret.update_client, ret.remove_client, ret.remove_probe);
uci_free_context(c);
return ret;
}
struct probe_metric_s uci_get_dawn_metric()
{
struct probe_metric_s ret;

View file

@ -515,11 +515,14 @@ static int ubus_get_clients() {
}
void *update_clients_thread(void *arg) {
time_t time_update_client = *(time_t*)arg;
printf("Update client thread with time: %lu\n", time_update_client);
const char *ubus_socket = NULL;
ctx_clients = ubus_connect(ubus_socket);
while (1) {
sleep(TIME_THRESHOLD_CLIENT_UPDATE);
sleep(time_update_client);
printf("[Thread] : Kicking clients!\n");
ubus_get_clients();
}