Skip to content
Snippets Groups Projects
Commit a26e78e0 authored by Jakob Olsson's avatar Jakob Olsson
Browse files

adds get_devices to uloop on boot and every 5s, slight structure change

parent 06d53737
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@
#include <time.h>
#include <limits.h>
#include <libubox/list.h>
#include <libubox/uloop.h>
#include "libmobile.h"
#include <json-c/json.h>
......
......@@ -8,12 +8,19 @@
struct ubus_context *ctx;
int debug;
struct uloop_timeout timeout = { .cb = get_devices };
static struct option long_options[] = {
{"debug", required_argument, NULL, 'd'},
{0, 0, 0, 0}
};
void uloop_add_get_devices(struct uloop_timeout *t)
{
uloop_timeout_set(t, 5000);
uloop_timeout_add(t);
}
int parse_args(int argc, char **argv)
{
char ch;
......@@ -62,6 +69,8 @@ int main(int argc, char **argv)
uloop_init();
init_ubus();
uloop_timeout_set(&timeout, 0);
uloop_timeout_add(&timeout);
/*
rv = expose_apn_object(ctx);
if (rv < 0)
......
#ifndef DONGLE_H
#define DONGLE_H
void uloop_add_get_devices(struct uloop_timeout *t);
#endif
\ No newline at end of file
......@@ -11,11 +11,15 @@
#include <limits.h>
#include "dongle_infrastructure.h"
#include "dongle.h"
struct device {
struct list_head list;
char *name;
char *ip;
struct ubus_object *obj;
struct ubus_methods *methods;
};
LIST_HEAD(devices);
......@@ -48,7 +52,7 @@ char *lexer(char **input, char *delimiter)
return substr;
}
int *get_devices(void)
int get_devices(struct uloop_timeout *t)
{
char device_path[PATH_MAX];
struct dirent *de;
......@@ -92,6 +96,8 @@ int *get_devices(void)
goto fail;
}
node->name = strdup(de->d_name);
node->ip = get_device_ip(node->name);
printf("added %s\n", node->name);
if (list_empty(&devices)) {
INIT_LIST_HEAD(&devices);
......@@ -176,7 +182,9 @@ fail:
}
void print_list(struct ubus_context *ctx, struct ubus_request_data *req)
int print_list(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
struct blob_attr *msg)
{
struct device *net_dev;
struct blob_buf bb;
......@@ -195,6 +203,7 @@ void print_list(struct ubus_context *ctx, struct ubus_request_data *req)
blobmsg_close_array(&bb, arr);
ubus_send_reply(ctx, req, bb.head);
blob_buf_free(&bb);
return 0;
}
int get_device_ips(struct ubus_context *ctx, struct ubus_object *obj,
......@@ -208,12 +217,13 @@ int get_device_ips(struct ubus_context *ctx, struct ubus_object *obj,
memset(&bb, 0, sizeof(struct blob_buf));
blob_buf_init(&bb, 0);
rv = get_devices();
/*rv = get_devices();
if (rv < 0)
goto fail;
*/
arr = blobmsg_open_array(&bb, "network_devices");
list_for_each_entry(net_dev, &devices, list) {
net_dev->ip = get_device_ip(net_dev->name);
//net_dev->ip = get_device_ip(net_dev->name);
table = blobmsg_open_table(&bb, "");
blobmsg_add_string(&bb, "device_name", net_dev->name);
if (net_dev->ip)
......@@ -238,7 +248,7 @@ fail:
struct ubus_method infrastructure_object_methods[] = {
UBUS_METHOD_NOARG("list", get_device_ips)
UBUS_METHOD_NOARG("list", print_list)
};
struct ubus_object_type infrastructure_object_type = UBUS_OBJECT_TYPE("dongle", infrastructure_object_methods);
......
......@@ -3,4 +3,6 @@
#include "common.h"
int expose_infrastructure_object(struct ubus_context *ctx);
int get_devices(struct uloop_timeout *t);
char *get_device_ip(char *device_name);
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment