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