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

changes for compilation, minor error handling, flags

parent e0094640
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include <limits.h> #include <limits.h>
#include <libubox/list.h> #include <libubox/list.h>
#include <libmobile.h> #include "libmobile.h"
#include <json-c/json.h> #include <json-c/json.h>
#include <string.h> #include <string.h>
#include <libubox/blobmsg.h> #include <libubox/blobmsg.h>
......
...@@ -5,6 +5,41 @@ ...@@ -5,6 +5,41 @@
struct ubus_context *ctx; struct ubus_context *ctx;
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;
}
void init_ubus(void) void init_ubus(void)
{ {
ctx = ubus_connect(NULL); ctx = ubus_connect(NULL);
...@@ -17,12 +52,30 @@ void init_ubus(void) ...@@ -17,12 +52,30 @@ void init_ubus(void)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int rv;
rv = parse_args(argc, argv);
if (rv < 0)
goto fail;
uloop_init(); uloop_init();
init_ubus(); init_ubus();
expose_apn_object(ctx);
expose_pin_object(ctx); rv = expose_apn_object(ctx);
expose_network_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;
uloop_run(); uloop_run();
return 0; return 0;
fail:
return -1;
} }
/**
* TODO:
* 1. Add more input options when creating APN profile
* 2. Add DEBUG printout
*/
#include "libmobile.h" #include "libmobile.h"
struct string { struct string {
......
...@@ -4,14 +4,16 @@ ...@@ -4,14 +4,16 @@
#include <json-c/json.h> #include <json-c/json.h>
#include <string.h> #include <string.h>
#define DEBUG 1 int debug;
//#define DEBUG 1 //how to define from some sort of config? there is no main?
#define debug_print(...) \ #define debug_print(...) \
do \ do \
{ \ { \
if (DEBUG) \ if (debug) \
fprintf(stderr, __VA_ARGS__); \ fprintf(stderr, __VA_ARGS__); \
} while (0) } while (0)
/*************************************************** /***************************************************
* Libmobile - A 4G Dongle library * Libmobile - A 4G Dongle library
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment