supla-device
Loading...
Searching...
No Matches
state_storage_interface.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef SRC_SUPLA_STORAGE_STATE_STORAGE_INTERFACE_H_
5#define SRC_SUPLA_STORAGE_STATE_STORAGE_INTERFACE_H_
6
7#include <stdint.h>
8
9namespace Supla {
10
11class Storage;
12struct SectionPreamble;
13
15 public:
16 explicit StateStorageInterface(Storage *storage, uint8_t sectionType);
17 virtual ~StateStorageInterface();
18 virtual bool loadPreambles(uint32_t storageStartingOffset, uint16_t size);
19 virtual void initSectionPreamble(Supla::SectionPreamble *preamble) = 0;
20 virtual bool writeSectionPreamble() = 0;
21 virtual bool initFromStorage() = 0;
22 virtual void deleteAll() = 0;
23 virtual bool prepareSaveState() = 0;
24 virtual bool prepareSizeCheck() = 0;
25 virtual bool prepareLoadState() = 0;
26 virtual bool readState(unsigned char *, int) = 0;
27 virtual bool writeState(const unsigned char *, int) = 0;
28 virtual bool finalizeSaveState() = 0;
29 virtual bool finalizeSizeCheck() = 0;
30 virtual bool finalizeLoadState() = 0;
31 virtual void notifyUpdate();
32
33 protected:
34 int readStorage(unsigned int address,
35 unsigned char *buf,
36 int size,
37 bool logs = true);
38 int writeStorage(unsigned int address, const unsigned char *buf, int size);
39 int updateStorage(unsigned int address, const unsigned char *buf, int size);
40 void commit();
41 void eraseSector(unsigned int address, int size);
42 virtual uint16_t getSizeValue(uint16_t availableSize);
43
44 Storage *storage = nullptr;
45 const uint8_t sectionType;
46};
47} // namespace Supla
48
49#endif // SRC_SUPLA_STORAGE_STATE_STORAGE_INTERFACE_H_
Definition state_storage_interface.h:14
Definition storage.h:23
Definition storage.h:147