Home | History | Annotate | Download | only in jni

Lines Matching refs:nat

133     native_data_t *nat = (native_data_t *)calloc(1, sizeof(native_data_t));
134 if (NULL == nat) {
138 memset(nat, 0, sizeof(native_data_t));
140 pthread_mutex_init(&(nat->thread_mutex), NULL);
142 env->SetIntField(object, field_mNativeData, (jint)nat);
148 nat->conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
153 dbus_connection_set_exit_on_disconnect(nat->conn, FALSE);
161 native_data_t *nat =
164 pthread_mutex_destroy(&(nat->thread_mutex));
166 if (nat) {
167 free(nat);
178 static int register_agent(native_data_t *nat,
199 static jboolean setUpEventLoop(native_data_t *nat) {
202 if (nat != NULL && nat->conn != NULL) {
208 if (!dbus_connection_add_filter(nat->conn, event_filter, nat, NULL)){
213 dbus_bus_add_match(nat->conn,
220 dbus_bus_add_match(nat->conn,
227 dbus_bus_add_match(nat->conn,
234 dbus_bus_add_match(nat->conn,
244 if (register_agent(nat, agent_path, capabilities) < 0) {
245 dbus_connection_unregister_object_path (nat->conn, agent_path);
309 static int register_agent(native_data_t *nat,
316 if (!dbus_connection_register_object_path(nat->conn, agent_path,
317 &agent_vtable, nat)) {
323 nat->adapter = get_adapter_path(nat->conn);
324 if (nat->adapter == NULL) {
327 msg = dbus_message_new_method_call("org.bluez", nat->adapter,
340 reply = dbus_connection_send_with_reply_and_block(nat->conn, msg, -1, &err);
352 dbus_connection_flush(nat->conn);
357 static void tearDownEventLoop(native_data_t *nat) {
359 if (nat != NULL && nat->conn != NULL) {
367 nat->adapter,
373 reply = dbus_connection_send_with_reply_and_block(nat->conn,
389 dbus_connection_flush(nat->conn);
390 dbus_connection_unregister_object_path(nat->conn, agent_path);
392 dbus_bus_remove_match(nat->conn,
398 dbus_bus_remove_match(nat->conn,
404 dbus_bus_remove_match(nat->conn,
410 dbus_bus_remove_match(nat->conn,
416 dbus_bus_remove_match(nat->conn,
423 dbus_connection_remove_filter(nat->conn, event_filter, nat);
433 native_data_t *nat = (native_data_t *)data;
441 write(nat->controlFdW, &control, sizeof(char));
444 write(nat->controlFdW, &fd, sizeof(int));
447 write(nat->controlFdW, &flags, sizeof(unsigned int));
449 write(nat
455 native_data_t *nat = (native_data_t *)data;
458 write(nat->controlFdW, &control, sizeof(char));
461 write(nat->controlFdW, &fd, sizeof(int));
464 write(nat->controlFdW, &flags, sizeof(unsigned int));
475 static void handleWatchAdd(native_data_t *nat) {
480 read(nat->controlFdR, &newFD, sizeof(int));
481 read(nat->controlFdR, &flags, sizeof(unsigned int));
482 read(nat->controlFdR, &watch, sizeof(DBusWatch *));
485 for (int y = 0; y<nat->pollMemberCount; y++) {
486 if ((nat->pollData[y].fd == newFD) &&
487 (nat->pollData[y].events == events)) {
492 if (nat->pollMemberCount == nat->pollDataSize) {
495 sizeof(struct pollfd) * (nat->pollMemberCount+1));
499 memcpy(temp, nat->pollData, sizeof(struct pollfd) *
500 nat->pollMemberCount);
501 free(nat->pollData);
502 nat->pollData = temp;
504 (nat->pollMemberCount+1));
508 memcpy(temp2, nat->watchData, sizeof(DBusWatch *) *
509 nat->pollMemberCount);
510 free(nat->watchData);
511 nat->watchData = temp2;
512 nat->pollDataSize++;
514 nat->pollData[nat->pollMemberCount].fd = newFD;
515 nat->pollData[nat->pollMemberCount].revents = 0;
516 nat->pollData[nat->pollMemberCount].events = events;
517 nat->watchData[nat->pollMemberCount] = watch;
518 nat->pollMemberCount++;
521 static void handleWatchRemove(native_data_t *nat) {
525 read(nat->controlFdR, &removeFD, sizeof(int));
526 read(nat->controlFdR, &flags, sizeof(unsigned int));
529 for (int y = 0; y < nat->pollMemberCount; y++) {
530 if ((nat->pollData[y].fd == removeFD) &&
531 (nat->pollData[y].events == events)) {
532 int newCount = --nat->pollMemberCount;
534 nat->pollData[y].fd = nat->pollData[newCount].fd;
535 nat->pollData[y].events = nat->pollData[newCount].events;
536 nat->pollData[y].revents = nat->pollData[newCount].revents;
537 nat->watchData[y] = nat->watchData[newCount];
545 native_data_t *nat = (native_data_t *)ptr;
550 args.version = nat->envVer;
554 nat->vm->AttachCurrentThread(&env, &args);
556 dbus_connection_set_watch_functions(nat->conn, dbusAddWatch,
559 nat->running = true;
562 for (int i = 0; i < nat->pollMemberCount; i++) {
563 if (!nat->pollData[i].revents) {
566 if (nat->pollData[i].fd == nat->controlFdR) {
568 while (recv(nat->controlFdR, &data, sizeof(char), MSG_DONTWAIT)
573 dbus_connection_set_watch_functions(nat->conn,
575 tearDownEventLoop(nat);
576 nat->vm->DetachCurrentThread();
578 int fd = nat->controlFdR;
579 nat->controlFdR = 0;
585 handleWatchAdd(nat);
590 handleWatchRemove(nat);
596 short events = nat->pollData[i].revents;
598 dbus_watch_handle(nat->watchData[i], flags);
599 nat->pollData[i].revents = 0;
604 while (dbus_connection_dispatch(nat->conn) ==
608 poll(nat->pollData, nat->pollMemberCount, -1);
616 event_loop_native_data_t *nat = get_native_data(env, object);
618 pthread_mutex_lock(&(nat->thread_mutex));
620 nat->running = false;
622 if (nat->pollData) {
624 pthread_mutex_unlock( &(nat->thread_mutex) );
628 nat->pollData = (struct pollfd *)malloc(sizeof(struct pollfd) *
630 if (!nat->pollData) {
635 nat->watchData = (DBusWatch **)malloc(sizeof(DBusWatch *) *
637 if (!nat->watchData) {
642 memset(nat->pollData, 0, sizeof(struct pollfd) *
644 memset(nat->watchData, 0, sizeof(DBusWatch *) *
646 nat->pollDataSize = DEFAULT_INITIAL_POLLFD_COUNT;
647 nat->pollMemberCount = 1;
649 if (socketpair(AF_LOCAL, SOCK_STREAM, 0, &(nat->controlFdR))) {
653 nat->pollData[0].fd = nat->controlFdR;
654 nat->pollData[0].events = POLLIN;
656 env->GetJavaVM( &(nat->vm) );
657 nat->envVer = env->GetVersion();
659 nat->me = env->NewGlobalRef(object);
661 if (setUpEventLoop(nat) != JNI_TRUE) {
666 pthread_create(&(nat->thread), NULL, eventLoopMain, nat);
671 if (nat->controlFdW) {
672 close(nat->controlFdW);
673 nat->controlFdW = 0;
675 if (nat->controlFdR) {
676 close(nat->controlFdR);
677 nat->controlFdR = 0;
679 if (nat->me) env->DeleteGlobalRef(nat->me);
680 nat->me = NULL;
681 if (nat->pollData) free(nat->pollData);
682 nat->pollData = NULL;
683 if (nat->watchData) free(nat->watchData);
684 nat->watchData = NULL;
685 nat->pollDataSize = 0;
686 nat->pollMemberCount = 0;
689 pthread_mutex_unlock(&(nat->thread_mutex));
696 native_data_t *nat = get_native_data(env, object);
698 pthread_mutex_lock(&(nat->thread_mutex));
699 if (nat->pollData) {
701 ssize_t t = write(nat->controlFdW, &data, sizeof(char));
703 pthread_join(nat->thread, &ret);
705 env->DeleteGlobalRef(nat->me);
706 nat->me = NULL;
707 free(nat->pollData);
708 nat->pollData = NULL;
709 free(nat->watchData);
710 nat->watchData = NULL;
711 nat->pollDataSize = 0;
712 nat->pollMemberCount = 0;
714 int fd = nat->controlFdW;
715 nat->controlFdW = 0;
718 nat->running = false;
719 pthread_mutex_unlock(&(nat->thread_mutex));
726 native_data_t *nat = get_native_data(env, object);
728 pthread_mutex_lock(&(nat->thread_mutex));
729 if (nat->running) {
732 pthread_mutex_unlock(&(nat->thread_mutex));
744 native_data_t *nat;
751 nat = (native_data_t *)data;
752 nat->vm->GetEnv((void**)&env, nat->envVer);
776 env->CallVoidMethod(nat->me,
791 env->CallVoidMethod(nat->me, method_onDeviceDisappeared,
803 env->CallVoidMethod(nat->me,
816 env->CallVoidMethod(nat->me,
834 nat->adapter = get_adapter_path(nat->conn);
839 env->CallVoidMethod(nat->me,
850 env->CallVoidMethod(nat->me,
860 env->CallVoidMethod(nat->me,
878 native_data_t *nat = (native_data_t *)data;
887 if (nat == NULL) return DBUS_HANDLER_RESULT_HANDLED;
889 nat->vm->GetEnv((void**)&env, nat->envVer);
894 env->CallVoidMethod(nat->me, method_onAgentCancel);
901 dbus_connection_send(nat->conn, reply, NULL);
921 env->CallBooleanMethod(nat->me, method_onAgentAuthorize,
939 env->CallBooleanMethod(nat->me, method_onAgentOutOfBandDataAvailable,
950 dbus_connection_send(nat->conn, reply, NULL);
959 dbus_connection_send(nat->conn, reply, NULL);
974 env->CallVoidMethod(nat->me, method_onRequestPinCode,
989 env->CallVoidMethod(nat->me, method_onRequestPasskey,
1004 env->CallVoidMethod(nat->me, method_onRequestOobData,
1021 env->CallVoidMethod(nat->me, method_onDisplayPasskey,
1039 env->CallVoidMethod(nat->me, method_onRequestPasskeyConfirmation,
1055 env->CallVoidMethod(nat->me, method_onRequestPairingConsent,
1067 dbus_connection_send(nat->conn, reply, NULL);
1101 native_data_t *nat = (native_data_t *)n;
1108 nat->vm->GetEnv((void**)&env, nat->envVer);
1157 env->CallVoidMethod(nat->me,
1170 native_data_t *nat = (native_data_t *)n;
1175 nat->vm->GetEnv((void**)&env, nat->envVer);
1189 env->CallVoidMethod(nat->me,
1200 native_data_t *nat = (native_data_t *)n;
1205 nat->vm->GetEnv((void**)&env, nat->envVer);
1215 env->CallVoidMethod(nat->me,
1227 native_data_t *nat = (native_data_t *) n;
1232 nat->vm->GetEnv((void**)&env, nat->envVer);
1248 env->CallVoidMethod(nat->me,