From 3b752a307f167ad536eb53cceac76f7034f2faf9 Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Sat, 21 Aug 2021 07:57:45 +0800 Subject: [PATCH] params: remove persistent params (#21975) * cleanup constructors * remove persistent_param * remove test_persist_params_put_and_get --- common/params_pxd.pxd | 2 +- common/params_pyx.pyx | 4 ++-- common/tests/test_params.py | 5 ----- selfdrive/common/params.cc | 12 +++++------- selfdrive/common/params.h | 8 ++++---- selfdrive/hardware/hw.h | 3 --- 6 files changed, 12 insertions(+), 22 deletions(-) diff --git a/common/params_pxd.pxd b/common/params_pxd.pxd index 489e064dc..ecf520041 100644 --- a/common/params_pxd.pxd +++ b/common/params_pxd.pxd @@ -17,7 +17,7 @@ cdef extern from "selfdrive/common/params.h": ALL cdef cppclass Params: - Params(bool) nogil + Params() nogil Params(string) nogil string get(string, bool) nogil bool getBool(string) nogil diff --git a/common/params_pyx.pyx b/common/params_pyx.pyx index 4a238a7d4..198c69068 100755 --- a/common/params_pyx.pyx +++ b/common/params_pyx.pyx @@ -30,11 +30,11 @@ class UnknownKeyName(Exception): cdef class Params: cdef c_Params* p - def __cinit__(self, d=None, bool persistent_params=False): + def __cinit__(self, d=None): cdef string path if d is None: with nogil: - self.p = new c_Params(persistent_params) + self.p = new c_Params() else: path = d.encode() with nogil: diff --git a/common/tests/test_params.py b/common/tests/test_params.py index ca9136930..36bb6d96b 100644 --- a/common/tests/test_params.py +++ b/common/tests/test_params.py @@ -21,11 +21,6 @@ class TestParams(unittest.TestCase): self.params.put("DongleId", "cb38263377b873ee") assert self.params.get("DongleId") == b"cb38263377b873ee" - def test_persist_params_put_and_get(self): - p = Params(persistent_params=True) - p.put("DongleId", "cb38263377b873ee") - assert p.get("DongleId") == b"cb38263377b873ee" - def test_params_non_ascii(self): st = b"\xe1\x90\xff" self.params.put("CarParams", st) diff --git a/selfdrive/common/params.cc b/selfdrive/common/params.cc index 013c1b485..cada3b8ad 100644 --- a/selfdrive/common/params.cc +++ b/selfdrive/common/params.cc @@ -228,15 +228,13 @@ std::unordered_map keys = { } // namespace -Params::Params(bool persistent_param) : Params(persistent_param ? Path::persistent_params() : Path::params()) {} +Params::Params() : params_path(Path::params()) { + static std::once_flag once_flag; + std::call_once(once_flag, ensure_params_path, params_path); +} -std::once_flag default_params_path_ensured; Params::Params(const std::string &path) : params_path(path) { - if (path == Path::params()) { - std::call_once(default_params_path_ensured, ensure_params_path, path); - } else { - ensure_params_path(path); - } + ensure_params_path(params_path); } bool Params::checkKey(const std::string &key) { diff --git a/selfdrive/common/params.h b/selfdrive/common/params.h index 07c046180..c83d652b6 100644 --- a/selfdrive/common/params.h +++ b/selfdrive/common/params.h @@ -17,11 +17,8 @@ enum ParamKeyType { }; class Params { -private: - std::string params_path; - public: - Params(bool persistent_param = false); + Params(); Params(const std::string &path); bool checkKey(const std::string &key); @@ -78,4 +75,7 @@ public: inline int putBool(const std::string &key, bool val) { return putBool(key.c_str(), val); } + +private: + const std::string params_path; }; diff --git a/selfdrive/hardware/hw.h b/selfdrive/hardware/hw.h index b88882d70..400b1816f 100644 --- a/selfdrive/hardware/hw.h +++ b/selfdrive/hardware/hw.h @@ -29,9 +29,6 @@ inline std::string log_root() { inline std::string params() { return Hardware::PC() ? HOME + "/.comma/params" : "/data/params"; } -inline std::string persistent_params() { - return Hardware::PC() ? HOME + "/.comma/params" : "/persist/comma/params"; -} inline std::string rsa_file() { return Hardware::PC() ? HOME + "/.comma/persist/comma/id_rsa" : "/persist/comma/id_rsa"; }