Created
June 26, 2019 11:12
-
-
Save SysMan-One/ac2bc2128c9ecb8301b42d5191fcb820 to your computer and use it in GitHub Desktop.
A template for the callback function. Don't forget to include <stdarg.h>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
** DESCRIPTION: A template for the callback function. Don't forget to include <stdarg.h> | |
** | |
** INPUT: | |
** ctx: a callback context argument has been passed into the bagent_init() | |
** what: see BP$K_* constants: | |
** sd: is an optional argument is passed if what==BP$K_PROTSD | |
** | |
** OUTPUT: | |
** NONE | |
** | |
** RETURN: | |
** NONE | |
*/ | |
void callback ( void *ctx, int what, ...) | |
{ | |
#if ANDROID | |
/* Globals for callback function */ | |
JavaVM* javaVM = NULL; | |
jclass bagentClass; | |
jobject bagentObj; | |
JNIEnv *env; | |
#endif /* ANDROID */ | |
switch (what) | |
{ | |
case BP$K_BAGUP: | |
case BP$K_BAGDOWN: | |
case BP$K_BAGCTLUP: | |
case BP$K_BAGCTLDOWN: | |
$LOG(STS$K_INFO, "BAGENT Sent notification #%d", what); | |
break; | |
case BP$K_PROTSD: | |
{ | |
int *p; | |
int sd = -1; | |
va_list ap; | |
/* ‘sd’ (to be protected from VPN routing) is coming as third argument, | |
** Point pointer to next after 'what' argument in stack | |
*/ | |
va_start(ap, what); | |
sd = (int) va_arg(ap, int); | |
va_end(ap); | |
$IFTRACE(g_trace, "Got sd=%d", sd); | |
#if ANDROID | |
/* Prepare jvm and call Java method */ | |
(*javaVM)->AttachCurrentThread(javaVM, &env, NULL); | |
jmethodID method = (*env)->GetMethodID(env, bagentClass, "protectBagentSocketCallback", "(I)V"); | |
(*env)->CallVoidMethod(env, bagentObj, method, sd); | |
#endif /* ANDROID */ | |
} /* case BP$K_PROTSD */ | |
break; | |
default: | |
$LOG(STS$K_ERROR, "Uhandled function code %#x", what); | |
} | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment