apphandler: Add storage for Get/Set System Info Parameter
All but one standard System Info Parameter and most (all?) OEM
parameters are string type. Add a interface to connect string callbacks
to System Info Parameter selector codes. Also add a convenience call
that can connect a static string to a parameter selector code.
Change-Id: I5e35d0418b8ddf5b2575fac093acfc7d7ca2217c
Signed-off-by: Xo Wang <xow@google.com>
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/sys_info_param.cpp b/sys_info_param.cpp
new file mode 100644
index 0000000..c9bee32
--- /dev/null
+++ b/sys_info_param.cpp
@@ -0,0 +1,33 @@
+#include "sys_info_param.hpp"
+
+std::tuple<bool, std::string>
+ SysInfoParamStore::lookup(uint8_t paramSelector) const
+{
+ const auto iterator = params.find(paramSelector);
+ if (iterator == params.end())
+ {
+ return std::make_tuple(false, "");
+ }
+
+ auto& callback = iterator->second;
+ auto s = callback();
+ return std::make_tuple(true, s);
+}
+
+void SysInfoParamStore::update(uint8_t paramSelector, const std::string& s)
+{
+ // Add a callback that captures a copy of the string passed and returns it
+ // when invoked.
+
+ // clang-format off
+ update(paramSelector, [s]() {
+ return s;
+ });
+ // clang-format on
+}
+
+void SysInfoParamStore::update(uint8_t paramSelector,
+ const std::function<std::string()>& callback)
+{
+ params[paramSelector] = callback;
+}