void jni_init() { try { net_thread = std::thread([] { if (!main_loop.init()) { return; } JNIEnv *env; bool attached = false; int status = java_vm->GetEnv((void **)&env, JNI_VERSION_1_4); if (status < 0) { LOGE("callback_handler: failed to get JNI environment, assuming native thread"); status = java_vm->AttachCurrentThread(&env, NULL); if (status < 0) { LOGE("callback_handler: failed to attach current thread"); } attached = true; } main_loop.loop(); if (attached) { java_vm->DetachCurrentThread(); } }); } catch (...) { } }
EventLoop* init_loop() { int ret; EventLoop *loop = new EventLoop(); ret = loop->init(); if(ret<0){ printf("error in inialize the loop\n"); delete loop; return NULL; } return loop; }