diff options
-rw-r--r-- | binding/bluetooth-api.c | 19 | ||||
-rw-r--r-- | binding/bluetooth-api.h | 2 | ||||
-rw-r--r-- | binding/bluetooth-util.c | 9 |
3 files changed, 10 insertions, 20 deletions
diff --git a/binding/bluetooth-api.c b/binding/bluetooth-api.c index e9c339f..58c326c 100644 --- a/binding/bluetooth-api.c +++ b/binding/bluetooth-api.c @@ -599,14 +599,9 @@ static void bluetooth_state(afb_req_t request) struct bluetooth_state *ns = bluetooth_get_userdata(request); GError *error = NULL; json_object *jresp; - const char *adapter; + const char *adapter = afb_req_value(request, "adapter"); - adapter = afb_req_value(request, "adapter"); - if (!adapter) { - afb_req_fail(request, "failed", "No adapter give to return state"); - return; - } - adapter = BLUEZ_ROOT_PATH(adapter); + adapter = BLUEZ_ROOT_PATH(adapter ? adapter : BLUEZ_DEFAULT_ADAPTER); jresp = adapter_properties(ns, &error, adapter); if (!jresp) { @@ -622,14 +617,10 @@ static void bluetooth_adapter(afb_req_t request) { struct bluetooth_state *ns = bluetooth_get_userdata(request); GError *error = NULL; - const char *adapter, *scan, *discoverable, *powered; + const char *adapter = afb_req_value(request, "adapter"); + const char *scan, *discoverable, *powered; - adapter = afb_req_value(request, "adapter"); - if (!adapter) { - afb_req_fail(request, "failed", "No adapter given to configure"); - return; - } - adapter = BLUEZ_ROOT_PATH(adapter); + adapter = BLUEZ_ROOT_PATH(adapter ? adapter : BLUEZ_DEFAULT_ADAPTER); scan = afb_req_value(request, "discovery"); if (scan) { diff --git a/binding/bluetooth-api.h b/binding/bluetooth-api.h index 8ab8135..31a1d76 100644 --- a/binding/bluetooth-api.h +++ b/binding/bluetooth-api.h @@ -65,6 +65,8 @@ #define BLUEZ_AT_AGENT "agent" #define BLUEZ_AT_AGENTMANAGER "agent-manager" +#define BLUEZ_DEFAULT_ADAPTER "hci0" + struct bluetooth_state; static inline gchar *bluez_return_adapter(const char *path) diff --git a/binding/bluetooth-util.c b/binding/bluetooth-util.c index 3e0303f..f57b43e 100644 --- a/binding/bluetooth-util.c +++ b/binding/bluetooth-util.c @@ -1038,13 +1038,10 @@ void json_process_path(json_object *jresp, const char *path) { } gchar *return_bluez_path(afb_req_t request) { - const char *adapter, *device; + const char *adapter = afb_req_value(request, "adapter"); + const char *device; - adapter = afb_req_value(request, "adapter"); - if (!adapter) { - afb_req_fail(request, "failed", "No adapter parameter"); - return NULL; - } + adapter = adapter ? adapter : BLUEZ_DEFAULT_ADAPTER; device = afb_req_value(request, "device"); if (!device) { |