mirror of
https://github.com/Tencent/MMKV.git
synced 2026-10-17 04:30:56 +08:00
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:
+6
-6
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user