summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-03-14 10:48:07 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2017-03-16 17:15:55 +0100
commit83f0501dbb4cd2f2baf8c164728334a0142ec94d (patch)
treec54619fb6f53afacabc7c0b0e1c116140622c15b
parent665f905386a0362657888db5e3a213a1c03f72ee (diff)
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 <romain.forlot@iot.bzh>
-rw-r--r--src/diagnostic/diagnostic-manager.cpp23
-rw-r--r--src/low-can-binding.cpp7
2 files changed, 22 insertions, 8 deletions
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 <systemd/sd-event.h>
#include <algorithm>
#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;
}
}
diff --git a/src/low-can-binding.cpp b/src/low-can-binding.cpp
index f6e9849..0c26595 100644
--- a/src/low-can-binding.cpp
+++ b/src/low-can-binding.cpp
@@ -25,7 +25,6 @@
#include <time.h>
#include <linux/can.h>
#include <json-c/json.h>
-#include <systemd/sd-event.h>
#include "openxc.pb.h"
#include "configuration.hpp"
@@ -42,8 +41,6 @@ extern "C"
#include <afb/afb-service-itf.h>
};
-#define MICRO 1000000
-
// Interface between the daemon and the binding
const struct afb_binding_interface *binder_interface;
@@ -124,7 +121,6 @@ static int subscribe_unsubscribe_signal(struct afb_req request, bool subscribe,
static int subscribe_unsubscribe_signals(struct afb_req request, bool subscribe, const std::vector<std::string>& signals)
{
int rets = 0;
- sd_event_source *source;
//TODO: Implement way to dynamically call the right function no matter
// how much signals types we have.
@@ -141,9 +137,6 @@ static int subscribe_unsubscribe_signals(struct afb_req request, bool subscribe,
configuration_t::instance().get_diagnostic_manager().add_recurring_request(
diag_req, sig.c_str(), false, obd2_signal_t::decode_obd2_response, nullptr, (float)frequency);
//TODO: Adding callback requesting ignition status: diag_req, sig.c_str(), false, obd2_signal_t::decode_obd2_response, obd2_signal_t::check_ignition_status, frequency);
- sd_event_add_time(afb_daemon_get_event_loop(binder_interface->daemon), &source, CLOCK_MONOTONIC, frequency*MICRO, 0,
- configuration_t::instance().get_diagnostic_manager().send_request, diag_req);
- sd_event_source_set_enabled(source, SD_EVENT_ON);
}
ret = subscribe_unsubscribe_signal(request, subscribe, sig);