storage_glue.h 2.3 KB

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