summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Collignon <loic.collignon@iot.bzh>2018-10-31 14:18:49 +0100
committerLoïc Collignon <loic.collignon@iot.bzh>2018-12-20 18:08:01 +0100
commit1401b3d2c1974220deffb27754326976c341405b (patch)
tree56638cf86a9c0c2e3b0b0dc63418d032d1affe45
parent0b4547dd01aec3b00287344d258e4db21bcd57b8 (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>
-rw-r--r--ahl-binding/role.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/ahl-binding/role.cpp b/ahl-binding/role.cpp
index bc109e8..06caa98 100644
--- a/ahl-binding/role.cpp
+++ b/ahl-binding/role.cpp
@@ -160,20 +160,22 @@ void role_t::open(afb_req_t r, json_object* o)
if (!apply_policy(r))
{
- afb_req_context(r,
- 0, // Do not replace previous context if any
- [](void* arg) -> void* { return new session_t(); },
- [](void* arg) {
- afb_api_t api = ahl_binding_t::instance().handle();
- session_t* opened_roles = reinterpret_cast<session_t*>(arg);
- for(role_t* role : *opened_roles)
+ afb_req_context_set(
+ r,
+ this,
+ [](void* arg)
+ {
+ role_t * role = (role_t*) arg;
+
+ 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;
- if(role->interrupts_.size()) role->interrupts_[0].clear();
// 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.
+ // 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));
@@ -185,9 +187,7 @@ void role_t::open(afb_req_t r, json_object* o)
NULL,
NULL);
}
- delete opened_roles;
- },
- this
+ }
);
opened_ = true;