diff options
author | Loïc Collignon <loic.collignon@iot.bzh> | 2018-10-31 14:18:49 +0100 |
---|---|---|
committer | Loïc Collignon <loic.collignon@iot.bzh> | 2018-10-31 14:18:49 +0100 |
commit | 2df32d051f3154576cd0eb807f2bf132172ff16d (patch) | |
tree | 4d880538519f92d1acd2ecf80be21acb30ca528c /ahl-binding/role.cpp | |
parent | 00340de676ba1cac9c43e2d0ba366e9a593581a4 (diff) |
Don't automatically close already closed roles
On connection close, opened roles are closed as well. This prevent the
auto-close to happen if the role is already closed.
Bug: SPEC-1835
Change-Id: I9d8d8265927e758009108cdade26600d408b93e0
Signed-off-by: Loïc Collignon <loic.collignon@iot.bzh>
Diffstat (limited to 'ahl-binding/role.cpp')
-rw-r--r-- | ahl-binding/role.cpp | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/ahl-binding/role.cpp b/ahl-binding/role.cpp index b48b58e..1114973 100644 --- a/ahl-binding/role.cpp +++ b/ahl-binding/role.cpp @@ -206,23 +206,27 @@ void role_t::open(afb_req_t r, json_object* o) [](void* arg) { role_t * role = (role_t*) arg; - afb_api_t api = ahl_binding_t::instance().handle(); - - AFB_API_DEBUG(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_req_t is no longer valid. - json_object* a = json_object_new_object(); - json_object_object_add(a, "mute", json_object_new_boolean(true)); - - afb_api_call( - api, - role->hal_.c_str(), - role->stream_.c_str(), - a, - NULL, - NULL); + + if (role->opened_) + { + afb_api_t api = ahl_binding_t::instance().handle(); + + AFB_API_DEBUG(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_req_t is no longer valid. + json_object* a = json_object_new_object(); + json_object_object_add(a, "mute", json_object_new_boolean(true)); + + afb_api_call( + api, + role->hal_.c_str(), + role->stream_.c_str(), + a, + NULL, + NULL); + } } ); opened_ = true; |