summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Collignon <loic.collignon@iot.bzh>2018-11-15 15:45:30 +0100
committerLoïc Collignon <loic.collignon@iot.bzh>2018-12-20 18:12:28 +0100
commitcc1b67bfc67fb5c7a9e1b8c9ba287dd48d2ccf36 (patch)
treee5fa5d78902a7a891b7433422ec7f967a3b2e3a5
parentdf83729280b6540b9a5eb796b404cc70dc1566c4 (diff)
Fix issues with session and policies
When a policy does a 'ramp-down' on an audio role, it never does the 'ramp-up' when closing the role that triggered the policy. Also, session handling was very buggy and had to be reworked to allow the policy to do its job. Bug: SPEC-1949 Bug: SPEC-1950 Change-Id: Iabf0e08b87862bf4620870e4b4a1214f699c7e64 Signed-off-by: Loïc Collignon <loic.collignon@iot.bzh>
-rw-r--r--ahl-binding/interrupt.cpp14
-rw-r--r--ahl-binding/role.cpp26
2 files changed, 18 insertions, 22 deletions
diff --git a/ahl-binding/interrupt.cpp b/ahl-binding/interrupt.cpp
index b0eebec..5bf0b79 100644
--- a/ahl-binding/interrupt.cpp
+++ b/ahl-binding/interrupt.cpp
@@ -72,17 +72,13 @@ int interrupt_t::apply(afb_req_t req, const role_t& role)
afb_req_fail(req, "Failed to call 'ramp' action on stream", nullptr);
return -1;
}
- json_object* response = nullptr;
json_object* jvolold = nullptr;
- if (json_object_object_get_ex(result, "response", &response))
+ if (json_object_object_get_ex(result, "volold", &jvolold))
{
- if (json_object_object_get_ex(response, "volold", &jvolold))
- {
- applied_on_.push_back(std::make_tuple<std::string, int>(r.uid(), json_object_get_int(jvolold)));
- AFB_API_DEBUG(ahl_binding_t::instance().handle(),
- "POLICY: Applying a ramp to '%s' stream because '%s' is opened and have higher priority!",
- r.stream().c_str(), role.stream().c_str());
- }
+ applied_on_.push_back(std::make_tuple<std::string, int>(r.uid(), json_object_get_int(jvolold)));
+ AFB_API_DEBUG(ahl_binding_t::instance().handle(),
+ "POLICY: Applying a ramp to '%s' stream because '%s' is opened and have higher priority!",
+ r.stream().c_str(), role.stream().c_str());
}
}
}
diff --git a/ahl-binding/role.cpp b/ahl-binding/role.cpp
index 7d35889..3a4dd0e 100644
--- a/ahl-binding/role.cpp
+++ b/ahl-binding/role.cpp
@@ -160,22 +160,20 @@ void role_t::open(afb_req_t r, json_object* o)
if (!apply_policy(r))
{
- afb_req_context_set(
- r,
- this,
- [](void* arg)
- {
- role_t * role = (role_t*) arg;
-
- if (role->opened_)
+ 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_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_req_t is no longer valid.
+ // 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));
@@ -187,14 +185,16 @@ void role_t::open(afb_req_t r, json_object* o)
NULL,
NULL);
}
- }
+ delete opened_roles;
+ },
+ nullptr
);
opened_ = true;
// Add the current role to the session
session_t* context = reinterpret_cast<session_t*>(afb_req_context_get(r));
- context->push_back(this);
+ if(context) context->push_back(this);
json_object* result = json_object_new_object();
json_object_object_add(result, "device_uri", json_object_new_string(device_uri_.c_str()));