diff --git a/cereal b/cereal index 736a4cce2c..fa580de1b4 160000 --- a/cereal +++ b/cereal @@ -1 +1 @@ -Subproject commit 736a4cce2c51cb73465e88dae6ff4cec5b9c3b43 +Subproject commit fa580de1b42534d3417306c416784e1add99ad32 diff --git a/common/util.cc b/common/util.cc index 6ad619c35c..11e8ad4555 100644 --- a/common/util.cc +++ b/common/util.cc @@ -253,6 +253,14 @@ std::string dir_name(std::string const &path) { return path.substr(0, pos); } +bool starts_with(const std::string &s1, const std::string &s2) { + return strncmp(s1.c_str(), s2.c_str(), s2.size()) == 0; +} + +bool ends_with(const std::string &s1, const std::string &s2) { + return strcmp(s1.c_str() + (s1.size() - s2.size()), s2.c_str()) == 0; +} + std::string check_output(const std::string& command) { char buffer[128]; std::string result; diff --git a/common/util.h b/common/util.h index 23c37f153a..26bc15ba33 100644 --- a/common/util.h +++ b/common/util.h @@ -77,6 +77,8 @@ float getenv(const char* key, float default_val); std::string hexdump(const uint8_t* in, const size_t size); std::string dir_name(std::string const& path); +bool starts_with(const std::string &s1, const std::string &s2); +bool ends_with(const std::string &s1, const std::string &s2); // ***** random helpers ***** int random_int(int min, int max); diff --git a/system/loggerd/loggerd.cc b/system/loggerd/loggerd.cc index 303235e9d8..2bcf9e3256 100644 --- a/system/loggerd/loggerd.cc +++ b/system/loggerd/loggerd.cc @@ -207,11 +207,11 @@ void loggerd_thread() { std::unique_ptr poller(Poller::create()); // subscribe to all socks - for (const auto& it : services) { - const bool encoder = strcmp(it.name+strlen(it.name)-strlen("EncodeData"), "EncodeData") == 0; - const bool livestream_encoder = strncmp(it.name, "livestream", strlen("livestream")) == 0; + for (const auto& [_, it] : services) { + const bool encoder = util::ends_with(it.name, "EncodeData"); + const bool livestream_encoder = util::starts_with(it.name, "livestream"); if (!it.should_log && (!encoder || livestream_encoder)) continue; - LOGD("logging %s (on port %d)", it.name, it.port); + LOGD("logging %s (on port %d)", it.name.c_str(), it.port); SubSocket * sock = SubSocket::create(ctx.get(), it.name); assert(sock != NULL); @@ -221,7 +221,7 @@ void loggerd_thread() { .counter = 0, .freq = it.decimation, .encoder = encoder, - .user_flag = (strcmp(it.name, "userFlag") == 0), + .user_flag = it.name == "userFlag", }; } diff --git a/tools/replay/replay.cc b/tools/replay/replay.cc index 9029213af5..e323a9f64d 100644 --- a/tools/replay/replay.cc +++ b/tools/replay/replay.cc @@ -16,19 +16,20 @@ Replay::Replay(QString route, QStringList allow, QStringList block, QStringList auto event_struct = capnp::Schema::from().asStruct(); sockets_.resize(event_struct.getUnionFields().size()); for (const auto &it : services) { - uint16_t which = event_struct.getFieldByName(it.name).getProto().getDiscriminantValue(); + auto name = it.second.name.c_str(); + uint16_t which = event_struct.getFieldByName(name).getProto().getDiscriminantValue(); if ((which == cereal::Event::Which::UI_DEBUG || which == cereal::Event::Which::USER_FLAG) && !(flags & REPLAY_FLAG_ALL_SERVICES) && - !allow.contains(it.name)) { + !allow.contains(name)) { continue; } - if ((allow.empty() || allow.contains(it.name)) && !block.contains(it.name)) { - sockets_[which] = it.name; + if ((allow.empty() || allow.contains(name)) && !block.contains(name)) { + sockets_[which] = name; if (!allow.empty() || !block.empty()) { allow_list.insert((cereal::Event::Which)which); } - s.push_back(it.name); + s.push_back(name); } }