storage_glue.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #pragma once
  2. #include <furi.h>
  3. #include "filesystem_api_internal.h"
  4. #include <m-list.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. typedef enum { ST_EXT = 0, ST_INT = 1, ST_ANY, ST_ERROR } StorageType;
  9. typedef struct StorageData StorageData;
  10. typedef struct {
  11. void (*tick)(StorageData* storage);
  12. } StorageApi;
  13. typedef struct {
  14. File* file;
  15. void* file_data;
  16. FuriString* path;
  17. } StorageFile;
  18. typedef enum {
  19. StorageStatusOK, /**< storage ok */
  20. StorageStatusNotReady, /**< storage not ready (not initialized or waiting for data storage to appear) */
  21. StorageStatusNotMounted, /**< datastore appeared, but we cannot mount it */
  22. StorageStatusNoFS, /**< datastore appeared and mounted, but does not have a file system */
  23. StorageStatusNotAccessible, /**< datastore appeared and mounted, but not available */
  24. StorageStatusErrorInternal, /**< any other internal error */
  25. } StorageStatus;
  26. void storage_file_init(StorageFile* obj);
  27. void storage_file_init_set(StorageFile* obj, const StorageFile* src);
  28. void storage_file_set(StorageFile* obj, const StorageFile* src);
  29. void storage_file_clear(StorageFile* obj);
  30. void storage_data_init(StorageData* storage);
  31. StorageStatus storage_data_status(StorageData* storage);
  32. const char* storage_data_status_text(StorageData* storage);
  33. void storage_data_timestamp(StorageData* storage);
  34. uint32_t storage_data_get_timestamp(StorageData* storage);
  35. LIST_DEF(
  36. StorageFileList,
  37. StorageFile,
  38. (INIT(API_2(storage_file_init)),
  39. SET(API_6(storage_file_init_set)),
  40. INIT_SET(API_6(storage_file_set)),
  41. CLEAR(API_2(storage_file_clear))))
  42. struct StorageData {
  43. const FS_Api* fs_api;
  44. StorageApi api;
  45. void* data;
  46. StorageStatus status;
  47. StorageFileList_t files;
  48. uint32_t timestamp;
  49. };
  50. bool storage_has_file(const File* file, StorageData* storage_data);
  51. bool storage_path_already_open(FuriString* path, StorageData* storage_data);
  52. void storage_set_storage_file_data(const File* file, void* file_data, StorageData* storage);
  53. void* storage_get_storage_file_data(const File* file, StorageData* storage);
  54. void storage_push_storage_file(File* file, FuriString* path, StorageData* storage);
  55. bool storage_pop_storage_file(File* file, StorageData* storage);
  56. #ifdef __cplusplus
  57. }
  58. #endif