supla-device
Loading...
Searching...
No Matches
simple_state.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_STORAGE_SIMPLE_STATE_H_
20#define SRC_SUPLA_STORAGE_SIMPLE_STATE_H_
21
22#include "state_storage_interface.h"
23
24namespace Supla {
25
26struct SectionPreamble;
27
28class SimpleState : public StateStorageInterface {
29 public:
30 explicit SimpleState(Storage *storage, uint32_t offset);
31 ~SimpleState();
32
33 void initSectionPreamble(SectionPreamble *preamble) override;
34
35 bool writeSectionPreamble() override;
36 bool initFromStorage() override;
37 void deleteAll() override;
38 bool prepareSaveState() override;
39 bool prepareSizeCheck() override;
40 bool prepareLoadState() override;
41 bool readState(unsigned char *, int) override;
42 bool writeState(const unsigned char *, int) override;
43 bool finalizeSaveState() override;
44 bool finalizeSizeCheck() override;
45 bool finalizeLoadState() override;
46
47 private:
48 uint32_t sectionOffset = 0;
49 uint32_t elementStateOffset = 0;
50 uint32_t elementStateSize = 0;
51 uint32_t stateSectionNewSize = 0;
52 uint32_t currentStateOffset = 0;
53 uint16_t storedCrc = 0; // CRC value stored in section preamble
54 uint16_t crc = 0; // value calculated on each save/read
55 bool elementStateCrcCValid = false;
56 bool dryRun = false;
57};
58
59} // namespace Supla
60#endif // SRC_SUPLA_STORAGE_SIMPLE_STATE_H_
Definition storage.h:142