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