// #include <stdlib.h>
// #include <sys/types.h>
-// static void callLogger(void *func, int level, const char *msg)
+// static void callLogger(void *func, void *ctx, int level, const char *msg)
// {
-// ((void(*)(int, const char *))func)(level, msg);
+// ((void(*)(void *, int, const char *))func)(ctx, level, msg);
// }
import "C"
)
var loggerFunc unsafe.Pointer
+var loggerCtx unsafe.Pointer
var versionString *C.char
type CLogger struct {
return 0, errors.New("No logger initialized")
}
message := C.CString(string(p))
- C.callLogger(loggerFunc, l.level, message)
+ C.callLogger(loggerFunc, loggerCtx, l.level, message)
C.free(unsafe.Pointer(message))
return len(p), nil
}
n := runtime.Stack(buf, true)
buf[n] = 0
if uintptr(loggerFunc) != 0 {
- C.callLogger(loggerFunc, 0, (*C.char)(unsafe.Pointer(&buf[0])))
+ C.callLogger(loggerFunc, loggerCtx, 0, (*C.char)(unsafe.Pointer(&buf[0])))
}
}
}
}
//export wgSetLogger
-func wgSetLogger(loggerFn uintptr) {
+func wgSetLogger(context, loggerFn uintptr) {
+ loggerCtx = unsafe.Pointer(context)
loggerFunc = unsafe.Pointer(loggerFn)
}
#include <stdint.h>
#include <stdbool.h>
-typedef void(*logger_fn_t)(int level, const char *msg);
+typedef void(*logger_fn_t)(void *context, int level, const char *msg);
extern void wgEnableRoaming(bool enabled);
-extern void wgSetLogger(logger_fn_t logger_fn);
+extern void wgSetLogger(void *context, logger_fn_t logger_fn);
extern int wgTurnOn(const char *settings, int32_t tun_fd);
extern void wgTurnOff(int handle);
extern int64_t wgSetConfig(int handle, const char *settings);