diff options
author | Thierry Bultel <thierry.bultel@iot.bzh> | 2018-07-03 18:52:33 +0200 |
---|---|---|
committer | Thierry Bultel <thierry.bultel@iot.bzh> | 2018-07-11 13:33:30 +0200 |
commit | 11d2ae972c434453f09a7ffe66a8c202efbce2a5 (patch) | |
tree | 9d02251b24e6a895405dd353587f0c468c84cc43 /ahl-binding/role.cpp | |
parent | e2e78437b472dc40e605cdcd895804105a680a1f (diff) |
Added role for radio, and mute/unmute actionsflounder_5.99.4flounder_5.99.3flounder_5.99.2flounder/5.99.4flounder/5.99.3flounder/5.99.25.99.45.99.35.99.2
This defines a new 'radio' role that uses the radio_stream
Also implements the new mute/unmute actions, that are
forwarded to the softmixer.
Now registers to a client (multimedia player, radio service ...)
disconnection, to properly free the leased role.
Change-Id: Ic15fb63cd90ba28f3978c67d917a77ed6b030e08
Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
Diffstat (limited to 'ahl-binding/role.cpp')
-rw-r--r-- | ahl-binding/role.cpp | 66 |
1 files changed, 63 insertions, 3 deletions
diff --git a/ahl-binding/role.cpp b/ahl-binding/role.cpp index 5b2f95e..1b60a40 100644 --- a/ahl-binding/role.cpp +++ b/ahl-binding/role.cpp @@ -187,6 +187,8 @@ void role_t::invoke(afb_request* req) else if (action == "close") close(req, arg); else if (action == "volume") volume(req, arg); else if (action == "interrupt") interrupt(req, arg); + else if (action == "mute") mute(req, arg); + else if (action == "unmute") unmute(req, arg); else afb_request_fail(req, "Unknown action!", nullptr); } @@ -200,7 +202,31 @@ void role_t::open(afb_request* r, json_object* o) if (!apply_policy(r)) { - afb_request_context_set(r, this, nullptr); + afb_request_context_set( + r, + this, + [](void* arg) + { + role_t * role = (role_t*) arg; + afb_dynapi * api = ahl_binding_t::instance().handle(); + + AFB_DYNAPI_NOTICE(api, "Released role %s\n", role->uid_.c_str()); + role->opened_ = false; + + // send a mute command to the HAL. We cannot reuse the do_mute function, + // because in the context here, the afb_request is no longer valid. + json_object* a = json_object_new_object(); + json_object_object_add(a, "mute", json_object_new_boolean(true)); + + afb_dynapi_call( + api, + role->hal_.c_str(), + role->stream_.c_str(), + a, + NULL, + NULL); + } + ); opened_ = true; json_object* result = json_object_new_object(); @@ -228,8 +254,42 @@ void role_t::close(afb_request* r, json_object* o) afb_request_success(r, nullptr, "Stream closed!"); } +void role_t::mute(afb_request * r, json_object* o) { + do_mute(r, true); +} + +void role_t::unmute(afb_request *r, json_object *o) { + do_mute(r, false); +} + +void role_t::do_mute(afb_request * r, bool v) { + + json_object* a = json_object_new_object(); + json_object_object_add(a, "mute", json_object_new_boolean(v)); + afb_dynapi * api = ahl_binding_t::instance().handle(); + + afb_dynapi_call( + api, + hal_.c_str(), + stream_.c_str(), + a, + [](void* closure, int status, json_object* result, afb_dynapi* handle) + { + AFB_DYNAPI_DEBUG(handle, "Got the following answer: %s", json_object_to_json_string(result)); + afb_request* r = (afb_request*)closure; + + json_object_get(result); + if (status) afb_request_fail(r, json_object_to_json_string(result), nullptr); + else afb_request_success(r, result, nullptr); + afb_request_unref(r); + }, + afb_request_addref(r)); +} + void role_t::volume(afb_request* r, json_object* o) { + afb_dynapi * api = ahl_binding_t::instance().handle(); + if(!afb_request_has_permission(r, "urn:AGL:permission::public:4a-audio-mixer")) { if (!opened_) @@ -246,7 +306,7 @@ void role_t::volume(afb_request* r, json_object* o) } else { - AFB_DYNAPI_NOTICE(ahl_binding_t::instance().handle(), "Granted special audio-mixer permission to change volume"); + AFB_DYNAPI_NOTICE(api, "Granted special audio-mixer permission to change volume"); } json_object* value; @@ -263,7 +323,7 @@ void role_t::volume(afb_request* r, json_object* o) json_object_object_add(a, "volume", value); afb_dynapi_call( - r->api, + api, hal_.c_str(), stream_.c_str(), a, |