Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
campaign.h
1 #ifndef CAMPAIGN_CAMPAIGN_H_
2 #define CAMPAIGN_CAMPAIGN_H_
3 
4 #include <string>
5 #include <vector>
6 #include "http/httpclient.h"
7 #include "utilities/utils.h"
8 
9 namespace campaign {
10 
11 constexpr int64_t kMaxCampaignsMetaSize = 1024 * 1024;
12 
13 class CampaignParseError : std::exception {
14  public:
15  const char *what() const noexcept override { return "Could not parse Campaign metadata"; }
16 };
17 
18 //! @cond Doxygen_Suppress
19 // Annoying bug in doxygen 1.8.13
20 // Looks like it's fixed in later versions: https://sourceforge.net/p/doxygen/mailman/message/35481387/
21 enum class Cmd {
22  Accept,
23  Decline,
24  Postpone,
25 };
26 ///! @endcond
27 
28 static inline Cmd cmdFromName(const std::string &name) {
29  return std::map<std::string, Cmd>{
30  {"campaign_accept", Cmd::Accept}, {"campaign_decline", Cmd::Decline}, {"campaign_postpone", Cmd::Postpone}}
31  .at(name);
32 }
33 
34 // Out of uptane concept: update campaign for a device
35 class Campaign {
36  public:
37  static std::vector<Campaign> campaignsFromJson(const Json::Value &json);
38  static void JsonFromCampaigns(const std::vector<Campaign> &in, Json::Value &out);
39  static std::vector<Campaign> fetchAvailableCampaigns(HttpInterface &http_client, const std::string &tls_server);
40 
41  public:
42  Campaign() = default;
43  Campaign(const Json::Value &json);
44  void getJson(Json::Value &out) const;
45 
46  std::string id;
47  std::string name;
48  int64_t size{0};
49  bool autoAccept{false};
50  std::string description;
51  int estInstallationDuration{0};
52  int estPreparationDuration{0};
53 };
54 
55 } // namespace campaign
56 
57 #endif