From 6d6b880b2769add860cb0f135e0f784f8aaf5e00 Mon Sep 17 00:00:00 2001 From: Arthur Guyader Date: Tue, 27 Aug 2019 14:48:29 +0200 Subject: Add some typedef to reduce the size of the lines Bug-AGL : SPEC-2779 Change-Id: Iebcf7492133cd7789d301593ff999b24ae10a054 Signed-off-by: Arthur Guyader --- low-can-binding/binding/application.cpp | 8 ++++---- low-can-binding/binding/application.hpp | 4 ++-- low-can-binding/binding/low-can-cb.cpp | 22 +++++++++++----------- low-can-binding/binding/low-can-hat.hpp | 6 ++++-- low-can-binding/binding/low-can-subscription.cpp | 2 +- low-can-binding/binding/low-can-subscription.hpp | 5 +++-- low-can-binding/can/can-bus.cpp | 8 ++++---- low-can-binding/can/can-bus.hpp | 4 ++-- low-can-binding/can/message-definition.cpp | 6 +++--- low-can-binding/can/message-definition.hpp | 8 ++++---- low-can-binding/can/message-set.cpp | 8 ++++---- low-can-binding/can/message-set.hpp | 14 +++++++++----- low-can-binding/utils/signals.cpp | 2 +- low-can-binding/utils/signals.hpp | 15 +++++++++------ 14 files changed, 61 insertions(+), 51 deletions(-) diff --git a/low-can-binding/binding/application.cpp b/low-can-binding/binding/application.cpp index d93bf0cf..d22633f9 100644 --- a/low-can-binding/binding/application.cpp +++ b/low-can-binding/binding/application.cpp @@ -57,17 +57,17 @@ std::vector > application_t::get_message_set() return message_set_; } -std::vector > application_t::get_all_signals() +vect_ptr_signal_t application_t::get_all_signals() { return message_set_[active_message_set_]->get_all_signals(); } -std::vector> application_t::get_diagnostic_messages() +vect_ptr_diag_msg_t application_t::get_diagnostic_messages() { return message_set_[active_message_set_]->get_diagnostic_messages(); } -std::vector> application_t::get_messages_definition() +vect_ptr_msg_def_t application_t::get_messages_definition() { return message_set_[active_message_set_]->get_messages_definition(); } @@ -76,7 +76,7 @@ std::vector> application_t::get_messages_d std::shared_ptr application_t::get_message_definition(uint32_t id) { std::shared_ptr ret = nullptr; - std::vector> messages_definition = get_messages_definition(); + vect_ptr_msg_def_t messages_definition = get_messages_definition(); for(std::shared_ptr &msg_def : messages_definition) { if(msg_def->get_id() == id) diff --git a/low-can-binding/binding/application.hpp b/low-can-binding/binding/application.hpp index 5045ddab..47a0e2f1 100644 --- a/low-can-binding/binding/application.hpp +++ b/low-can-binding/binding/application.hpp @@ -73,9 +73,9 @@ class application_t std::vector > get_message_set(); - std::vector > get_all_signals(); + vect_ptr_signal_t get_all_signals(); - std::vector > get_diagnostic_messages(); + vect_ptr_diag_msg_t get_diagnostic_messages(); const std::vector& get_signals_prefix() const; diff --git a/low-can-binding/binding/low-can-cb.cpp b/low-can-binding/binding/low-can-cb.cpp index 6c8a1ee0..5879b686 100644 --- a/low-can-binding/binding/low-can-cb.cpp +++ b/low-can-binding/binding/low-can-cb.cpp @@ -47,7 +47,7 @@ /// ///*******************************************************************************/ -void on_no_clients(std::shared_ptr can_subscription, uint32_t pid, std::map >& s) +void on_no_clients(std::shared_ptr can_subscription, uint32_t pid, map_subscription& s) { bool is_permanent_recurring_request = false; @@ -68,7 +68,7 @@ void on_no_clients(std::shared_ptr can_subscription, uin on_no_clients(can_subscription, s); } -void on_no_clients(std::shared_ptr can_subscription, std::map >& s) +void on_no_clients(std::shared_ptr can_subscription, map_subscription& s) { auto it = s.find(can_subscription->get_index()); s.erase(it); @@ -132,7 +132,7 @@ int read_message(sd_event_source *event_source, int fd, uint32_t revents, void * static int subscribe_unsubscribe_signal(afb_req_t request, bool subscribe, std::shared_ptr& can_subscription, - std::map >& s) + map_subscription& s) { int ret = 0; int sub_index = can_subscription->get_index(); @@ -194,9 +194,9 @@ static int add_to_event_loop(std::shared_ptr& can_subscr static int subscribe_unsubscribe_diagnostic_messages(afb_req_t request, bool subscribe, - std::list > diagnostic_messages, + list_ptr_diag_msg_t diagnostic_messages, struct event_filter_t& event_filter, - std::map >& s, + map_subscription& s, bool perm_rec_diag_req) { int rets = 0; @@ -259,9 +259,9 @@ static int subscribe_unsubscribe_diagnostic_messages(afb_req_t request, static int subscribe_unsubscribe_signals(afb_req_t request, bool subscribe, - std::list > signals, + list_ptr_signal_t signals, struct event_filter_t& event_filter, - std::map >& s) + map_subscription& s) { int rets = 0; for(const auto& sig: signals) @@ -309,7 +309,7 @@ static int subscribe_unsubscribe_signals(afb_req_t request, utils::signals_manager_t& sm = utils::signals_manager_t::instance(); std::lock_guard subscribed_signals_lock(sm.get_subscribed_signals_mutex()); - std::map >& s = sm.get_subscribed_signals(); + map_subscription& s = sm.get_subscribed_signals(); rets += subscribe_unsubscribe_diagnostic_messages(request, subscribe, signals.diagnostic_messages, event_filter, s, false); rets += subscribe_unsubscribe_signals(request, subscribe, signals.signals, event_filter, s); @@ -390,7 +390,7 @@ static int one_subscribe_unsubscribe_id(afb_req_t request, bool subscribe, const if(message_definition) { - sf.signals = std::list>(message_definition->get_signals().begin(),message_definition->get_signals().end()); + sf.signals = list_ptr_signal_t(message_definition->get_signals().begin(),message_definition->get_signals().end()); } if(sf.signals.empty()) @@ -956,14 +956,14 @@ int init_binding(afb_api_t api) struct event_filter_t event_filter; event_filter.frequency = sf.diagnostic_messages.front()->get_frequency(); - std::map >& s = sm.get_subscribed_signals(); + map_subscription& s = sm.get_subscribed_signals(); subscribe_unsubscribe_diagnostic_messages(request, true, sf.diagnostic_messages, event_filter, s, true); } #ifdef USE_FEATURE_J1939 - std::vector> current_messages_definition = application.get_messages_definition(); + vect_ptr_msg_def_t current_messages_definition = application.get_messages_definition(); for(std::shared_ptr message_definition: current_messages_definition) { if(message_definition->is_j1939()) diff --git a/low-can-binding/binding/low-can-hat.hpp b/low-can-binding/binding/low-can-hat.hpp index 1662ce04..131b61f2 100644 --- a/low-can-binding/binding/low-can-hat.hpp +++ b/low-can-binding/binding/low-can-hat.hpp @@ -29,8 +29,10 @@ class low_can_subscription_t; -void on_no_clients(std::shared_ptr can_subscription, std::map >& s); -void on_no_clients(std::shared_ptr can_subscription, uint32_t pid, std::map >& s); +typedef std::map> map_subscription; + +void on_no_clients(std::shared_ptr can_subscription, map_subscription& s); +void on_no_clients(std::shared_ptr can_subscription, uint32_t pid, map_subscription& s); int read_message(sd_event_source *s, int fd, uint32_t revents, void *userdata); inline bool caseInsCharCompareN(char a, char b) { diff --git a/low-can-binding/binding/low-can-subscription.cpp b/low-can-binding/binding/low-can-subscription.cpp index 6d02b101..9cc5fcbb 100644 --- a/low-can-binding/binding/low-can-subscription.cpp +++ b/low-can-binding/binding/low-can-subscription.cpp @@ -139,7 +139,7 @@ bool low_can_subscription_t::is_signal_subscription_corresponding(const std::sha return signal_ == signal && event_filter_ == event_filter; } -const std::vector > low_can_subscription_t::get_diagnostic_message() const +const vect_ptr_diag_msg_t low_can_subscription_t::get_diagnostic_message() const { return diagnostic_message_; } diff --git a/low-can-binding/binding/low-can-subscription.hpp b/low-can-binding/binding/low-can-subscription.hpp index 3f2c3acd..5abf8550 100644 --- a/low-can-binding/binding/low-can-subscription.hpp +++ b/low-can-binding/binding/low-can-subscription.hpp @@ -44,6 +44,7 @@ struct event_filter_t } }; + /// @brief The object stores socket to CAN to be used to write on it. /// This is a simple access to a CAN bus device without any subscriptions attached class low_can_subscription_t @@ -55,7 +56,7 @@ private: /// Signal part std::shared_ptr signal_; ///< signal_ - the CAN signal subscribed - std::vector > diagnostic_message_; ///< diagnostic_message_ - diagnostic messages meant to receive OBD2 + vect_ptr_diag_msg_t diagnostic_message_; ///< diagnostic_message_ - diagnostic messages meant to receive OBD2 /// responses. Normal diagnostic request and response are not tested for now. std::shared_ptr socket_; ///< socket_ - socket_ that receives CAN messages. @@ -79,7 +80,7 @@ public: const std::shared_ptr get_signal() const; bool is_signal_subscription_corresponding(const std::shared_ptr, const struct event_filter_t& event_filter) const; const std::shared_ptr get_diagnostic_message(uint32_t pid) const; - const std::vector > get_diagnostic_message() const; + const vect_ptr_diag_msg_t get_diagnostic_message() const; const std::shared_ptr get_diagnostic_message(const std::string& name) const; const std::string get_name() const; const std::string get_name(uint32_t pid) const; diff --git a/low-can-binding/can/can-bus.cpp b/low-can-binding/can/can-bus.cpp index 48ac697a..6cd99ba3 100644 --- a/low-can-binding/can/can-bus.cpp +++ b/low-can-binding/can/can-bus.cpp @@ -81,7 +81,7 @@ bool can_bus_t::apply_filter(const openxc_VehicleMessage& vehicle_message, std:: /// @param[in] can_message - a single CAN message from the CAN socket read, to be decode. /// /// @return How many signals has been decoded. -void can_bus_t::process_signals(std::shared_ptr message, std::map >& s) +void can_bus_t::process_signals(std::shared_ptr message, map_subscription& s) { int subscription_id = message->get_sub_id(); openxc_DynamicField decoded_message; @@ -114,7 +114,7 @@ void can_bus_t::process_signals(std::shared_ptr message, std::map message, std::map >& s) +void can_bus_t::process_diagnostic_signals(diagnostic_manager_t& manager, std::shared_ptr message, map_subscription& s) { int subscription_id = message->get_sub_id(); @@ -160,7 +160,7 @@ void can_bus_t::can_decode_message() { std::lock_guard subscribed_signals_lock(sm.get_subscribed_signals_mutex()); - std::map >& s = sm.get_subscribed_signals(); + map_subscription& s = sm.get_subscribed_signals(); if(application_t::instance().get_diagnostic_manager().is_diagnostic_response(message)) { process_diagnostic_signals(application_t::instance().get_diagnostic_manager(), message, s); @@ -192,7 +192,7 @@ void can_bus_t::can_event_push() decoded_can_message_lock.unlock(); { std::lock_guard subscribed_signals_lock(sm.get_subscribed_signals_mutex()); - std::map >& s = sm.get_subscribed_signals(); + map_subscription& s = sm.get_subscribed_signals(); if(s.find(v_message.first) != s.end() && afb_event_is_valid(s[v_message.first]->get_event())) { jo = json_object_new_object(); diff --git a/low-can-binding/can/can-bus.hpp b/low-can-binding/can/can-bus.hpp index 53e6b9ae..a9f6b0c1 100644 --- a/low-can-binding/can/can-bus.hpp +++ b/low-can-binding/can/can-bus.hpp @@ -46,8 +46,8 @@ private: utils::config_parser_t conf_file_; ///< configuration file handle used to initialize can_bus_dev_t objects. bool apply_filter(const openxc_VehicleMessage& vehicle_message, std::shared_ptr can_subscription); - void process_signals(std::shared_ptr message, std::map >& s); - void process_diagnostic_signals(diagnostic_manager_t& manager, std::shared_ptr can_message, std::map >& s); + void process_signals(std::shared_ptr message, map_subscription& s); + void process_diagnostic_signals(diagnostic_manager_t& manager, std::shared_ptr can_message, map_subscription& s); void can_decode_message(); std::thread th_decoding_; ///< thread that will handle decoding a can frame diff --git a/low-can-binding/can/message-definition.cpp b/low-can-binding/can/message-definition.cpp index a875dafa..ab7a884b 100644 --- a/low-can-binding/can/message-definition.cpp +++ b/low-can-binding/can/message-definition.cpp @@ -25,7 +25,7 @@ message_definition_t::message_definition_t( uint32_t flags, frequency_clock_t frequency_clock, bool force_send_changed, - const std::vector >& signals) + const vect_ptr_signal_t& signals) : parent_{nullptr}, bus_{bus}, id_{id}, @@ -43,7 +43,7 @@ message_definition_t::message_definition_t(const std::string bus, uint32_t flags, frequency_clock_t frequency_clock, bool force_send_changed, - const std::vector >& signals) + const vect_ptr_signal_t& signals) : parent_{nullptr}, bus_{bus}, id_{id}, @@ -82,7 +82,7 @@ bool message_definition_t::is_isotp() const return (flags_&ISOTP_PROTOCOL); } -std::vector>& message_definition_t::get_signals() +vect_ptr_signal_t& message_definition_t::get_signals() { return signals_; } diff --git a/low-can-binding/can/message-definition.hpp b/low-can-binding/can/message-definition.hpp index f46d3adb..cce42e14 100644 --- a/low-can-binding/can/message-definition.hpp +++ b/low-can-binding/can/message-definition.hpp @@ -54,7 +54,7 @@ private: std::vector last_value_; ///< last_value_ - The last received value of the message. Defaults to undefined. /// This is required for the forceSendChanged functionality, as the stack /// needs to compare an incoming CAN message with the previous frame.*/ - std::vector > signals_; ///< signals_ - Vector holding signal_t object which share the same arbitration ID */ + vect_ptr_signal_t signals_; ///< signals_ - Vector holding signal_t object which share the same arbitration ID */ public: //message_definition_t(const message_definition_t& b); @@ -66,7 +66,7 @@ public: uint32_t flags, frequency_clock_t frequency_clock, bool force_send_changed, - const std::vector >& signals); + const vect_ptr_signal_t& signals); message_definition_t(const std::string bus, uint32_t id, std::string name, @@ -74,7 +74,7 @@ public: uint32_t flags, frequency_clock_t frequency_clock, bool force_send_changed, - const std::vector >& signals); + const vect_ptr_signal_t& signals); const std::string get_bus_name() const; @@ -83,7 +83,7 @@ public: bool is_fd() const; bool is_j1939() const; bool is_isotp() const; - std::vector>& get_signals(); + vect_ptr_signal_t& get_signals(); uint32_t get_length() const; uint32_t get_flags() const; diff --git a/low-can-binding/can/message-set.cpp b/low-can-binding/can/message-set.cpp index 69682e1a..2fc300ac 100644 --- a/low-can-binding/can/message-set.cpp +++ b/low-can-binding/can/message-set.cpp @@ -24,7 +24,7 @@ message_set_t::message_set_t( uint8_t index, const std::string& name, const std::vector >& messages_definition, - const std::vector >& diagnostic_messages) + const vect_ptr_diag_msg_t& diagnostic_messages) : index_{index} , name_{name} , messages_definition_{messages_definition} @@ -32,14 +32,14 @@ message_set_t::message_set_t( {} /// @brief Returns a vector holding all message definitions which are handled by this message set. -std::vector>& message_set_t::get_messages_definition() +vect_ptr_msg_def_t& message_set_t::get_messages_definition() { return messages_definition_; } std::vector> message_set_t::get_all_signals() const { - std::vector > signals; + vect_ptr_signal_t signals; for(const auto& cmd: messages_definition_) { std::vector> cmd_signals = cmd->get_signals(); @@ -53,7 +53,7 @@ std::vector> message_set_t::get_all_signals() const } /// @brief Returns a vector holding all diagnostic message definitions which are handled by this message set. -std::vector>& message_set_t::get_diagnostic_messages() +vect_ptr_diag_msg_t& message_set_t::get_diagnostic_messages() { return diagnostic_messages_; } diff --git a/low-can-binding/can/message-set.hpp b/low-can-binding/can/message-set.hpp index 4af97fa6..d54f27ac 100644 --- a/low-can-binding/can/message-set.hpp +++ b/low-can-binding/can/message-set.hpp @@ -27,6 +27,10 @@ class signal_t; class message_definition_t; class diagnostic_message_t; +typedef std::vector> vect_ptr_signal_t; +typedef std::vector> vect_ptr_diag_msg_t; +typedef std::vector> vect_ptr_msg_def_t; + /// @brief A parent wrapper for a particular set of CAN messages and diagnostic messages /// (e.g. a vehicle or program). class message_set_t @@ -35,16 +39,16 @@ private: uint8_t index_; /// < A numerical ID for the message set, ideally the index is in an array for fast lookup const std::string name_; /// < The name of the message set. std::vector > messages_definition_; ///< Vector holding all message definitions handled by the message set. - std::vector > diagnostic_messages_; ///< Vector holding all diagnostics messages from JSON signals description file. First vector map to message set + vect_ptr_diag_msg_t diagnostic_messages_; ///< Vector holding all diagnostics messages from JSON signals description file. First vector map to message set public: message_set_t( uint8_t index, const std::string& name, const std::vector >& messages_definition, - const std::vector >& diagnostic_messages); + const vect_ptr_diag_msg_t& diagnostic_messages); - std::vector>& get_messages_definition(); - std::vector> get_all_signals() const; - std::vector>& get_diagnostic_messages(); + vect_ptr_msg_def_t& get_messages_definition(); + vect_ptr_signal_t get_all_signals() const; + vect_ptr_diag_msg_t& get_diagnostic_messages(); }; diff --git a/low-can-binding/utils/signals.cpp b/low-can-binding/utils/signals.cpp index 4895395f..a26906e0 100644 --- a/low-can-binding/utils/signals.cpp +++ b/low-can-binding/utils/signals.cpp @@ -39,7 +39,7 @@ namespace utils /// @brief return the subscribed_signals map. /// /// @return Map of subscribed signals. - std::map >& signals_manager_t::get_subscribed_signals() + map_subscription& signals_manager_t::get_subscribed_signals() { return subscribed_signals_; } diff --git a/low-can-binding/utils/signals.hpp b/low-can-binding/utils/signals.hpp index b28942e7..b7b2ca03 100644 --- a/low-can-binding/utils/signals.hpp +++ b/low-can-binding/utils/signals.hpp @@ -29,12 +29,15 @@ #include "../binding/low-can-subscription.hpp" +typedef std::list> list_ptr_signal_t; +typedef std::list> list_ptr_diag_msg_t; + namespace utils { struct signals_found { - std::list > signals; - std::list > diagnostic_messages; + list_ptr_signal_t signals; + list_ptr_diag_msg_t diagnostic_messages; }; /// @brief Signal manager singleton hold subscription object with attached afb_event_t and its mutex @@ -45,7 +48,7 @@ namespace utils { private: std::mutex subscribed_signals_mutex_; - std::map > subscribed_signals_; ///< Map containing all subscribed signals, key is the socket int value. + map_subscription subscribed_signals_; ///< Map containing all subscribed signals, key is the socket int value. signals_manager_t(); ///< Private constructor to make singleton class. @@ -53,11 +56,11 @@ namespace utils static signals_manager_t& instance(); std::mutex& get_subscribed_signals_mutex(); - std::map >& get_subscribed_signals(); + map_subscription& get_subscribed_signals(); struct signals_found find_signals(const openxc_DynamicField &key); - void find_diagnostic_messages(const openxc_DynamicField &key, std::vector >& found_signals); - void find_signals(const openxc_DynamicField &key, std::vector >& found_signals); + void find_diagnostic_messages(const openxc_DynamicField &key, vect_ptr_diag_msg_t& found_signals); + void find_signals(const openxc_DynamicField &key, vect_ptr_signal_t& found_signals); template void lookup_signals_by_name(const std::string& key, std::vector > signals, std::list >& found_signals) -- cgit 1.2.3-korg