diff options
author | Matt Ranostay <matt.ranostay@konsulko.com> | 2018-11-07 19:08:06 -0800 |
---|---|---|
committer | Matt Ranostay <matt.ranostay@konsulko.com> | 2018-11-23 08:49:14 -0800 |
commit | 2702c40734efa883bfd1f0cbc4f08a8fe12f1a2a (patch) | |
tree | 2790b47f04569c2bd0de11d8fc93b32bc52f3372 /binding/bluetooth-api.h | |
parent | f4e8cddddc0675821de04bacdb36b0bb33daaceb (diff) |
binding: bluetooth: add MediaPlayer1 interface media events
Report back MediaPlayer1 interface events for A2DP media playback
Bug-AGL: SPEC-1630
Change-Id: I777f19af2de247fe676d5bede4bacbbad8ca9844
Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'binding/bluetooth-api.h')
-rw-r--r-- | binding/bluetooth-api.h | 68 |
1 files changed, 50 insertions, 18 deletions
diff --git a/binding/bluetooth-api.h b/binding/bluetooth-api.h index 0d72afc..cd6a775 100644 --- a/binding/bluetooth-api.h +++ b/binding/bluetooth-api.h @@ -68,39 +68,56 @@ #define BLUEZ_AT_MEDIAPLAYER "mediaplayer" #define BLUEZ_DEFAULT_ADAPTER "hci0" +#define BLUEZ_DEFAULT_PLAYER "player0" struct bluetooth_state; -static inline gchar *bluez_return_adapter(const char *path) + +static inline int split_length(const char *path) { + gchar **strings = g_strsplit(path, "/", -1); + int ret = g_strv_length(strings) ; + + g_strfreev(strings); + return ret; +} + +static inline gchar *find_index(const char *path, int idx) { gchar **strings = g_strsplit(path, "/", -1); - gchar *adapter; + gchar *item = NULL; + + if (g_strv_length(strings) > idx) + item = g_strdup(strings[idx]); - if (g_strv_length(strings) < 3) { - g_strfreev(strings); - return NULL; - } - adapter = g_strdup(strings[3]); g_strfreev(strings); + return item; +} - return adapter; +static inline gchar *bluez_return_adapter(const char *path) +{ + return find_index(path, 3); } static inline gchar *bluez_return_device(const char *path) { - const char *basename; + return find_index(path, 4); +} + +static inline gboolean is_mediaplayer1_interface(const char *path) +{ + gchar *data = NULL; + gboolean ret; - basename = strrchr(path, '/'); - if (!basename) - return NULL; - basename++; + // Don't trigger on NowPlaying, Item, etc paths + if (split_length(path) != 6) + return FALSE; - /* be sure it is a bluez path with device */ - if (strncmp(basename, "dev_", 4)) - return NULL; + // TODO: allow mutiple players per device + data = find_index(path, 5); + ret = !g_strcmp0(data, BLUEZ_DEFAULT_PLAYER); + g_free(data); - /* at least one character */ - return *basename ? g_strdup(basename) : NULL; + return ret; } struct call_work *call_work_create_unlocked(struct bluetooth_state *ns, @@ -163,6 +180,14 @@ static inline gboolean agent_property_dbus2json(json_object *jprop, jprop, key, var, is_config, error); } +static inline gboolean mediaplayer_property_dbus2json(json_object *jprop, + const gchar *key, GVariant *var, gboolean *is_config, + GError **error) +{ + return bluez_property_dbus2json(BLUEZ_AT_MEDIAPLAYER, + jprop, key, var, is_config, error); +} + static inline GVariant *device_call(struct bluetooth_state *ns, const char *device, const char *method, GVariant *params, GError **error) @@ -216,6 +241,13 @@ static inline json_object *adapter_properties(struct bluetooth_state *ns, BLUEZ_AT_ADAPTER, adapter, error); } +static inline json_object *mediaplayer_properties(struct bluetooth_state *ns, + GError **error, const gchar *player) +{ + return bluez_get_properties(ns, + BLUEZ_AT_MEDIAPLAYER, player, error); +} + static inline json_object *object_properties(struct bluetooth_state *ns, GError **error) { |