mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-12-22 18:53:18 +00:00
79 lines
2.3 KiB
C
79 lines
2.3 KiB
C
|
#pragma once
|
||
|
#include <furi.h>
|
||
|
#include "filesystem-api-internal.h"
|
||
|
#include <m-string.h>
|
||
|
#include <m-array.h>
|
||
|
|
||
|
#ifdef __cplusplus
|
||
|
extern "C" {
|
||
|
#endif
|
||
|
|
||
|
typedef enum { ST_EXT = 0, ST_INT = 1, ST_ANY, ST_ERROR } StorageType;
|
||
|
|
||
|
typedef struct StorageData StorageData;
|
||
|
|
||
|
typedef struct {
|
||
|
void (*tick)(StorageData* storage);
|
||
|
} StorageApi;
|
||
|
|
||
|
typedef struct {
|
||
|
File* file;
|
||
|
StorageType type;
|
||
|
void* file_data;
|
||
|
string_t path;
|
||
|
} StorageFile;
|
||
|
|
||
|
typedef enum {
|
||
|
StorageStatusOK, /**< storage ok */
|
||
|
StorageStatusNotReady, /**< storage not ready (not initialized or waiting for data storage to appear) */
|
||
|
StorageStatusNotMounted, /**< datastore appeared, but we cannot mount it */
|
||
|
StorageStatusNoFS, /**< datastore appeared and mounted, but does not have a file system */
|
||
|
StorageStatusNotAccessible, /**< datastore appeared and mounted, but not available */
|
||
|
StorageStatusErrorInternal, /**< any other internal error */
|
||
|
} StorageStatus;
|
||
|
|
||
|
void storage_file_init(StorageFile* obj);
|
||
|
void storage_file_init_set(StorageFile* obj, const StorageFile* src);
|
||
|
void storage_file_set(StorageFile* obj, const StorageFile* src);
|
||
|
void storage_file_clear(StorageFile* obj);
|
||
|
|
||
|
void storage_data_init(StorageData* storage);
|
||
|
bool storage_data_lock(StorageData* storage);
|
||
|
bool storage_data_unlock(StorageData* storage);
|
||
|
StorageStatus storage_data_status(StorageData* storage);
|
||
|
const char* storage_data_status_text(StorageData* storage);
|
||
|
|
||
|
LIST_DEF(
|
||
|
StorageFileList,
|
||
|
StorageFile,
|
||
|
(INIT(API_2(storage_file_init)),
|
||
|
SET(API_6(storage_file_init_set)),
|
||
|
INIT_SET(API_6(storage_file_set)),
|
||
|
CLEAR(API_2(storage_file_clear))))
|
||
|
|
||
|
struct StorageData {
|
||
|
FS_Api fs_api;
|
||
|
StorageApi api;
|
||
|
void* data;
|
||
|
osMutexId_t mutex;
|
||
|
StorageStatus status;
|
||
|
StorageFileList_t files;
|
||
|
};
|
||
|
|
||
|
bool storage_has_file(const File* file, StorageData* storage_data);
|
||
|
StorageType storage_get_type_by_path(const char* path);
|
||
|
bool storage_path_already_open(const char* path, StorageFileList_t files);
|
||
|
|
||
|
void storage_set_storage_file_data(const File* file, void* file_data, StorageData* storage);
|
||
|
void* storage_get_storage_file_data(const File* file, StorageData* storage);
|
||
|
|
||
|
void storage_push_storage_file(
|
||
|
File* file,
|
||
|
const char* path,
|
||
|
StorageType type,
|
||
|
StorageData* storage);
|
||
|
bool storage_pop_storage_file(File* file, StorageData* storage);
|
||
|
|
||
|
#ifdef __cplusplus
|
||
|
}
|
||
|
#endif
|