diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-03-13 09:45:01 +0100 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-03-16 17:15:55 +0100 |
commit | b606db2b74d5c92d33a126071062c9eb2a548beb (patch) | |
tree | 26e0edc377c35521bba345a5f162809894751376 /src/diagnostic/diagnostic-message.cpp | |
parent | 37bf83a16cbd07b168b8c4f5a2c05cbf281d8fad (diff) |
Change the way to check signal type making prefix_
attribute as static with a static class method which
will check that the beginning of string argument
matches the prefix.
Change-Id: Idb129c7179391da61447996560957b2791aa9383
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src/diagnostic/diagnostic-message.cpp')
-rw-r--r-- | src/diagnostic/diagnostic-message.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/diagnostic/diagnostic-message.cpp b/src/diagnostic/diagnostic-message.cpp index c9035eb0..8b2273ef 100644 --- a/src/diagnostic/diagnostic-message.cpp +++ b/src/diagnostic/diagnostic-message.cpp @@ -33,6 +33,8 @@ const char *UNIT_NAMES[10] = { "NM" }; +std::string obd2_signal_t::prefix_ = "diagnostic_messages."; + obd2_signal_t::obd2_signal_t(uint8_t pid, const char* generic_name, const int min, const int max, enum UNIT unit, int frequency, bool supported) : pid_{pid}, generic_name_{generic_name}, min_{min}, max_{max}, unit_{unit}, frequency_{frequency}, supported_{supported} { @@ -53,7 +55,7 @@ const std::string obd2_signal_t::get_name() const return prefix_ + "." + generic_name_; } -const std::string& obd2_signal_t::get_prefix() const +const std::string& obd2_signal_t::get_prefix() { return prefix_; } @@ -63,7 +65,7 @@ int obd2_signal_t::get_frequency() const return frequency_; } -void obd2_signal_t::set_prefix(std::string val) +void obd2_signal_t::set_prefix(const std::string& val) { prefix_ = val; } @@ -144,9 +146,9 @@ bool obd2_signal_t::is_obd2_request(DiagnosticRequest* request) * * @return true if name began with obd2 else false. */ -bool obd2_signal_t::is_obd2_signal(const char *name) +bool obd2_signal_t::is_obd2_signal(const std::string& name) { - if(fnmatch("obd2.*", name, FNM_CASEFOLD) == 0) + if(name.find_first_of(prefix_.c_str(), 0, prefix_.size())) return true; return false; } |