Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
events.h
Go to the documentation of this file.
1 #ifndef EVENTS_H_
2 #define EVENTS_H_
3 /** \file */
4 
5 #include <memory>
6 #include <string>
7 
8 #include <boost/signals2.hpp>
9 
10 #include "primary/results.h"
11 #include "uptane/fetcher.h"
12 #include "uptane/tuf.h"
13 #include "utilities/types.h"
14 
15 /**
16  * Aktualizr status events.
17  */
18 namespace event {
19 
20 /**
21  * Base class for all event objects.
22  */
23 class BaseEvent {
24  public:
25  BaseEvent() = default;
26  BaseEvent(std::string variant_in) : variant(std::move(variant_in)) {}
27  virtual ~BaseEvent() = default;
28 
29  template <typename T>
30  bool isTypeOf() {
31  return variant == T::TypeName;
32  }
33 
34  std::string variant;
35 };
36 
37 /**
38  * Device data has been sent to the server.
39  */
41  public:
42  static constexpr const char* TypeName{"SendDeviceDataComplete"};
43 
44  SendDeviceDataComplete() { variant = TypeName; }
45 };
46 
47 /**
48  * A manifest has been sent to the server.
49  */
51  public:
52  static constexpr const char* TypeName{"PutManifestComplete"};
53  explicit PutManifestComplete(bool success_in) : success(success_in) { variant = TypeName; }
54  bool success;
55 };
56 
57 /**
58  * An update is available for download from the server.
59  */
61  public:
62  static constexpr const char* TypeName{"UpdateCheckComplete"};
63  explicit UpdateCheckComplete(result::UpdateCheck result_in) : result(std::move(result_in)) { variant = TypeName; }
64 
66 };
67 
68 /**
69  * A report for a download in progress.
70  */
72  public:
73  static constexpr const char* TypeName{"DownloadProgressReport"};
74 
75  static bool isDownloadCompleted(const DownloadProgressReport& report) {
76  return (report.progress == DownloadProgressReport::ProgressCompletedValue);
77  }
78 
79  public:
80  DownloadProgressReport(Uptane::Target target_in, std::string description_in, unsigned int progress_in)
81  : target{std::move(target_in)}, description{std::move(description_in)}, progress{progress_in} {
82  variant = TypeName;
83  }
84 
85  Uptane::Target target;
86  std::string description;
87  unsigned int progress;
88 
89  private:
90  static const unsigned int ProgressCompletedValue{100};
91 };
92 
93 /**
94  * A target has been downloaded.
95  */
97  public:
98  static constexpr const char* TypeName{"DownloadTargetComplete"};
99 
100  DownloadTargetComplete(Uptane::Target update_in, bool success_in)
101  : update(std::move(update_in)), success(success_in) {
102  variant = TypeName;
103  }
104 
105  Uptane::Target update;
106  bool success;
107 };
108 
109 /**
110  * All targets for an update have been downloaded.
111  */
113  public:
114  static constexpr const char* TypeName{"AllDownloadsComplete"};
115 
116  explicit AllDownloadsComplete(result::Download result_in) : result(std::move(result_in)) { variant = TypeName; }
117 
119 };
120 
121 /**
122  * An ECU has begun installation of an update.
123  */
124 class InstallStarted : public BaseEvent {
125  public:
126  static constexpr const char* TypeName{"InstallStarted"};
127 
128  explicit InstallStarted(Uptane::EcuSerial serial_in) : serial(std::move(serial_in)) { variant = TypeName; }
129  Uptane::EcuSerial serial;
130 };
131 
132 /**
133  * An installation attempt on an ECU has completed.
134  */
136  public:
137  static constexpr const char* TypeName{"InstallTargetComplete"};
138 
139  InstallTargetComplete(Uptane::EcuSerial serial_in, bool success_in)
140  : serial(std::move(serial_in)), success(success_in) {
141  variant = TypeName;
142  }
143 
144  Uptane::EcuSerial serial;
145  bool success;
146 };
147 
148 /**
149  * All ECU installation attempts for an update have completed.
150  */
152  public:
153  static constexpr const char* TypeName{"AllInstallsComplete"};
154 
155  explicit AllInstallsComplete(result::Install result_in) : result(std::move(result_in)) { variant = TypeName; }
156 
158 };
159 
160 /**
161  * The server has been queried for available campaigns.
162  */
164  public:
165  static constexpr const char* TypeName{"CampaignCheckComplete"};
166 
167  explicit CampaignCheckComplete(result::CampaignCheck result_in) : result(std::move(result_in)) { variant = TypeName; }
168 
170 };
171 
172 /**
173  * A campaign has been accepted.
174  */
176  public:
177  static constexpr const char* TypeName{"CampaignAcceptComplete"};
178 
179  CampaignAcceptComplete() { variant = TypeName; }
180 };
181 
183  public:
184  static constexpr const char* TypeName{"CampaignDeclineComplete"};
185 
186  CampaignDeclineComplete() { variant = TypeName; }
187 };
188 
190  public:
191  static constexpr const char* TypeName{"CampaignPostponeComplete"};
192 
193  CampaignPostponeComplete() { variant = TypeName; }
194 };
195 
196 using Channel = boost::signals2::signal<void(std::shared_ptr<event::BaseEvent>)>;
197 
198 } // namespace event
199 
200 #endif // EVENTS_H_
results.h
event::AllDownloadsComplete
All targets for an update have been downloaded.
Definition: events.h:112
types.h
event::UpdateCheckComplete
An update is available for download from the server.
Definition: events.h:60
event::CampaignDeclineComplete
Definition: events.h:182
event::DownloadTargetComplete
A target has been downloaded.
Definition: events.h:96
event::AllInstallsComplete
All ECU installation attempts for an update have completed.
Definition: events.h:151
result::UpdateCheck
Container for information about available updates.
Definition: results.h:38
event::SendDeviceDataComplete
Device data has been sent to the server.
Definition: events.h:40
event::InstallTargetComplete
An installation attempt on an ECU has completed.
Definition: events.h:135
Uptane::EcuSerial
Definition: tuf.h:174
event::CampaignPostponeComplete
Definition: events.h:189
result::Download
Container for information about downloading an update.
Definition: results.h:117
event::CampaignAcceptComplete
A campaign has been accepted.
Definition: events.h:175
event::BaseEvent
Base class for all event objects.
Definition: events.h:23
result
Results of libaktualizr API calls.
Definition: results.h:13
event::PutManifestComplete
A manifest has been sent to the server.
Definition: events.h:50
result::Install
Container for information about installing an update.
Definition: results.h:130
event::InstallStarted
An ECU has begun installation of an update.
Definition: events.h:124
event::DownloadProgressReport
A report for a download in progress.
Definition: events.h:71
Uptane::Target
Definition: tuf.h:238
result::CampaignCheck
Container for information about available campaigns.
Definition: results.h:17
event::CampaignCheckComplete
The server has been queried for available campaigns.
Definition: events.h:163
event
Aktualizr status events.
Definition: events.h:18