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 <map>
6 
7 #include <json/json.h>
8 #include <boost/signals2.hpp>
9 
10 #include "uptane/tuf.h"
11 #include "utilities/types.h"
12 
13 /**
14  * Aktualizr status events.
15  */
16 namespace event {
17 
18 /**
19  * Base class for all event objects.
20  */
21 class BaseEvent {
22  public:
23  BaseEvent() = default;
24  BaseEvent(std::string variant_in) : variant(std::move(variant_in)) {}
25  virtual ~BaseEvent() = default;
26  std::string variant;
27  virtual std::string toJson(Json::Value json);
28  virtual std::string toJson();
29 };
30 
31 /**
32  * An error occurred processing a command.
33  */
34 class Error : public BaseEvent {
35  public:
36  std::string message;
37  explicit Error(std::string /*message_in*/);
38  std::string toJson() override;
39  static Error fromJson(const std::string& /*json_str*/);
40 };
41 
42 /**
43  * Metadata has been successfully fetched from the server.
44  */
45 class FetchMetaComplete : public BaseEvent {
46  public:
47  explicit FetchMetaComplete();
48 };
49 
50 /**
51  * Device data has been successfully sent to the server.
52  */
54  public:
55  explicit SendDeviceDataComplete();
56 };
57 
58 /**
59  * A manifest has been successfully sent to the server.
60  */
62  public:
63  explicit PutManifestComplete();
64 };
65 
66 /**
67  * An update is available for download from the server.
68  */
69 class UpdateAvailable : public BaseEvent {
70  public:
71  std::vector<Uptane::Target> updates;
72  unsigned int ecus_count;
73  explicit UpdateAvailable(std::vector<Uptane::Target> updates_in, unsigned int ecus_count_in);
74  std::string toJson() override;
75  static UpdateAvailable fromJson(const std::string& json_str);
76 };
77 
78 /**
79  * A report for a download in progress.
80  */
82  public:
83  Uptane::Target target;
84  std::string description;
85  unsigned int progress;
86  std::string toJson() override;
87 
88  explicit DownloadProgressReport(Uptane::Target target_in, std::string description_in, unsigned int progress_in);
89 };
90 
91 /**
92  * An update has been successfully downloaded.
93  */
94 class DownloadComplete : public BaseEvent {
95  public:
96  std::vector<Uptane::Target> updates;
97  std::string toJson() override;
98 
99  explicit DownloadComplete(std::vector<Uptane::Target> updates_in);
100  static DownloadComplete fromJson(const std::string& json_str);
101 };
102 
103 /**
104  * An ECU has begun installation of an update.
105  */
106 class InstallStarted : public BaseEvent {
107  public:
109  Uptane::EcuSerial serial;
110 };
111 
112 /**
113  * An update has been successfully installed on an ECU.
114  */
115 class InstallComplete : public BaseEvent {
116  public:
118  Uptane::EcuSerial serial;
119 };
120 
121 /**
122  * The server has been successfully queried for available campaigns.
123  */
125  public:
126  explicit CampaignCheckComplete();
127 };
128 
129 /**
130  * A campaign has been successfully accepted.
131  */
133  public:
134  explicit CampaignAcceptComplete();
135 };
136 
137 using Channel = boost::signals2::signal<void(std::shared_ptr<event::BaseEvent>)>;
138 
139 } // namespace event
140 
141 #endif
Device data has been successfully sent to the server.
Definition: events.h:53
A campaign has been successfully accepted.
Definition: events.h:132
A manifest has been successfully sent to the server.
Definition: events.h:61
The server has been successfully queried for available campaigns.
Definition: events.h:124
A report for a download in progress.
Definition: events.h:81
An ECU has begun installation of an update.
Definition: events.h:106
An update is available for download from the server.
Definition: events.h:69
An update has been successfully installed on an ECU.
Definition: events.h:115
An update has been successfully downloaded.
Definition: events.h:94
Metadata has been successfully fetched from the server.
Definition: events.h:45
An error occurred processing a command.
Definition: events.h:34
Aktualizr status events.
Definition: events.cc:4
Base class for all event objects.
Definition: events.h:21