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