Newer
Older
Jakob Olsson
committed
#include "common.h"
#include "dongle_apn.h"
#include "dongle_pin.h"
#include "dongle_network.h"
struct ubus_context *ctx;
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
static struct option long_options[] =
{
{"debug", required_argument, NULL, 'd'}
};
int parse_args(int argc, char **argv)
{
while ((ch = getopt_long(argc, argv, ":d:", long_options, NULL)) != -1) {
int flag;
switch (ch) {
case 'd':
flag = atoi(ch);
if (flag > 1 || flag < 0) {
debug_print("%s: option '-%c' is invalid.\n", argv[0], optopt);
goto fail;
}
debug = flag;
break;
case ':':
debug_print(stderr, "%s: option '-%c' requires an argument\n", argv[0], optopt);
goto fail;
break;
case '?':
debug_print(stderr, "%s: option '-%c' is invalid: ignored\n", argv[0], optopt);
goto fail;
break;
}
}
return 0;
fail:
return -1;
}
Jakob Olsson
committed
void init_ubus(void)
{
ctx = ubus_connect(NULL);
if (!ctx) {
perror("ubus");
exit(1);
}
ubus_add_uloop(ctx);
}
int main(int argc, char **argv)
{
int rv;
rv = parse_args(argc, argv);
if (rv < 0)
goto fail;
Jakob Olsson
committed
uloop_init();
init_ubus();
rv = expose_apn_object(ctx);
if (rv < 0)
goto fail;
rv = expose_pin_object(ctx);
if (rv < 0)
goto fail;
rv = expose_network_object(ctx);
if (rv < 0)
goto fail;
Jakob Olsson
committed
uloop_run();
return 0;