refactor callback system into unified MMKVHandler across all platforms

Replace 4 separate static function pointers (LogHandler, ErrorHandler,
ContentChangeHandler, ContentLoadedHandler) with a single MMKVHandler
abstract class in Core C++. Update all 6 platform wrappers (iOS, Android,
OHOS, Python, Golang, Flutter) to use adapter classes bridging to the new
unified handler. Add onMMKVContentLoadSuccessfully callback to Android,
OHOS, Flutter, Python and Golang where it was previously missing.
This commit is contained in:
guoling
2026-03-18 12:40:05 +08:00
parent d90f664a2e
commit 9348a93f26
33 changed files with 917 additions and 671 deletions
+6 -6
View File
@@ -32,8 +32,6 @@ MMKVLogLevel g_currentLogLevel = MMKVLogDebug;
MMKVLogLevel g_currentLogLevel = MMKVLogInfo;
#endif
mmkv::LogHandler g_logHandler = nullptr;
#ifndef __FILE_NAME__
const char *_getFileName(const char *path) {
const char *ptr = strrchr(path, '/');
@@ -48,6 +46,8 @@ const char *_getFileName(const char *path) {
}
#endif
mmkv::MMKVHandler *g_handler = nullptr;
MMKV_NAMESPACE_END
@@ -84,8 +84,8 @@ void _MMKVLogWithLevel(MMKVLogLevel level, const char *filename, const char *fun
NSString *message = [[NSString alloc] initWithFormat:nsFormat arguments:argList];
va_end(argList);
if (g_logHandler) {
g_logHandler(level, filename, line, func, message);
if (g_handler) {
g_handler->mmkvLog(level, filename, line, func, message);
} else {
NSLog(@"[%s] <%s:%d::%s> %@", MMKVLogLevelDesc(level), filename, line, func, message);
}
@@ -169,8 +169,8 @@ void _MMKVLogWithLevel(MMKVLogLevel level, const char *filename, const char *fun
va_end(args);
}
if (g_logHandler) {
g_logHandler(level, filename, line, func, message);
if (g_handler) {
g_handler->mmkvLog(level, filename, line, func, message);
} else {
#if defined(MMKV_WIN32)
PrintUTF8("[%s] <%s:%d::%s> %s\n", MMKVLogLevelDesc(level), filename, line, func, message.c_str());