supla-device
Loading...
Searching...
No Matches
sw_update.h
1/*
2 Copyright (C) AC SOFTWARE SP. Z O.O.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17*/
18
19#ifndef SRC_SUPLA_DEVICE_SW_UPDATE_H_
20#define SRC_SUPLA_DEVICE_SW_UPDATE_H_
21
22#define SUPLA_MAX_URL_LENGTH 202
23
24#include <SuplaDevice.h>
25
26namespace Supla {
27
28namespace Device {
29class SwUpdate {
30 public:
31 static SwUpdate *Create(SuplaDeviceClass *sdc,
32 const char *newUrl,
33 Supla::SwUpdateMode mode);
34 virtual ~SwUpdate();
35
36 void start() {
37 started = true;
38 }
39 virtual void iterate() = 0;
40
41 void setUrl(const char *newUrl);
42 bool isStarted() {
43 return started;
44 }
45 bool isFinished() {
46 return finished;
47 }
48 bool isAborted() {
49 return abort;
50 }
51 void useBeta() {
52 beta = true;
53 }
54 void setSkipCert() {
55 // One-time recovery fallback for expired OTA certificates.
56 // The OTA flow clears this mode after use.
57 skipCert = true;
58 }
59 bool isRetryAllowed() {
60 return retryAllowed;
61 }
62
63 const char *getUrl() const {
64 return updateUrl;
65 }
66 const char *getNewVersion() const {
67 return newVersion;
68 }
69 const char *getChangelogUrl() const {
70 return changelogUrl;
71 }
72
73 bool isSecurityOnly() const {
74 return securityOnly;
75 }
76 void setSecurityOnly() {
77 securityOnly = true;
78 }
79
80 protected:
81 explicit SwUpdate(SuplaDeviceClass *sdc,
82 const char *newUrl,
83 Supla::SwUpdateMode mode);
84
85 bool beta = false;
86 bool skipCert = false;
87 bool securityOnly = false;
88 bool started = false;
89 bool finished = false;
90 bool abort = false;
91 SuplaDeviceClass *sdc = nullptr;
92 char *updateUrl = nullptr;
93 char *newVersion = nullptr;
94 char *changelogUrl = nullptr;
95 bool retryAllowed = false;
96 Supla::SwUpdateMode mode = Supla::SwUpdateMode::NotSet;
97
98 char url[SUPLA_MAX_URL_LENGTH] = {};
99};
100}; // namespace Device
101}; // namespace Supla
102
103#endif // SRC_SUPLA_DEVICE_SW_UPDATE_H_
Definition SuplaDevice.h:163