Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
results.h
Go to the documentation of this file.
1 #ifndef RESULTS_H_
2 #define RESULTS_H_
3 /** \file */
4 
5 #include <string>
6 #include <vector>
7 
8 #include "campaign/campaign.h"
9 #include "uptane/fetcher.h"
10 #include "uptane/tuf.h"
11 
12 /** Results of libaktualizr API calls. */
13 namespace result {
14 /**
15  * Container for information about available campaigns.
16  */
18  public:
19  explicit CampaignCheck(std::vector<campaign::Campaign> campaigns_in) : campaigns(std::move(campaigns_in)) {}
20  std::vector<campaign::Campaign> campaigns;
21 };
22 
23 /**
24  * Status of an update.
25  */
26 enum class UpdateStatus {
27  /* Updates are available for ECUs known to aktualizr. */
28  kUpdatesAvailable = 0,
29  /* No updates are available for ECUs known to aktualizr. */
30  kNoUpdatesAvailable,
31  /* There was an error checking for updates. */
32  kError,
33 };
34 
35 /**
36  * Container for information about available updates.
37  */
38 class UpdateCheck {
39  public:
40  UpdateCheck() = default;
41  UpdateCheck(std::vector<Uptane::Target> updates_in, unsigned int ecus_count_in, UpdateStatus status_in,
42  Json::Value targets_meta_in, std::string message_in)
43  : updates(std::move(updates_in)),
44  ecus_count(ecus_count_in),
45  status(status_in),
46  targets_meta(std::move(targets_meta_in)),
47  message(std::move(message_in)) {}
48  std::vector<Uptane::Target> updates;
49  unsigned int ecus_count{0};
50  UpdateStatus status{UpdateStatus::kNoUpdatesAvailable};
51  Json::Value targets_meta;
52  std::string message;
53 };
54 
55 /**
56  * Result of an attempt to pause or resume a download.
57  */
58 enum class PauseStatus {
59  /* The system was successfully paused or resumed */
60  kSuccess = 0,
61  /* The system was already paused */
62  kAlreadyPaused,
63  /* The system was already running */
64  kAlreadyRunning,
65  /* General error */
66  kError,
67 };
68 
69 class Pause {
70  public:
71  Pause() = default;
72  Pause(PauseStatus status_in) : status(status_in) {}
73 
74  PauseStatus status{PauseStatus::kSuccess};
75 };
76 
77 /**
78  * Status of an update download.
79  */
80 enum class DownloadStatus {
81  /* Update was downloaded successfully. */
82  kSuccess = 0,
83  /* Some targets in the update were downloaded successfully, but some were not. */
84  kPartialSuccess,
85  /* There are no targets to download for this update. */
86  kNothingToDownload,
87  /* There was an error downloading targets. */
88  kError,
89 };
90 
91 inline std::ostream& operator<<(std::ostream& os, const DownloadStatus stat) {
92  std::string stat_str;
93  switch (stat) {
94  case DownloadStatus::kSuccess:
95  stat_str = "Success";
96  break;
97  case DownloadStatus::kPartialSuccess:
98  stat_str = "Partial success";
99  break;
100  case DownloadStatus::kNothingToDownload:
101  stat_str = "Nothing to download";
102  break;
103  case DownloadStatus::kError:
104  stat_str = "Error";
105  break;
106  default:
107  stat_str = "unknown";
108  break;
109  }
110  os << '"' << stat_str << '"';
111  return os;
112 }
113 
114 /**
115  * Container for information about downloading an update.
116  */
117 class Download {
118  public:
119  Download() = default;
120  Download(std::vector<Uptane::Target> updates_in, DownloadStatus status_in, std::string message_in)
121  : updates(std::move(updates_in)), status(status_in), message(std::move(message_in)) {}
122  std::vector<Uptane::Target> updates;
123  DownloadStatus status{DownloadStatus::kNothingToDownload};
124  std::string message;
125 };
126 
127 /**
128  * Container for information about installing an update.
129  */
130 class Install {
131  public:
132  Install() = default;
133  class EcuReport;
134  Install(data::InstallationResult dev_report_in, std::vector<EcuReport> ecu_reports_in, std::string raw_report_in = "")
135  : dev_report(std::move(dev_report_in)),
136  ecu_reports(std::move(ecu_reports_in)),
137  raw_report(std::move(raw_report_in)) {}
138 
139  data::InstallationResult dev_report{false, data::ResultCode::Numeric::kUnknown, ""};
140  std::vector<EcuReport> ecu_reports;
141  std::string raw_report;
142 
143  class EcuReport {
144  public:
145  EcuReport(Uptane::Target update_in, Uptane::EcuSerial serial_in, data::InstallationResult install_res_in)
146  : update(std::move(update_in)), serial(std::move(serial_in)), install_res(std::move(install_res_in)) {}
147 
148  Uptane::Target update;
149  Uptane::EcuSerial serial;
150  data::InstallationResult install_res;
151  };
152 };
153 
154 } // namespace result
155 
156 #endif // RESULTS_H_
DownloadStatus
Status of an update download.
Definition: results.h:80
Container for information about downloading an update.
Definition: results.h:117
Container for information about available campaigns.
Definition: results.h:17
UpdateStatus
Status of an update.
Definition: results.h:26
PauseStatus
Result of an attempt to pause or resume a download.
Definition: results.h:58
Container for information about installing an update.
Definition: results.h:130
Container for information about available updates.
Definition: results.h:38
Results of libaktualizr API calls.
Definition: results.h:13