Add SDUtilsAddCleanUpHandlesHandler and SDUtilsRemoveCleanUpHandlesHandler

This commit is contained in:
Maschell 2022-04-28 20:09:25 +02:00
parent 9cc06a1130
commit 6e2b4fa800
3 changed files with 53 additions and 2 deletions

View File

@ -6,6 +6,8 @@
#define MAX_HANDLERS 16 #define MAX_HANDLERS 16
static SDAttachHandlerFn sHandlers[MAX_HANDLERS] = {nullptr}; static SDAttachHandlerFn sHandlers[MAX_HANDLERS] = {nullptr};
static SDCleanUpHandlesHandlerFn sCleanupHandlesHandlers[MAX_HANDLERS] = {nullptr};
void callAttachCallbacks(SDUtilsAttachStatus status) { void callAttachCallbacks(SDUtilsAttachStatus status) {
int i; int i;
for (i = 0; i < MAX_HANDLERS; ++i) { for (i = 0; i < MAX_HANDLERS; ++i) {
@ -15,10 +17,23 @@ void callAttachCallbacks(SDUtilsAttachStatus status) {
} }
} }
void callCleanUpHandlesCallbacks() {
int i;
for (i = 0; i < MAX_HANDLERS; ++i) {
if (sCleanupHandlesHandlers[i]) {
sCleanupHandlesHandlers[i]();
}
}
}
void cleanUpAttachCallbacks() { void cleanUpAttachCallbacks() {
memset(sHandlers, 0, sizeof(sHandlers)); memset(sHandlers, 0, sizeof(sHandlers));
} }
void cleanUpCleanUpHandlesCallbacks() {
memset(sCleanupHandlesHandlers, 0, sizeof(sCleanupHandlesHandlers));
}
bool SDUtilsAddAttachHandler(SDAttachHandlerFn fn) { bool SDUtilsAddAttachHandler(SDAttachHandlerFn fn) {
int i; int i;
@ -48,6 +63,35 @@ bool SDUtilsRemoveAttachHandler(SDAttachHandlerFn fn) {
return false; return false;
} }
bool SDUtilsAddCleanUpHandlesHandler(SDCleanUpHandlesHandlerFn fn) {
int i;
for (i = 0; i < MAX_HANDLERS; ++i) {
if (sCleanupHandlesHandlers[i] == fn) {
return true;
}
if (!sCleanupHandlesHandlers[i]) {
sCleanupHandlesHandlers[i] = fn;
return true;
}
}
return false;
}
bool SDUtilsRemoveCleanUpHandlesHandler(SDCleanUpHandlesHandlerFn fn) {
int i;
for (i = 0; i < MAX_HANDLERS; ++i) {
if (sCleanupHandlesHandlers[i] == fn) {
sCleanupHandlesHandlers[i] = nullptr;
return true;
}
}
return false;
}
SDUtilsVersion SDUtilsGetVersion() { SDUtilsVersion SDUtilsGetVersion() {
return SDUTILS_MODULE_VERSION; return SDUTILS_MODULE_VERSION;
} }
@ -55,4 +99,7 @@ SDUtilsVersion SDUtilsGetVersion() {
WUMS_EXPORT_FUNCTION(SDUtilsGetVersion); WUMS_EXPORT_FUNCTION(SDUtilsGetVersion);
WUMS_EXPORT_FUNCTION(SDUtilsAddAttachHandler); WUMS_EXPORT_FUNCTION(SDUtilsAddAttachHandler);
WUMS_EXPORT_FUNCTION(SDUtilsRemoveAttachHandler); WUMS_EXPORT_FUNCTION(SDUtilsRemoveAttachHandler);
WUMS_EXPORT_FUNCTION(SDUtilsAddCleanUpHandlesHandler);
WUMS_EXPORT_FUNCTION(SDUtilsRemoveCleanUpHandlesHandler);

View File

@ -2,5 +2,7 @@
#include <sdutils/sdutils.h> #include <sdutils/sdutils.h>
void callAttachCallbacks(SDUtilsAttachStatus status); void callAttachCallbacks(SDUtilsAttachStatus status);
void cleanUpAttachCallbacks();
void cleanUpAttachCallbacks(); void callCleanUpHandlesCallbacks();
void cleanUpCleanUpHandlesCallbacks();

View File

@ -40,6 +40,7 @@ void DeInitSDCheck() {
} }
cleanUpAttachCallbacks(); cleanUpAttachCallbacks();
cleanUpCleanUpHandlesCallbacks();
OSMemoryBarrier(); OSMemoryBarrier();
} }
@ -85,6 +86,7 @@ int UnmountSDCard() {
return -1; return -1;
} }
std::lock_guard<std::mutex> lk(*mutex); std::lock_guard<std::mutex> lk(*mutex);
callCleanUpHandlesCallbacks();
FSCmdBlock fsCmd; FSCmdBlock fsCmd;
FSInitCmdBlock(&fsCmd); FSInitCmdBlock(&fsCmd);