diff options
Diffstat (limited to 'ahl-binding/role.cpp')
-rw-r--r-- | ahl-binding/role.cpp | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/ahl-binding/role.cpp b/ahl-binding/role.cpp index 1114973..0da9304 100644 --- a/ahl-binding/role.cpp +++ b/ahl-binding/role.cpp @@ -257,18 +257,18 @@ void role_t::close(afb_req_t r, json_object* o) } void role_t::mute(afb_req_t r, json_object* o) { - do_mute(r, true); + do_mute(r, true); } void role_t::unmute(afb_req_t r, json_object *o) { - do_mute(r, false); + do_mute(r, false); } void role_t::do_mute(afb_req_t r, bool v) { - json_object* a = json_object_new_object(); + json_object* a = json_object_new_object(); json_object_object_add(a, "mute", json_object_new_boolean(v)); - afb_api_t api = ahl_binding_t::instance().handle(); + afb_api_t api = ahl_binding_t::instance().handle(); afb_api_call( api, @@ -288,9 +288,15 @@ void role_t::do_mute(afb_req_t r, bool v) { afb_req_addref(r)); } +struct volumeclosure +{ + std::string role; + afb_req_t req; +}; + void role_t::volume(afb_req_t r, json_object* o) { - afb_api_t api = ahl_binding_t::instance().handle(); + afb_api_t api = ahl_binding_t::instance().handle(); if(!afb_req_has_permission(r, "urn:AGL:permission::public:4a-audio-mixer")) { @@ -324,6 +330,10 @@ void role_t::volume(afb_req_t r, json_object* o) json_object* a = json_object_new_object(); json_object_object_add(a, "volume", value); + volumeclosure* userdata = new volumeclosure(); + userdata->role = uid_; + userdata->req = afb_req_addref(r); + afb_api_call( api, hal_.c_str(), @@ -332,14 +342,24 @@ void role_t::volume(afb_req_t r, json_object* o) [](void* closure, json_object* result, const char* error, const char* info, afb_api_t handle) { AFB_API_DEBUG(handle, "Got the following answer: %s", json_object_to_json_string(result)); - afb_req_t r = (afb_req_t)closure; + volumeclosure* r = reinterpret_cast<volumeclosure*>(closure); json_object_get(result); - if (error) afb_req_fail(r, json_object_to_json_string(result), nullptr); - else afb_req_success(r, result, nullptr); - afb_req_unref(r); + if (error) afb_req_fail(r->req, json_object_to_json_string(result), nullptr); + else + { + json_object* volnew; + if (json_object_object_get_ex(result, "volnew", &volnew)) + { + ahl_binding_t::instance().emit_volume_changed(r->role, json_object_get_int(volnew)); + } + afb_req_success(r->req, result, nullptr); + } + afb_req_unref(r->req); + delete r; }, - afb_req_addref(r)); + userdata + ); } void role_t::interrupt(afb_req_t r, json_object* o) |