mirror of
https://github.com/wiiu-env/libsdutils.git
synced 2024-11-22 11:09:14 +01:00
Add version check to make sure the lib is comaptible with the loaded module
This commit is contained in:
parent
faa0eb1422
commit
c9c3ba3f71
@ -15,8 +15,12 @@ enum SDUtilsStatus {
|
|||||||
SDUTILS_RESULT_INVALID_ARGUMENT = -5,
|
SDUTILS_RESULT_INVALID_ARGUMENT = -5,
|
||||||
SDUTILS_RESULT_FAILED = -10,
|
SDUTILS_RESULT_FAILED = -10,
|
||||||
SDUTILS_RESULT_LIB_UNINITIALIZED = -20,
|
SDUTILS_RESULT_LIB_UNINITIALIZED = -20,
|
||||||
|
SDUTILS_RESULT_UNSUPPORTED_VERSION = -99,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef uint32_t SDUtilsVersion;
|
||||||
|
#define SDUTILS_MODULE_VERSION 0x00000001
|
||||||
|
|
||||||
enum SDUtilsAttachStatus {
|
enum SDUtilsAttachStatus {
|
||||||
SDUTILS_ATTACH_MOUNTED = 1,
|
SDUTILS_ATTACH_MOUNTED = 1,
|
||||||
SDUTILS_ATTACH_UNMOUNTED = 0,
|
SDUTILS_ATTACH_UNMOUNTED = 0,
|
||||||
@ -32,6 +36,12 @@ typedef void (*SDAttachHandlerFn)(SDUtilsAttachStatus status);
|
|||||||
*/
|
*/
|
||||||
SDUtilsStatus SDUtils_Init();
|
SDUtilsStatus SDUtils_Init();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the API Version of the WUHBUtils Module.
|
||||||
|
* @return The WUHBUtilsVersion of the Module
|
||||||
|
*/
|
||||||
|
SDUtilsVersion SDUtils_GetVersion();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deinitializes the SDUtils library, must be called before exiting the application
|
* Deinitializes the SDUtils library, must be called before exiting the application
|
||||||
* @return SDUTILS_RESULT_SUCCESS on success
|
* @return SDUTILS_RESULT_SUCCESS on success
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
static OSDynLoad_Module sModuleHandle = nullptr;
|
static OSDynLoad_Module sModuleHandle = nullptr;
|
||||||
|
|
||||||
|
static SDUtilsVersion (*sSDUtilsGetVersion)() = nullptr;
|
||||||
|
|
||||||
static bool (*sSDUtilsAddAttachHandler)(SDAttachHandlerFn) = nullptr;
|
static bool (*sSDUtilsAddAttachHandler)(SDAttachHandlerFn) = nullptr;
|
||||||
static bool (*sSDUtilsRemoveAttachHandler)(SDAttachHandlerFn) = nullptr;
|
static bool (*sSDUtilsRemoveAttachHandler)(SDAttachHandlerFn) = nullptr;
|
||||||
|
|
||||||
@ -14,6 +16,15 @@ SDUtilsStatus SDUtils_Init() {
|
|||||||
return SDUTILS_RESULT_MODULE_NOT_FOUND;
|
return SDUTILS_RESULT_MODULE_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (OSDynLoad_FindExport(sModuleHandle, FALSE, "SDUtilsGetVersion", (void **) &sSDUtilsGetVersion) != OS_DYNLOAD_OK) {
|
||||||
|
OSReport("SDUtils_Init: SDUtilsGetVersion failed.\n");
|
||||||
|
return SDUTILS_RESULT_MODULE_MISSING_EXPORT;
|
||||||
|
}
|
||||||
|
auto res = SDUtils_GetVersion();
|
||||||
|
if (res != SDUTILS_MODULE_VERSION) {
|
||||||
|
return SDUTILS_RESULT_UNSUPPORTED_VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
if (OSDynLoad_FindExport(sModuleHandle, FALSE, "SDUtilsAddAttachHandler", (void **) &sSDUtilsAddAttachHandler) != OS_DYNLOAD_OK) {
|
if (OSDynLoad_FindExport(sModuleHandle, FALSE, "SDUtilsAddAttachHandler", (void **) &sSDUtilsAddAttachHandler) != OS_DYNLOAD_OK) {
|
||||||
OSReport("SDUtils_Init: SDUtilsAddAttachHandler failed.\n");
|
OSReport("SDUtils_Init: SDUtilsAddAttachHandler failed.\n");
|
||||||
return SDUTILS_RESULT_MODULE_MISSING_EXPORT;
|
return SDUTILS_RESULT_MODULE_MISSING_EXPORT;
|
||||||
@ -27,6 +38,15 @@ SDUtilsStatus SDUtils_Init() {
|
|||||||
return SDUTILS_RESULT_SUCCESS;
|
return SDUTILS_RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDUtilsVersion GetVersion();
|
||||||
|
SDUtilsVersion SDUtils_GetVersion() {
|
||||||
|
if (sSDUtilsGetVersion == nullptr) {
|
||||||
|
return SDUTILS_RESULT_LIB_UNINITIALIZED;
|
||||||
|
}
|
||||||
|
|
||||||
|
return reinterpret_cast<decltype(&GetVersion)>(sSDUtilsGetVersion)();
|
||||||
|
}
|
||||||
|
|
||||||
SDUtilsStatus SDUtils_DeInit() {
|
SDUtilsStatus SDUtils_DeInit() {
|
||||||
// We don't need to release the OSDynLoad handle for modules.
|
// We don't need to release the OSDynLoad handle for modules.
|
||||||
return SDUTILS_RESULT_SUCCESS;
|
return SDUTILS_RESULT_SUCCESS;
|
||||||
|
Loading…
Reference in New Issue
Block a user