8 struct tm time_struct {};
10 gmtime_r(&raw_time, &time_struct);
12 strftime(formatted, 22,
"%Y-%m-%dT%H:%M:%SZ", &time_struct);
17 if (rfc3339.length() != 20 || rfc3339[19] !=
'Z') {
23 bool TimeStamp::IsValid()
const {
return time_.length() != 0; }
25 bool TimeStamp::IsExpiredAt(
const TimeStamp &now)
const {
35 bool TimeStamp::operator<(
const TimeStamp &other)
const {
return IsValid() && other.IsValid() && time_ < other.time_; }
37 bool TimeStamp::operator>(
const TimeStamp &other)
const {
return (other < *
this); }
39 std::ostream &operator<<(std::ostream &os,
const TimeStamp &t) {
45 Json::Value Package::toJson() {
48 json[
"version"] = version;
52 Package Package::fromJson(
const std::string &json_str) {
55 reader.parse(json_str, json);
57 package.name = json[
"name"].asString();
58 package.version = json[
"version"].asString();
62 OperationResult::OperationResult(std::string id_in,
UpdateResultCode result_code_in, std::string result_text_in)
63 : id(std::move(id_in)), result_code(result_code_in), result_text(std::move(result_text_in)) {}
65 OperationResult::OperationResult(std::string id_in, InstallOutcome outcome_in)
66 : id(std::move(id_in)), result_code(outcome_in.first), result_text(outcome_in.second) {}
68 InstallOutcome OperationResult::toOutcome()
const {
return InstallOutcome(result_code, result_text); }
70 Json::Value OperationResult::toJson()
const {
73 json[
"result_code"] =
static_cast<int>(result_code);
74 json[
"result_text"] = result_text;
78 OperationResult OperationResult::fromJson(
const std::string &json_str) {
81 reader.parse(json_str, json);
83 operation_result.id = json[
"id"].asString();
84 operation_result.result_code =
static_cast<UpdateResultCode>(json[
"result_code"].asUInt());
85 operation_result.result_text = json[
"result_text"].asString();
86 return operation_result;
89 OperationResult OperationResult::fromOutcome(
const std::string &
id,
const InstallOutcome &outcome) {
91 return operation_result;
96 RunningMode RunningModeFromString(
const std::string &mode) {
97 if (mode ==
"full" || mode.empty()) {
99 }
else if (mode ==
"once") {
101 }
else if (mode ==
"check") {
103 }
else if (mode ==
"download") {
105 }
else if (mode ==
"install") {
107 }
else if (mode ==
"campaign_check") {
109 }
else if (mode ==
"campaign_accept") {
112 throw std::runtime_error(std::string(
"Incorrect running mode: ") + mode);
116 std::string StringFromRunningMode(
RunningMode mode) {
117 std::string mode_str =
"full";
125 mode_str =
"download";
127 mode_str =
"install";
129 return "campaign_check";
131 return "campaign_accept";
Only accept an existing campaign.
Download any available updates and then shut down.
TimeStamp()
An invalid TimeStamp.
RunningMode
Execution mode to run aktualizr in.
Only check for an existing campaign related to the device.
UpdateResultCode
Result of an update.
Install any available updates and then shut down.