diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-05-24 01:38:00 +0200 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-05-24 01:38:00 +0200 |
commit | 71096ceee301ebc450aacb29d99190b3e158753f (patch) | |
tree | 9a524b08cb60c115018562e5127f6a5d7b887cca /CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp | |
parent | d9e84736777908cd23ce1f7e935fa8b43849685c (diff) |
Close diagnostic manager socket if there isn't any requests
No need to listen diagnostic responses if there isn't any subscriptions.
Change-Id: I7fa48dbc3e8fb1847b8186337fe2813625894406
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp')
-rw-r--r-- | CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp b/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp index 49013f8e..31a3d23f 100644 --- a/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp +++ b/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp @@ -214,6 +214,16 @@ DiagnosticShims& diagnostic_manager_t::get_shims() return shims_; } +bool diagnostic_manager_t::socket_close() +{ + if(non_recurring_requests_.empty() && recurring_requests_.empty()) + { + socket_.close(); + return true; + } + return false; +} + /// @brief Search for a specific active diagnostic request in the provided requests list /// and erase it from the vector. This is useful at unsubscription to clean up the list otherwize /// all received CAN messages will be passed to DiagnosticRequestHandle of all active diagnostic request @@ -251,16 +261,17 @@ void diagnostic_manager_t::cleanup_request(active_diagnostic_request_t* entry, b request_string, sizeof(request_string)); if(force && entry->get_recurring()) { - find_and_erase(entry, recurring_requests_); cancel_request(entry); + find_and_erase(entry, recurring_requests_); DEBUG(binder_interface, "%s: Cancelling completed, recurring request: %s", __FUNCTION__, request_string); } - else + else if (!entry->get_recurring()) { DEBUG(binder_interface, "%s: Cancelling completed, non-recurring request: %s", __FUNCTION__, request_string); - find_and_erase(entry, non_recurring_requests_); cancel_request(entry); + find_and_erase(entry, non_recurring_requests_); } + socket_close(); } } @@ -271,12 +282,17 @@ void diagnostic_manager_t::cleanup_request(active_diagnostic_request_t* entry, b void diagnostic_manager_t::cleanup_active_requests(bool force) { for(auto& entry : non_recurring_requests_) + { if (entry != nullptr) cleanup_request(entry, force); + } for(auto& entry : recurring_requests_) + { if (entry != nullptr) cleanup_request(entry, force); + } + } /// @brief Will return the active_diagnostic_request_t pointer for theDiagnosticRequest or nullptr if |