diff options
author | Scott Murray <scott.murray@konsulko.com> | 2019-12-11 23:06:18 +0000 |
---|---|---|
committer | Scott Murray <scott.murray@konsulko.com> | 2019-12-11 23:15:40 +0000 |
commit | 76169c061b7ceabdf6f67dcc700d53ae8f02c821 (patch) | |
tree | 2221fa43abcd512e304c39af5e133eaea4c0d1c9 /binding/afm-mediaplayer-binding.c | |
parent | 0a43c4a922f09c2a485d9f1497a9a9b20a42b020 (diff) |
Initial steering wheel event support
Add initial basic support for next/previous events from signal composer,
mapping them to track forward/back. More work will be required to handle
the issues around both mediaplayer and radio both being running and
differentiating which should handle the events.
Bug-AGL: SPEC-3047
Signed-off-by: Scott Murray <scott.murray@konsulko.com>
Change-Id: I789181e1921aa55f4a9ec84deffe3f27560289c3
Diffstat (limited to 'binding/afm-mediaplayer-binding.c')
-rw-r--r-- | binding/afm-mediaplayer-binding.c | 76 |
1 files changed, 75 insertions, 1 deletions
diff --git a/binding/afm-mediaplayer-binding.c b/binding/afm-mediaplayer-binding.c index 14a4fa1..495353d 100644 --- a/binding/afm-mediaplayer-binding.c +++ b/binding/afm-mediaplayer-binding.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Konsulko Group + * Copyright (C) 2017, 2019 Konsulko Group * Author: Matt Ranostay <matt.ranostay@konsulko.com> * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -40,6 +40,13 @@ static GList *playlist = NULL; static GList *metadata_track = NULL; static GList *current_track = NULL; +static const char *signalcomposer_events[] = { + "event.media.next", + "event.media.previous", + "event.media.mode", + NULL, +}; + static json_object *populate_json_metadata(void); enum { @@ -990,11 +997,58 @@ static void onevent(afb_api_t api, const char *event, struct json_object *object afb_event_push(metadata_event, object); return; + } else if (g_str_has_prefix(event, "signal-composer/")) { + json_object *tmp = NULL; + const char *uid; + const char *value; + + json_object_object_get_ex(object, "uid", &tmp); + if (tmp == NULL) + return; + + uid = json_object_get_string(tmp); + if (strncmp(uid, "event.media.", 12)) + return; + + json_object_object_get_ex(object, "value", &tmp); + if (tmp == NULL) + return; + + value = json_object_get_string(tmp); + if (strncmp(value, "true", 4)) + return; + + if (!strcmp(uid, "event.media.next")) { + if(data.playing) { + g_mutex_lock(&mutex); + seek_track(NEXT_CMD); + g_mutex_unlock(&mutex); + + json_object_get(object); + afb_event_push(metadata_event, object); + } + } else if (!strcmp(uid, "event.media.previous")) { + if(data.playing) { + g_mutex_lock(&mutex); + seek_track(PREVIOUS_CMD); + g_mutex_unlock(&mutex); + + json_object_get(object); + afb_event_push(metadata_event, object); + } + } else if (!strcmp(uid, "event.media.mode")) { + // Do nothing ATM + } else { + AFB_WARNING("Unhandled signal-composer uid '%s'", uid); + } + return; } else { AFB_ERROR("Invalid event: %s", event); return; } + // Fall through for mediascanner events + jresp = json_object_new_object(); jresp = populate_json_playlist(jresp); @@ -1052,6 +1106,26 @@ static int init(afb_api_t api) return ret; } + ret = afb_daemon_require_api("signal-composer", 1); + if (ret) { + AFB_WARNING("unable to initialize signal-composer binding"); + } else { + const char **tmp = signalcomposer_events; + json_object *args = json_object_new_object(); + json_object *signals = json_object_new_array(); + + while (*tmp) { + json_object_array_add(signals, json_object_new_string(*tmp++)); + } + json_object_object_add(args, "signal", signals); + if(json_object_array_length(signals)) { + afb_api_call_sync(api, "signal-composer", "subscribe", + args, NULL, NULL, NULL); + } else { + json_object_put(args); + } + } + metadata_event = afb_daemon_make_event("metadata"); playlist_event = afb_daemon_make_event("playlist"); |