Return WUPSStorageError enum instead of int for storage API

This commit is contained in:
Maschell 2022-08-26 19:26:45 +02:00
parent 6ef886df33
commit a2f75edfeb
2 changed files with 34 additions and 34 deletions

View File

@ -14,7 +14,7 @@ typedef enum wups_storage_type_t_ {
WUPS_STORAGE_TYPE_ITEM,
} wups_storage_type_t;
enum {
typedef enum {
WUPS_STORAGE_ERROR_SUCCESS = 0,
WUPS_STORAGE_ERROR_NOT_OPENED = -1,
WUPS_STORAGE_ERROR_ALREADY_OPENED = -2,
@ -26,7 +26,7 @@ enum {
WUPS_STORAGE_ERROR_IO = -8,
WUPS_STORAGE_ERROR_B64_DECODE_FAILED = -9,
WUPS_STORAGE_ERROR_BUFFER_TOO_SMALL = -10,
};
} WUPSStorageError;
typedef struct wups_storage_item_t_ {
char *key;
@ -36,8 +36,8 @@ typedef struct wups_storage_item_t_ {
wups_storage_type_t type;
} wups_storage_item_t;
typedef int32_t (*OpenStorageFunction)(const char *plugin_id, wups_storage_item_t *items);
typedef int32_t (*CloseStorageFunction)(const char *plugin_id, wups_storage_item_t *items);
typedef WUPSStorageError (*OpenStorageFunction)(const char *plugin_id, wups_storage_item_t *items);
typedef WUPSStorageError (*CloseStorageFunction)(const char *plugin_id, wups_storage_item_t *items);
typedef struct wups_loader_init_storage_args_t_ {
OpenStorageFunction open_storage_ptr;
@ -49,30 +49,30 @@ typedef struct wups_loader_init_storage_args_t_ {
void WUPS_InitStorage(wups_loader_init_storage_args_t args);
/* opens storage for reading and writing */
int32_t WUPS_OpenStorage(void);
WUPSStorageError WUPS_OpenStorage(void);
/* closes storage and saves changes */
int32_t WUPS_CloseStorage(void);
WUPSStorageError WUPS_CloseStorage(void);
/* deletes key from storage */
int32_t WUPS_DeleteItem(wups_storage_item_t *parent, const char *key);
WUPSStorageError WUPS_DeleteItem(wups_storage_item_t *parent, const char *key);
/* returns the size of key on success, or an error code */
// TODO do we need this? what about binary data?
// int32_t WUPS_GetSize(const char* key);
int32_t WUPS_CreateSubItem(wups_storage_item_t *parent, const char *key, wups_storage_item_t **outItem);
int32_t WUPS_GetSubItem(wups_storage_item_t *parent, const char *key, wups_storage_item_t **outItem);
WUPSStorageError WUPS_CreateSubItem(wups_storage_item_t *parent, const char *key, wups_storage_item_t **outItem);
WUPSStorageError WUPS_GetSubItem(wups_storage_item_t *parent, const char *key, wups_storage_item_t **outItem);
int32_t WUPS_StoreString(wups_storage_item_t *parent, const char *key, const char *string);
int32_t WUPS_StoreBool(wups_storage_item_t *parent, const char *key, bool value);
int32_t WUPS_StoreInt(wups_storage_item_t *parent, const char *key, int32_t value);
int32_t WUPS_StoreBinary(wups_storage_item_t *parent, const char *key, const void *data, uint32_t size);
WUPSStorageError WUPS_StoreString(wups_storage_item_t *parent, const char *key, const char *string);
WUPSStorageError WUPS_StoreBool(wups_storage_item_t *parent, const char *key, bool value);
WUPSStorageError WUPS_StoreInt(wups_storage_item_t *parent, const char *key, int32_t value);
WUPSStorageError WUPS_StoreBinary(wups_storage_item_t *parent, const char *key, const void *data, uint32_t size);
int32_t WUPS_GetString(wups_storage_item_t *parent, const char *key, char *outString, uint32_t maxSize);
int32_t WUPS_GetBool(wups_storage_item_t *parent, const char *key, bool *outBool);
int32_t WUPS_GetInt(wups_storage_item_t *parent, const char *key, int32_t *outInt);
int32_t WUPS_GetBinary(wups_storage_item_t *parent, const char *key, void *outData, uint32_t maxSize);
WUPSStorageError WUPS_GetString(wups_storage_item_t *parent, const char *key, char *outString, uint32_t maxSize);
WUPSStorageError WUPS_GetBool(wups_storage_item_t *parent, const char *key, bool *outBool);
WUPSStorageError WUPS_GetInt(wups_storage_item_t *parent, const char *key, int32_t *outInt);
WUPSStorageError WUPS_GetBinary(wups_storage_item_t *parent, const char *key, void *outData, uint32_t maxSize);
#ifdef __cplusplus
}

View File

@ -29,7 +29,7 @@ void WUPS_InitStorage(wups_loader_init_storage_args_t args) {
rootItem.type = WUPS_STORAGE_TYPE_ITEM;
}
int32_t WUPS_OpenStorage(void) {
WUPSStorageError WUPS_OpenStorage(void) {
if (!storage_initialized) {
return WUPS_STORAGE_ERROR_NOT_INITIALIZED;
}
@ -38,7 +38,7 @@ int32_t WUPS_OpenStorage(void) {
return WUPS_STORAGE_ERROR_ALREADY_OPENED;
}
int32_t result = openfunction_ptr(plugin_id, &rootItem);
WUPSStorageError result = openfunction_ptr(plugin_id, &rootItem);
if (result == WUPS_STORAGE_ERROR_SUCCESS || result == WUPS_STORAGE_ERROR_INVALID_JSON) {
isOpened = true;
@ -64,7 +64,7 @@ static void closeItem(wups_storage_item_t *item) {
}
}
int32_t WUPS_CloseStorage(void) {
WUPSStorageError WUPS_CloseStorage(void) {
if (!storage_initialized) {
return WUPS_STORAGE_ERROR_NOT_INITIALIZED;
}
@ -73,12 +73,12 @@ int32_t WUPS_CloseStorage(void) {
return WUPS_STORAGE_ERROR_NOT_OPENED;
}
int32_t result = 0;
WUPSStorageError result = WUPS_STORAGE_ERROR_SUCCESS;
if (isDirty) {
result = closefunction_ptr(plugin_id, &rootItem);
}
if (result == 0) {
if (result == WUPS_STORAGE_ERROR_SUCCESS) {
isOpened = false;
isDirty = false;
@ -91,7 +91,7 @@ int32_t WUPS_CloseStorage(void) {
return result;
}
int32_t WUPS_DeleteItem(wups_storage_item_t *parent, const char *key) {
WUPSStorageError WUPS_DeleteItem(wups_storage_item_t *parent, const char *key) {
if (!storage_initialized) {
return WUPS_STORAGE_ERROR_NOT_INITIALIZED;
}
@ -190,7 +190,7 @@ static wups_storage_item_t *addItem(wups_storage_item_t *parent, const char *key
return foundItem;
}
int32_t WUPS_CreateSubItem(wups_storage_item_t *parent, const char *key, wups_storage_item_t **outItem) {
WUPSStorageError WUPS_CreateSubItem(wups_storage_item_t *parent, const char *key, wups_storage_item_t **outItem) {
if (!storage_initialized) {
return WUPS_STORAGE_ERROR_NOT_INITIALIZED;
}
@ -215,7 +215,7 @@ int32_t WUPS_CreateSubItem(wups_storage_item_t *parent, const char *key, wups_st
return WUPS_STORAGE_ERROR_SUCCESS;
}
int32_t WUPS_GetSubItem(wups_storage_item_t *parent, const char *key, wups_storage_item_t **outItem) {
WUPSStorageError WUPS_GetSubItem(wups_storage_item_t *parent, const char *key, wups_storage_item_t **outItem) {
if (!storage_initialized) {
return WUPS_STORAGE_ERROR_NOT_INITIALIZED;
}
@ -248,7 +248,7 @@ int32_t WUPS_GetSubItem(wups_storage_item_t *parent, const char *key, wups_stora
return WUPS_STORAGE_ERROR_NOT_FOUND;
}
int32_t WUPS_StoreString(wups_storage_item_t *parent, const char *key, const char *string) {
WUPSStorageError WUPS_StoreString(wups_storage_item_t *parent, const char *key, const char *string) {
if (!storage_initialized) {
return WUPS_STORAGE_ERROR_NOT_INITIALIZED;
}
@ -277,11 +277,11 @@ int32_t WUPS_StoreString(wups_storage_item_t *parent, const char *key, const cha
return WUPS_STORAGE_ERROR_SUCCESS;
}
int32_t WUPS_StoreBool(wups_storage_item_t *parent, const char *key, bool value) {
WUPSStorageError WUPS_StoreBool(wups_storage_item_t *parent, const char *key, bool value) {
return WUPS_StoreInt(parent, key, (int32_t) value);
}
int32_t WUPS_StoreInt(wups_storage_item_t *parent, const char *key, int32_t value) {
WUPSStorageError WUPS_StoreInt(wups_storage_item_t *parent, const char *key, int32_t value) {
if (!storage_initialized) {
return WUPS_STORAGE_ERROR_NOT_INITIALIZED;
}
@ -309,7 +309,7 @@ int32_t WUPS_StoreInt(wups_storage_item_t *parent, const char *key, int32_t valu
return WUPS_STORAGE_ERROR_SUCCESS;
}
int32_t WUPS_StoreBinary(wups_storage_item_t *parent, const char *key, const void *data, uint32_t size) {
WUPSStorageError WUPS_StoreBinary(wups_storage_item_t *parent, const char *key, const void *data, uint32_t size) {
if (!storage_initialized) {
return WUPS_STORAGE_ERROR_NOT_INITIALIZED;
}
@ -334,7 +334,7 @@ int32_t WUPS_StoreBinary(wups_storage_item_t *parent, const char *key, const voi
return WUPS_STORAGE_ERROR_SUCCESS;
}
int32_t WUPS_GetString(wups_storage_item_t *parent, const char *key, char *outString, uint32_t maxSize) {
WUPSStorageError WUPS_GetString(wups_storage_item_t *parent, const char *key, char *outString, uint32_t maxSize) {
if (!storage_initialized) {
return WUPS_STORAGE_ERROR_NOT_INITIALIZED;
}
@ -366,9 +366,9 @@ int32_t WUPS_GetString(wups_storage_item_t *parent, const char *key, char *outSt
return WUPS_STORAGE_ERROR_NOT_FOUND;
}
int32_t WUPS_GetBool(wups_storage_item_t *parent, const char *key, bool *outBool) {
WUPSStorageError WUPS_GetBool(wups_storage_item_t *parent, const char *key, bool *outBool) {
int32_t out;
int32_t result = WUPS_GetInt(parent, key, &out);
WUPSStorageError result = WUPS_GetInt(parent, key, &out);
if (result != WUPS_STORAGE_ERROR_SUCCESS) {
return result;
}
@ -378,7 +378,7 @@ int32_t WUPS_GetBool(wups_storage_item_t *parent, const char *key, bool *outBool
return WUPS_STORAGE_ERROR_SUCCESS;
}
int32_t WUPS_GetInt(wups_storage_item_t *parent, const char *key, int32_t *outInt) {
WUPSStorageError WUPS_GetInt(wups_storage_item_t *parent, const char *key, int32_t *outInt) {
if (!storage_initialized) {
return WUPS_STORAGE_ERROR_NOT_INITIALIZED;
}
@ -411,7 +411,7 @@ int32_t WUPS_GetInt(wups_storage_item_t *parent, const char *key, int32_t *outIn
return WUPS_STORAGE_ERROR_NOT_FOUND;
}
int32_t WUPS_GetBinary(wups_storage_item_t *parent, const char *key, void *outData, uint32_t maxSize) {
WUPSStorageError WUPS_GetBinary(wups_storage_item_t *parent, const char *key, void *outData, uint32_t maxSize) {
if (!storage_initialized) {
return WUPS_STORAGE_ERROR_NOT_INITIALIZED;
}