storage_glue.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. StorageType type;
  16. void* file_data;
  17. FuriString* path;
  18. } StorageFile;
  19. typedef enum {
  20. StorageStatusOK, /**< storage ok */
  21. StorageStatusNotReady, /**< storage not ready (not initialized or waiting for data storage to appear) */
  22. StorageStatusNotMounted, /**< datastore appeared, but we cannot mount it */
  23. StorageStatusNoFS, /**< datastore appeared and mounted, but does not have a file system */
  24. StorageStatusNotAccessible, /**< datastore appeared and mounted, but not available */
  25. StorageStatusErrorInternal, /**< any other internal error */
  26. } StorageStatus;
  27. void storage_file_init(StorageFile* obj);
  28. void storage_file_init_set(StorageFile* obj, const StorageFile* src);
  29. void storage_file_set(StorageFile* obj, const StorageFile* src);
  30. void storage_file_clear(StorageFile* obj);
  31. void storage_data_init(StorageData* storage);
  32. bool storage_data_lock(StorageData* storage);
  33. bool storage_data_unlock(StorageData* storage);
  34. StorageStatus storage_data_status(StorageData* storage);
  35. const char* storage_data_status_text(StorageData* storage);
  36. void storage_data_timestamp(StorageData* storage);
  37. uint32_t storage_data_get_timestamp(StorageData* storage);
  38. LIST_DEF(
  39. StorageFileList,
  40. StorageFile,
  41. (INIT(API_2(storage_file_init)),
  42. SET(API_6(storage_file_init_set)),
  43. INIT_SET(API_6(storage_file_set)),
  44. CLEAR(API_2(storage_file_clear))))
  45. struct StorageData {
  46. const FS_Api* fs_api;
  47. StorageApi api;
  48. void* data;
  49. FuriMutex* mutex;
  50. StorageStatus status;
  51. StorageFileList_t files;
  52. uint32_t timestamp;
  53. };
  54. bool storage_has_file(const File* file, StorageData* storage_data);
  55. bool storage_path_already_open(FuriString* path, StorageFileList_t files);
  56. void storage_set_storage_file_data(const File* file, void* file_data, StorageData* storage);
  57. void* storage_get_storage_file_data(const File* file, StorageData* storage);
  58. void storage_push_storage_file(
  59. File* file,
  60. FuriString* path,
  61. StorageType type,
  62. StorageData* storage);
  63. bool storage_pop_storage_file(File* file, StorageData* storage);
  64. #ifdef __cplusplus
  65. }
  66. #endif