Aktualizr
C++ SOTA Client
bootloader_config.cc
1 #include "libaktualizr/config.h"
2 #include "utilities/config_utils.h"
3 
4 std::ostream& operator<<(std::ostream& os, RollbackMode mode) {
5  std::string mode_s;
6  switch (mode) {
7  case RollbackMode::kUbootGeneric:
8  mode_s = "uboot_generic";
9  break;
10  case RollbackMode::kUbootMasked:
11  mode_s = "uboot_masked";
12  break;
13  default:
14  mode_s = "none";
15  break;
16  }
17  os << '"' << mode_s << '"';
18  return os;
19 }
20 
21 template <>
22 inline void CopyFromConfig(RollbackMode& dest, const std::string& option_name, const boost::property_tree::ptree& pt) {
23  boost::optional<std::string> value = pt.get_optional<std::string>(option_name);
24  if (value.is_initialized()) {
25  std::string mode{StripQuotesFromStrings(value.get())};
26  if (mode == "uboot_generic") {
27  dest = RollbackMode::kUbootGeneric;
28  } else if (mode == "uboot_masked") {
29  dest = RollbackMode::kUbootMasked;
30  } else {
31  dest = RollbackMode::kBootloaderNone;
32  }
33  }
34 }
35 
36 void BootloaderConfig::updateFromPropertyTree(const boost::property_tree::ptree& pt) {
37  CopyFromConfig(rollback_mode, "rollback_mode", pt);
38  CopyFromConfig(reboot_sentinel_dir, "reboot_sentinel_dir", pt);
39  CopyFromConfig(reboot_sentinel_name, "reboot_sentinel_name", pt);
40  CopyFromConfig(reboot_command, "reboot_command", pt);
41 }
42 
43 void BootloaderConfig::writeToStream(std::ostream& out_stream) const {
44  writeOption(out_stream, rollback_mode, "rollback_mode");
45  writeOption(out_stream, reboot_sentinel_dir, "reboot_sentinel_dir");
46  writeOption(out_stream, reboot_sentinel_name, "reboot_sentinel_name");
47  writeOption(out_stream, reboot_command, "reboot_command");
48 }