summaryrefslogtreecommitdiffstats
path: root/src/diagnostic/diagnostic-manager.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-03-15 00:47:06 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2017-03-16 17:21:57 +0100
commita67c74b2f5e53e628f07846ca9c8acd42ac94794 (patch)
treeba312db18906fba723cf149f1105cdc5471afa51 /src/diagnostic/diagnostic-manager.cpp
parent29c259518cc53e2de8b2a082803c4ace40b1f754 (diff)
Simplification of diagnostic manager. Delete uneeded vector
Control size manually, don't rely on STL container. Change-Id: Iede2f9b233c5b8a6dc77c9b146ffc92da8e7a989 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src/diagnostic/diagnostic-manager.cpp')
-rw-r--r--src/diagnostic/diagnostic-manager.cpp59
1 files changed, 20 insertions, 39 deletions
diff --git a/src/diagnostic/diagnostic-manager.cpp b/src/diagnostic/diagnostic-manager.cpp
index 2821dc0..a9af6e4 100644
--- a/src/diagnostic/diagnostic-manager.cpp
+++ b/src/diagnostic/diagnostic-manager.cpp
@@ -26,12 +26,11 @@
#define MAX_RECURRING_DIAGNOSTIC_FREQUENCY_HZ 10
#define MAX_SIMULTANEOUS_DIAG_REQUESTS 50
-#define MAX_REQUEST_ENTRIES 50
#define TIMERFD_ACCURACY 0
#define MICRO 1000000
diagnostic_manager_t::diagnostic_manager_t()
- : request_list_entries_(MAX_REQUEST_ENTRIES, new active_diagnostic_request_t()), initialized_{false}
+ : initialized_{false}
{}
bool diagnostic_manager_t::initialize(std::shared_ptr<can_bus_dev_t> cbd)
@@ -65,12 +64,6 @@ void diagnostic_manager_t::reset()
DEBUG(binder_interface, "Clearing existing diagnostic requests");
cleanup_active_requests(true);
}
-
- for(uint8_t i = 0; i < MAX_REQUEST_ENTRIES; i++)
- {
- free_request_entries_.push_back(request_list_entries_.back());
- request_list_entries_.pop_back();
- }
}
@@ -85,7 +78,7 @@ void diagnostic_manager_t::find_and_erase(active_diagnostic_request_t* entry, st
/// CAN filters it used.
void diagnostic_manager_t::cancel_request(active_diagnostic_request_t* entry)
{
- free_request_entries_.push_back(entry);
+
/* TODO: implement acceptance filters.
if(entry.arbitration_id_ == OBD2_FUNCTIONAL_BROADCAST_ID) {
for(uint32_t filter = OBD2_FUNCTIONAL_RESPONSE_START;
@@ -118,43 +111,41 @@ void diagnostic_manager_t::cleanup_request(active_diagnostic_request_t* entry, b
find_and_erase(entry, recurring_requests_);
if(force)
cancel_request(entry);
- else
- {
- DEBUG(binder_interface, "Moving completed recurring request to the back of the queue: %s", request_string);
- recurring_requests_.push_back(entry);
- }
}
else
{
- DEBUG(binder_interface, "Cancelling completed, non-recurring request: %s", request_string);
+ DEBUG(binder_interface, "cleanup_request: Cancelling completed, non-recurring request: %s", request_string);
find_and_erase(entry, non_recurring_requests_);
cancel_request(entry);
}
}
}
-/// @brief Clean up the request list, move as many to the free list as possible
+/// @brief Clean up the request list
void diagnostic_manager_t::cleanup_active_requests(bool force)
{
for(auto& entry : non_recurring_requests_)
- cleanup_request(entry, force);
+ if (entry != nullptr)
+ cleanup_request(entry, force);
for(auto& entry : recurring_requests_)
- cleanup_request(entry, force);
+ if (entry != nullptr)
+ cleanup_request(entry, force);
}
-/// @brief Note that this pops it off of whichver list it was on and returns it, so make
-/// sure to add it to some other list or it'll be lost.
+/// @brief Will return the active_diagnostic_request_t pointer of found request or nullptr if
+/// not found.
active_diagnostic_request_t* diagnostic_manager_t::find_recurring_request(const DiagnosticRequest* request)
{
for (auto& entry : recurring_requests_)
{
- active_diagnostic_request_t* candidate = entry;
- if(diagnostic_request_equals(&candidate->get_handle()->request, request))
+ if(entry != nullptr)
{
- find_and_erase(entry, recurring_requests_);
- return entry;
- break;
+ if(diagnostic_request_equals(&entry->get_handle()->request, request))
+ {
+ return entry;
+ break;
+ }
}
}
return nullptr;
@@ -165,16 +156,6 @@ std::shared_ptr<can_bus_dev_t> diagnostic_manager_t::get_can_bus_dev()
return bus_;
}
-active_diagnostic_request_t* diagnostic_manager_t::get_free_entry()
-{
- if (free_request_entries_.empty())
- return nullptr;
-
- active_diagnostic_request_t* adr = free_request_entries_.back();
- free_request_entries_.pop_back();
- return adr;
-}
-
bool diagnostic_manager_t::add_request(DiagnosticRequest* request, const std::string name,
bool wait_for_multiple_responses, const DiagnosticResponseDecoder decoder,
const DiagnosticResponseCallback callback)
@@ -182,13 +163,12 @@ bool diagnostic_manager_t::add_request(DiagnosticRequest* request, const std::st
cleanup_active_requests(false);
bool added = true;
- active_diagnostic_request_t* entry = get_free_entry();
- if (entry != nullptr)
+ if (non_recurring_requests_.size() <= MAX_SIMULTANEOUS_DIAG_REQUESTS)
{
// TODO: implement Acceptance Filter
// if(updateRequiredAcceptanceFilters(bus, request)) {
- entry = new active_diagnostic_request_t(bus_, request, name,
+ active_diagnostic_request_t* entry = new active_diagnostic_request_t(bus_, request, name,
wait_for_multiple_responses, decoder, callback, 0);
entry->set_handle(shims_, request);
@@ -204,7 +184,8 @@ bool diagnostic_manager_t::add_request(DiagnosticRequest* request, const std::st
}
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());
+ WARNING(binder_interface, "There isn't enough request entry. Vector exhausted %d/%d", (int)non_recurring_requests_.size());
+ non_recurring_requests_.resize(MAX_SIMULTANEOUS_DIAG_REQUESTS);
added = false;
}
return added;