storage-glue.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma once
  2. #include <furi.h>
  3. #include "filesystem-api-internal.h"
  4. #include <m-string.h>
  5. #include <m-array.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. 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. StorageType storage_get_type_by_path(const char* path);
  54. bool storage_path_already_open(const char* path, StorageFileList_t files);
  55. void storage_set_storage_file_data(const File* file, void* file_data, StorageData* storage);
  56. void* storage_get_storage_file_data(const File* file, StorageData* storage);
  57. void storage_push_storage_file(
  58. File* file,
  59. const char* path,
  60. StorageType type,
  61. StorageData* storage);
  62. bool storage_pop_storage_file(File* file, StorageData* storage);
  63. #ifdef __cplusplus
  64. }
  65. #endif