summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Murray <scott.murray@konsulko.com>2019-01-03 01:36:35 -0500
committerScott Murray <scott.murray@konsulko.com>2019-01-06 14:45:01 +0000
commit2e8ebe0377f4e6ac8d8e0cb43b6b3d8bce3552a9 (patch)
treea97041143f26871838996381b7b7721de4c6cc3f
parent6e70d2b8b821622ae81796a6f1d3f7f3881610a2 (diff)
Add a status event to indicate playing versus stopped state, this allows users to detect when the binding has been stopped by another user. Change-Id: I4c1256427f0113b535e12a2dbc121d45c93dc0dd Signed-off-by: Scott Murray <scott.murray@konsulko.com> (cherry picked from commit a2fdf6e139207e7b0e0270c8a167c6a30c8fe61d)
-rw-r--r--README.md4
-rw-r--r--binding/radio-binding.c16
2 files changed, 20 insertions, 0 deletions
diff --git a/README.md b/README.md
index ab76ec2..310f16b 100644
--- a/README.md
+++ b/README.md
@@ -32,6 +32,10 @@ JSON response has a single field **frequency** which is the currently tuned freq
JSON response has a single field **value** of the frequency of the discovered radio station.
+### status Event JSON Response
+
+JSON response has a single field **value** with one of the values "playing" or "stopped".
+
# AGL Radio Tuner Binding
## FM Band Plan Selection
diff --git a/binding/radio-binding.c b/binding/radio-binding.c
index 490af5b..02135fc 100644
--- a/binding/radio-binding.c
+++ b/binding/radio-binding.c
@@ -35,6 +35,7 @@ static radio_impl_ops_t *radio_impl_ops;
static struct afb_event freq_event;
static struct afb_event scan_event;
+static struct afb_event status_event;
static void freq_callback(uint32_t frequency, void *data)
{
@@ -376,6 +377,11 @@ static void start(struct afb_req request)
free(output);
}
afb_req_success(request, NULL, NULL);
+
+ json_object *jresp = json_object_new_object();
+ json_object *value = json_object_new_string("playing");
+ json_object_object_add(jresp, "value", value);
+ afb_event_push(status_event, json_object_get(jresp));
}
/*
@@ -389,6 +395,11 @@ static void stop(struct afb_req request)
radio_impl_ops->stop();
set_role_state(false, NULL);
afb_req_success(request, NULL, NULL);
+
+ json_object *jresp = json_object_new_object();
+ json_object *value = json_object_new_string("stopped");
+ json_object_object_add(jresp, "value", value);
+ afb_event_push(status_event, json_object_get(jresp));
}
/*
@@ -507,6 +518,8 @@ static void subscribe(struct afb_req request)
afb_req_subscribe(request, freq_event);
} else if(!strcasecmp(value, "station_found")) {
afb_req_subscribe(request, scan_event);
+ } else if(!strcasecmp(value, "status")) {
+ afb_req_subscribe(request, status_event);
} else {
afb_req_fail(request, "failed", "Invalid event");
return;
@@ -529,6 +542,8 @@ static void unsubscribe(struct afb_req request)
afb_req_unsubscribe(request, freq_event);
} else if(!strcasecmp(value, "station_found")) {
afb_req_unsubscribe(request, scan_event);
+ } else if(!strcasecmp(value, "status")) {
+ afb_req_unsubscribe(request, status_event);
} else {
afb_req_fail(request, "failed", "Invalid event");
return;
@@ -577,6 +592,7 @@ static int init()
// Initialize event structures
freq_event = afb_daemon_make_event("frequency");
scan_event = afb_daemon_make_event("station_found");
+ status_event = afb_daemon_make_event("status");
return 0;
}