From 62a466a8934bd3240aa202bdf28103617220619b Mon Sep 17 00:00:00 2001 From: Matt Ranostay Date: Mon, 24 Sep 2018 14:40:32 +0800 Subject: binding: bluetooth: return adapter/device versus bluez path To allow this binding API to be bluetooth stack agnostic remove pure bluez paths, and replace with generic fields. Bug-AGL: SPEC-1630 Change-Id: Iadba73782b6339df2ca5937e16a654e7ef3e477b Signed-off-by: Matt Ranostay --- binding/bluetooth-api.h | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'binding/bluetooth-api.h') diff --git a/binding/bluetooth-api.h b/binding/bluetooth-api.h index 50bf501..d8df0af 100644 --- a/binding/bluetooth-api.h +++ b/binding/bluetooth-api.h @@ -37,6 +37,18 @@ #define BLUEZ_OBJECT_PATH "/" #define BLUEZ_PATH "/org/bluez" +#define BLUEZ_ROOT_PATH(_t) \ + ({ \ + const char *__t = (_t); \ + size_t __len = strlen(BLUEZ_PATH) + 1 + \ + strlen(__t) + 1; \ + char *__tpath; \ + __tpath = alloca(__len + 1 + 1); \ + snprintf(__tpath, __len + 1, \ + BLUEZ_PATH "/%s", __t); \ + __tpath; \ + }) + #define FREEDESKTOP_INTROSPECT "org.freedesktop.DBus.Introspectable" #define FREEDESKTOP_PROPERTIES "org.freedesktop.DBus.Properties" #define FREEDESKTOP_OBJECTMANAGER "org.freedesktop.DBus.ObjectManager" @@ -52,7 +64,22 @@ struct bluetooth_state; -static inline const char *bluez_strip_path(const char *path) +static inline gchar *bluez_return_adapter(const char *path) +{ + gchar **strings = g_strsplit(path, "/", -1); + gchar *adapter; + + if (g_strv_length(strings) < 3) { + g_strfreev(strings); + return NULL; + } + adapter = g_strdup(strings[3]); + g_strfreev(strings); + + return adapter; +} + +static inline gchar *bluez_return_device(const char *path) { const char *basename; @@ -61,10 +88,9 @@ static inline const char *bluez_strip_path(const char *path) return NULL; basename++; /* at least one character */ - return *basename ? basename : NULL; + return *basename ? g_strdup(basename) : NULL; } - struct call_work *call_work_create_unlocked(struct bluetooth_state *ns, const char *access_type, const char *type_arg, const char *method, const char *bluez_method, -- cgit 1.2.3-korg