DataStore.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #pragma once
  2. #include <helpers/IdentityStore.h>
  3. #include <helpers/ContactInfo.h>
  4. #include <helpers/ChannelDetails.h>
  5. #include "NodePrefs.h"
  6. class DataStoreHost {
  7. public:
  8. virtual bool onContactLoaded(const ContactInfo& contact) =0;
  9. virtual bool getContactForSave(uint32_t idx, ContactInfo& contact) =0;
  10. virtual bool onChannelLoaded(uint8_t channel_idx, const ChannelDetails& ch) =0;
  11. virtual bool getChannelForSave(uint8_t channel_idx, ChannelDetails& ch) =0;
  12. };
  13. class DataStore {
  14. FILESYSTEM* _fs;
  15. mesh::RTCClock* _clock;
  16. IdentityStore identity_store;
  17. void loadPrefsInt(const char *filename, NodePrefs& prefs, double& node_lat, double& node_lon);
  18. #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
  19. void checkAdvBlobFile();
  20. #endif
  21. public:
  22. DataStore(FILESYSTEM& fs, mesh::RTCClock& clock);
  23. void begin();
  24. bool formatFileSystem();
  25. bool loadMainIdentity(mesh::LocalIdentity &identity);
  26. bool saveMainIdentity(const mesh::LocalIdentity &identity);
  27. void loadPrefs(NodePrefs& prefs, double& node_lat, double& node_lon);
  28. void savePrefs(const NodePrefs& prefs, double node_lat, double node_lon);
  29. void loadContacts(DataStoreHost* host);
  30. void saveContacts(DataStoreHost* host);
  31. void loadChannels(DataStoreHost* host);
  32. void saveChannels(DataStoreHost* host);
  33. uint8_t getBlobByKey(const uint8_t key[], int key_len, uint8_t dest_buf[]);
  34. bool putBlobByKey(const uint8_t key[], int key_len, const uint8_t src_buf[], uint8_t len);
  35. File openRead(const char* filename);
  36. bool removeFile(const char* filename);
  37. uint32_t getStorageUsedKb() const;
  38. uint32_t getStorageTotalKb() const;
  39. };