summaryrefslogtreecommitdiffstats
path: root/binding
diff options
context:
space:
mode:
authorMatt Ranostay <matt.ranostay@konsulko.com>2018-10-25 13:06:27 +0100
committerMatt Ranostay <matt.ranostay@konsulko.com>2018-11-23 08:49:14 -0800
commitc3556c79e883a463dc5f7f6f8d10f0743f195f2b (patch)
tree7ec18a0b998d57572b06710a2cd377ab2f5ab7eb /binding
parent581932bfa33050cc6791069c06711f4996ac1308 (diff)
binding: bluetooth: add return_bluez_path function
Concatenate adapter and device parameters to return a bluez path for usage within the binding's dbus calls. Bug-AGL: SPEC-1630 Change-Id: I4c96fa48baaf12b23aac98ba35f1ca82f7005bcb Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'binding')
-rw-r--r--binding/bluetooth-api.c55
-rw-r--r--binding/bluetooth-common.h2
-rw-r--r--binding/bluetooth-util.c18
3 files changed, 54 insertions, 21 deletions
diff --git a/binding/bluetooth-api.c b/binding/bluetooth-api.c
index 2ac25eb..e9c339f 100644
--- a/binding/bluetooth-api.c
+++ b/binding/bluetooth-api.c
@@ -707,11 +707,11 @@ static void bluetooth_connect_device(afb_req_t request)
{
struct bluetooth_state *ns = bluetooth_get_userdata(request);
GError *error = NULL;
- const char *device, *uuid;
+ const char *uuid;
struct call_work *cw;
+ gchar *device;
- /* first device */
- device = afb_req_value(request, "device");
+ device = return_bluez_path(request);
if (!device) {
afb_req_fail(request, "failed", "No path given");
return;
@@ -726,7 +726,7 @@ static void bluetooth_connect_device(afb_req_t request)
afb_req_fail_f(request, "failed", "can't queue work %s",
error->message);
g_error_free(error);
- return;
+ goto out_free;
}
cw->request = request;
@@ -746,8 +746,12 @@ static void bluetooth_connect_device(afb_req_t request)
error->message);
call_work_destroy(cw);
g_error_free(error);
- return;
+ /* fall-thru */
}
+
+out_free:
+ g_free(device);
+
}
static void bluetooth_disconnect_device(afb_req_t request)
@@ -756,10 +760,10 @@ static void bluetooth_disconnect_device(afb_req_t request)
json_object *jresp;
GVariant *reply = NULL;
GError *error = NULL;
- const char *device, *uuid;
+ const char *uuid;
+ gchar *device;
- /* first device */
- device = afb_req_value(request, "device");
+ device = return_bluez_path(request);
if (!device) {
afb_req_fail(request, "failed", "No device given to disconnect");
return;
@@ -777,6 +781,7 @@ static void bluetooth_disconnect_device(afb_req_t request)
if (!reply) {
afb_req_fail_f(request, "failed", "Disconnect error %s",
error ? error->message : "unspecified");
+ g_free(device);
g_error_free(error);
return;
}
@@ -786,6 +791,8 @@ static void bluetooth_disconnect_device(afb_req_t request)
jresp = json_object_new_object();
afb_req_success_f(request, jresp, "Device - Bluetooth %s disconnected",
device);
+
+ g_free(device);
}
static void pair_service_callback(void *user_data,
@@ -818,11 +825,10 @@ static void bluetooth_pair_device(afb_req_t request)
{
struct bluetooth_state *ns = bluetooth_get_userdata(request);
GError *error = NULL;
- const char *device;
+ gchar *device;
struct call_work *cw;
- /* first device */
- device = afb_req_value(request, "device");
+ device = return_bluez_path(request);
if (!device) {
afb_req_fail(request, "failed", "No path given");
return;
@@ -834,7 +840,7 @@ static void bluetooth_pair_device(afb_req_t request)
afb_req_fail_f(request, "failed", "can't queue work %s",
error->message);
g_error_free(error);
- return;
+ goto out_free;
}
cw->request = request;
@@ -848,8 +854,12 @@ static void bluetooth_pair_device(afb_req_t request)
error->message);
call_work_destroy(cw);
g_error_free(error);
- return;
+ goto out_free;
}
+
+out_free:
+ g_free(device);
+
}
static void bluetooth_cancel_pairing(afb_req_t request)
@@ -936,10 +946,10 @@ static void bluetooth_remove_device(afb_req_t request)
GError *error = NULL;
GVariant *reply;
json_object *jval = NULL;
- const char *device, *adapter;
+ const char *adapter;
+ gchar *device;
- /* first device */
- device = afb_req_value(request, "device");
+ device = return_bluez_path(request);
if (!device) {
afb_req_fail(request, "failed", "No path given");
return;
@@ -953,7 +963,7 @@ static void bluetooth_remove_device(afb_req_t request)
device, error->message);
g_error_free(error);
- return;
+ goto out_free;
}
adapter = json_object_get_string(jval);
@@ -966,15 +976,18 @@ static void bluetooth_remove_device(afb_req_t request)
" device %s method %s error %s",
device, "RemoveDevice", error->message);
g_error_free(error);
- json_object_put(jval);
- return;
+ goto out_free;
}
g_variant_unref(reply);
afb_req_success_f(request, json_object_new_object(),
"Bluetooth - device %s removed", adapter);
-
- json_object_put(jval);
+
+out_free:
+ if (!jval)
+ json_object_put(jval);
+ g_free(device);
+
}
static void bluetooth_version(afb_req_t request)
diff --git a/binding/bluetooth-common.h b/binding/bluetooth-common.h
index faa9558..bd64f83 100644
--- a/binding/bluetooth-common.h
+++ b/binding/bluetooth-common.h
@@ -112,6 +112,8 @@ json_object *simple_gvariant_to_json(GVariant *var, json_object *parent,
void json_process_path(json_object *jresp, const char *path);
+gchar *return_bluez_path(afb_req_t request);
+
/**
* Structure for converting from dbus properties to json
* and vice-versa.
diff --git a/binding/bluetooth-util.c b/binding/bluetooth-util.c
index e826aaf..3e0303f 100644
--- a/binding/bluetooth-util.c
+++ b/binding/bluetooth-util.c
@@ -1036,3 +1036,21 @@ void json_process_path(json_object *jresp, const char *path) {
json_object_object_add(jresp, "device", json_object_new_string(tmp));
g_free(tmp);
}
+
+gchar *return_bluez_path(afb_req_t request) {
+ const char *adapter, *device;
+
+ adapter = afb_req_value(request, "adapter");
+ if (!adapter) {
+ afb_req_fail(request, "failed", "No adapter parameter");
+ return NULL;
+ }
+
+ device = afb_req_value(request, "device");
+ if (!device) {
+ afb_req_fail(request, "failed", "No device parameter");
+ return NULL;
+ }
+
+ return g_strconcat("/org/bluez/", adapter, "/", device, NULL);
+}