From 83f0501dbb4cd2f2baf8c164728334a0142ec94d Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Tue, 14 Mar 2017 10:48:07 +0100 Subject: Move diagnostic requests scheduling to diagnostic manager while adding the request. It is more logic to make that here than in the subscription operation. Change-Id: I19b29bc11c5fb6e5828a0bf189fac1333b0199ed Signed-off-by: Romain Forlot --- src/diagnostic/diagnostic-manager.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/diagnostic') diff --git a/src/diagnostic/diagnostic-manager.cpp b/src/diagnostic/diagnostic-manager.cpp index 915b449..482a88f 100644 --- a/src/diagnostic/diagnostic-manager.cpp +++ b/src/diagnostic/diagnostic-manager.cpp @@ -15,6 +15,7 @@ * limitations under the License. */ +#include #include #include "diagnostic-manager.hpp" @@ -26,6 +27,7 @@ #define MAX_RECURRING_DIAGNOSTIC_FREQUENCY_HZ 10 #define MAX_SIMULTANEOUS_DIAG_REQUESTS 50 #define MAX_REQUEST_ENTRIES 50 +#define MICRO 1000000 diagnostic_manager_t::diagnostic_manager_t() : request_list_entries_(MAX_REQUEST_ENTRIES, new active_diagnostic_request_t()), initialized_{false} @@ -233,6 +235,7 @@ bool diagnostic_manager_t::add_recurring_request(DiagnosticRequest* request, con if(entry != nullptr) { + sd_event_source *source; // TODO: implement Acceptance Filter //if(updateRequiredAcceptanceFilters(bus, request)) { entry = new active_diagnostic_request_t(bus_, request, name, @@ -247,11 +250,29 @@ bool diagnostic_manager_t::add_recurring_request(DiagnosticRequest* request, con DEBUG(binder_interface, "Added recurring diagnostic request (freq: %f) on bus %s: %s", frequencyHz, bus_->get_device_name().c_str(), request_string); - recurring_requests_.push_back(entry); + if(sd_event_add_time(afb_daemon_get_event_loop(binder_interface->daemon), &source, + CLOCK_MONOTONIC, (uint64_t)frequencyHz*MICRO, 0,send_request, request) >= 0) + { + if(sd_event_source_set_enabled(source, SD_EVENT_ON) >= 0) + recurring_requests_.push_back(entry); + else + { + ERROR(binder_interface, "add_reccurring_request: Request has not been enabled, it will occurs only one time"); + free_request_entries_.push_back(entry); + added = false; + } + } + else + { + ERROR(binder_interface, "add_recurring_request: Request fails to be schedule through event loop"); + free_request_entries_.push_back(entry); + added = false; + } } else { WARNING(binder_interface, "There isn't enough request entry. Vector exhausted %d/%d", (int)request_list_entries_.size(), (int)request_list_entries_.max_size()); + free_request_entries_.push_back(entry); added = false; } } -- cgit 1.2.3-korg