1 #include "libaktualizr/config.h"
2 #include "utilities/config_utils.h"
4 std::ostream& operator<<(std::ostream& os, RollbackMode mode) {
7 case RollbackMode::kUbootGeneric:
8 mode_s =
"uboot_generic";
10 case RollbackMode::kUbootMasked:
11 mode_s =
"uboot_masked";
17 os <<
'"' << mode_s <<
'"';
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;
31 dest = RollbackMode::kBootloaderNone;
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);
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");