summaryrefslogtreecommitdiffstats
path: root/binding/bluetooth-api.h
diff options
context:
space:
mode:
authorMatt Ranostay <matt.ranostay@konsulko.com>2018-11-07 19:08:06 -0800
committerMatt Ranostay <matt.ranostay@konsulko.com>2018-11-14 03:16:58 -0800
commit76a617a9473c02e7c4624f47a62f5c60b1e77148 (patch)
tree4f776c7cb7ff1dfebbf949a920cd74434f34452b /binding/bluetooth-api.h
parenta5fe25e7496cf4a8369e1f34e66c9e55d2c95ed1 (diff)
binding: bluetooth: add MediaPlayer1 interface media eventsguppy_6.99.2guppy_6.99.1guppy/6.99.2guppy/6.99.16.99.26.99.1
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.h68
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)
{