diff options
author | Javier <dev.git@javispedro.com> | 2020-02-16 22:18:38 +0100 |
---|---|---|
committer | Javier <dev.git@javispedro.com> | 2020-02-16 22:18:38 +0100 |
commit | 0a72437088b3e8387aa6ab77e20293bc2385788a (patch) | |
tree | d9add727dee224eda5d4d4823a08ce14e37f107f /app/src/main/cpp | |
parent | e88fb30dd01e64a0b2bfd1baec949b1836772fc0 (diff) | |
download | vndroid-0a72437088b3e8387aa6ab77e20293bc2385788a.tar.gz vndroid-0a72437088b3e8387aa6ab77e20293bc2385788a.zip |
update to sdk 29, migrate to androidx, new GUI
Diffstat (limited to 'app/src/main/cpp')
-rw-r--r-- | app/src/main/cpp/native-lib.cpp | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/app/src/main/cpp/native-lib.cpp b/app/src/main/cpp/native-lib.cpp index 3a1811c..6216181 100644 --- a/app/src/main/cpp/native-lib.cpp +++ b/app/src/main/cpp/native-lib.cpp @@ -41,6 +41,7 @@ struct Data jobject cb_obj; jmethodID cb_ev_ptr; jmethodID cb_ev_key; + jmethodID cb_ev_client; std::atomic<bool> pendingPtrEvent; int ptrButtonMask, ptrX, ptrY; @@ -48,6 +49,10 @@ struct Data std::atomic<bool> pendingKeyEvent; rfbKeySym key; bool keyState; + + std::atomic<bool> pendingClientEvent; + + unsigned int numClients; }; static inline Data * getData(JNIEnv *env, jobject instance) @@ -71,6 +76,16 @@ static inline Data * getData(rfbClientPtr client) return data; } +static void listen_thread_client_gone(rfbClientPtr client) +{ + Data *data = getData(client); + + data->numClients--; + data->pendingClientEvent = true; + + eventfd_write(data->eventEventFd, 1); +} + static void listen_thread_main(Data *data, JavaVM *vm) { rfbScreenInfoPtr screen = data->screen; @@ -104,11 +119,20 @@ static void listen_thread_main(Data *data, JavaVM *vm) else if (data->listenEventFd >= 0 && FD_ISSET(data->listenEventFd, &listen_fds)) break; - rfbClientPtr cl = NULL; - if(client_fd >= 0) - cl = rfbNewClient(screen,client_fd); - if (cl && !cl->onHold ) - rfbStartOnHoldClient(cl); + if(client_fd >= 0) { + rfbClientPtr cl = rfbNewClient(screen, client_fd); + if (cl) { + cl->clientGoneHook = listen_thread_client_gone; + + data->numClients++; + data->pendingClientEvent = true; + + eventfd_write(data->eventEventFd, 1); + + if (!cl->onHold) + rfbStartOnHoldClient(cl); + } + } } } @@ -134,6 +158,11 @@ static void event_thread_main(Data *data, JavaVM *vm) env->CallVoidMethod(data->cb_obj, data->cb_ev_key, (jint)data->key, (jboolean)data->keyState); data->pendingKeyEvent = false; } + + if (data->pendingClientEvent) { + env->CallVoidMethod(data->cb_obj, data->cb_ev_client); + data->pendingClientEvent = false; + } } vm->DetachCurrentThread(); @@ -150,6 +179,7 @@ static void ptr_event(int buttonMask, int x, int y, rfbClientPtr cl) eventfd_write(data->eventEventFd, 1); + // Still send the event to RFB, to do server-side cursor processing rfbDefaultPtrAddEvent(buttonMask, x, y, cl); } @@ -199,10 +229,13 @@ Java_com_javispedro_vndroid_RFBServer_allocate(JNIEnv *env, jobject instance) assert(data->cb_ev_ptr); data->cb_ev_key = env->GetMethodID(cb_cls, "onKeyEvent", "(IZ)V"); assert(data->cb_ev_key); + data->cb_ev_client = env->GetMethodID(cb_cls, "onClientEvent", "()V"); + assert(data->cb_ev_client); data->screen = 0; data->listenEventFd = -1; data->eventEventFd = -1; + data->numClients = 0; env->SetLongField(instance, fid, reinterpret_cast<jlong>(data)); @@ -359,3 +392,10 @@ Java_com_javispedro_vndroid_RFBServer_put_1image(JNIEnv *env, jobject instance, return JNI_TRUE; } + +extern "C" +JNIEXPORT jint JNICALL +Java_com_javispedro_vndroid_RFBServer_get_1num_1clients(JNIEnv *env, jobject instance) { + Data *data = getData(env, instance); + return data->numClients; +}
\ No newline at end of file |