Skip to content

Instantly share code, notes, and snippets.

@sonOfRa
Created August 29, 2013 12:02
Show Gist options
  • Save sonOfRa/6377188 to your computer and use it in GitHub Desktop.
Save sonOfRa/6377188 to your computer and use it in GitHub Desktop.
typedef struct {
JNIEnv *env;
jobject jobj;
} tox_jni_callback;
static void friendrequest_callback(Tox *tox, uint8_t *publickey,
uint8_t *message, uint16_t *length, tox_jni_callback *data) {
printf("%s", "meh\n");
fflush(stdout);
JNIEnv *env = data->env; // Segfault
printf("%s", "muh\n");
fflush(stdout);
jstring str = (*env)->NewStringUTF(env, message);
jclass clazz = (*data->env)->GetObjectClass(data->env, data->jobj);
printf("%s", "Successfully got clazz\n");
fflush(stdout);
jmethodID method = (*data->env)->GetMethodID(data->env, clazz,
"executeOnFriendRequestCallback",
"(Ljava/lang/String;Ljava/lang/String;)V");
char address[ADDR_SIZE_HEX] = {0};
addr_to_hex(publickey, address);
jstring _address = (*data->env)->NewStringUTF(data->env, address);
jstring _message = (*data->env)->NewStringUTF(data->env, message);
(*data->env)->CallVoidMethod(data->env, data->jobj, method, _address, _message);
}
JNIEXPORT void JNICALL Java_im_tox_jtoxcore_JTox_tox_1callback_1friendrequest(
JNIEnv * env, jobject obj, jlong messenger) {
tox_jni_callback callback = { env, obj };
tox_callback_friendrequest((Tox *) messenger,
(void *) friendrequest_callback, &callback);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment