summaryrefslogtreecommitdiffstats
path: root/CAN-binder/low-can-binding/utils/signals.hpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-04-21 18:20:42 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-04-21 18:20:42 +0200
commit20c0dec8fd46f14c95618b7baed16c3c828ad530 (patch)
tree96d22269b6c7841a7ba7884c144f0f1810e6d2f9 /CAN-binder/low-can-binding/utils/signals.hpp
parent4f3b7570bb8e4c6943116026cf42da04830f7243 (diff)
Move all signals search functions into new signals_manager_t object
Create a class from signals lookup and find standalone function and gather all find function into it. There is now only 1 function to find either CAN signals or diagnostic messages, results are returned using an ad-hoc struct containing vector of one or the other type pointers. This object also hold subscribed_signals map with events, so this class is a singleton. Change-Id: I3584c6a91201e6904edc6aeac0abfa1785bdeccc Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'CAN-binder/low-can-binding/utils/signals.hpp')
-rw-r--r--CAN-binder/low-can-binding/utils/signals.hpp91
1 files changed, 41 insertions, 50 deletions
diff --git a/CAN-binder/low-can-binding/utils/signals.hpp b/CAN-binder/low-can-binding/utils/signals.hpp
index e9417569..d2e9205c 100644
--- a/CAN-binder/low-can-binding/utils/signals.hpp
+++ b/CAN-binder/low-can-binding/utils/signals.hpp
@@ -28,63 +28,54 @@
#include "../low-can-binding.hpp"
-extern std::mutex subscribed_signals_mutex;
-std::mutex& get_subscribed_signals_mutex();
-
-/**
- * @brief return the subscribed_signals map.
- *
- * return Map of subscribed signals.
- */
-extern std::map<std::string, struct afb_event> subscribed_signals;
-std::map<std::string, struct afb_event>& get_subscribed_signals();
-
-template <typename T>
-void lookup_signals_by_name(const std::string& key, std::vector<T>& signals, std::vector<T*>& found_signals)
+namespace utils
{
- for(T& s : signals)
+ struct signals_found
{
- if(::fnmatch(key.c_str(), s.get_generic_name().c_str(), FNM_CASEFOLD) == 0)
- found_signals.push_back(&s);
- if(::fnmatch(key.c_str(), s.get_name().c_str(), FNM_CASEFOLD) == 0)
- found_signals.push_back(&s);
- }
-}
+ std::vector<can_signal_t*> can_signals;
+ std::vector<diagnostic_message_t*> diagnostic_messages;
+ };
-template <typename T>
-void lookup_signals_by_name(const std::string& key, std::vector<T>& signals, std::vector<std::string>& found_signals_name)
-{
- for(T& s : signals)
+ class signals_manager_t
{
- if(::fnmatch(key.c_str(), s.get_generic_name().c_str(), FNM_CASEFOLD) == 0)
- found_signals_name.push_back(s.get_name());
- if(::fnmatch(key.c_str(), s.get_name().c_str(), FNM_CASEFOLD) == 0)
- found_signals_name.push_back(s.get_name());
- }
-}
+ private:
+ std::mutex subscribed_signals_mutex_;
+ std::map<std::string, struct afb_event> subscribed_signals_;
-template <typename T>
-void lookup_signals_by_id(const double key, std::vector<T>& signals, std::vector<T*>& found_signals)
-{
- for(T& s : signals)
- {
- if(configuration_t::instance().get_signal_id(s) == key)
+ signals_manager_t(); ///< Private constructor to make singleton class.
+
+ public:
+ static signals_manager_t& instance();
+
+ std::mutex& get_subscribed_signals_mutex();
+ std::map<std::string, struct afb_event>& get_subscribed_signals();
+
+ struct signals_found find_signals(const openxc_DynamicField &key);
+ void find_diagnostic_messages(const openxc_DynamicField &key, std::vector<diagnostic_message_t*>& found_signals);
+ void find_can_signals(const openxc_DynamicField &key, std::vector<can_signal_t*>& found_signals);
+
+ template <typename T>
+ void lookup_signals_by_name(const std::string& key, std::vector<T>& signals, std::vector<T*>& found_signals)
{
- found_signals.push_back(&s);
+ for(T& s : signals)
+ {
+ if(::fnmatch(key.c_str(), s.get_generic_name().c_str(), FNM_CASEFOLD) == 0)
+ found_signals.push_back(&s);
+ if(::fnmatch(key.c_str(), s.get_name().c_str(), FNM_CASEFOLD) == 0)
+ found_signals.push_back(&s);
+ }
}
- }
-}
-template <typename T>
-void lookup_signals_by_id(const double key, std::vector<T>& signals, std::vector<std::string>& found_signals_name)
-{
- for(T& s : signals)
- {
- if(configuration_t::instance().get_signal_id(s) == key)
+ template <typename T>
+ void lookup_signals_by_id(const double key, std::vector<T>& signals, std::vector<T*>& found_signals)
{
- found_signals_name.push_back(s.get_name());
+ for(T& s : signals)
+ {
+ if(configuration_t::instance().get_signal_id(s) == key)
+ {
+ found_signals.push_back(&s);
+ }
+ }
}
- }
-}
-
-std::vector<std::string> find_signals(const openxc_DynamicField &key);
+ };
+} \ No newline at end of file