JNIEXPORT void JNICALL Java_org_a11y_BrlAPI_Native_closeConnection(JNIEnv *jenv, jobject jobj) { env = jenv; GET_HANDLE(jenv, jobj, ); brlapi__closeConnection(handle); free((void*) (intptr_t) handle); (*jenv)->SetLongField(jenv, jobj, handleID, (jlong) (intptr_t) NULL); }
static void baum_close(struct CharDriverState *chr) { BaumDriverState *baum = chr->opaque; timer_free(baum->cellCount_timer); if (baum->brlapi) { brlapi__closeConnection(baum->brlapi); g_free(baum->brlapi); } g_free(baum); }
CharDriverState *chr_baum_init(void) { BaumDriverState *baum; CharDriverState *chr; brlapi_handle_t *handle; #if defined(CONFIG_SDL) #if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0) SDL_SysWMinfo info; #endif #endif int tty; baum = g_malloc0(sizeof(BaumDriverState)); baum->chr = chr = qemu_chr_alloc(); chr->opaque = baum; chr->chr_write = baum_write; chr->chr_accept_input = baum_accept_input; chr->chr_close = baum_close; handle = g_malloc0(brlapi_getHandleSize()); baum->brlapi = handle; baum->brlapi_fd = brlapi__openConnection(handle, NULL, NULL); if (baum->brlapi_fd == -1) { brlapi_perror("baum_init: brlapi_openConnection"); goto fail_handle; } baum->cellCount_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, baum_cellCount_timer_cb, baum); if (brlapi__getDisplaySize(handle, &baum->x, &baum->y) == -1) { brlapi_perror("baum_init: brlapi_getDisplaySize"); goto fail; } #if defined(CONFIG_SDL) #if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0) memset(&info, 0, sizeof(info)); SDL_VERSION(&info.version); if (SDL_GetWMInfo(&info)) tty = info.info.x11.wmwindow; else #endif #endif tty = BRLAPI_TTY_DEFAULT; if (brlapi__enterTtyMode(handle, tty, NULL) == -1) { brlapi_perror("baum_init: brlapi_enterTtyMode"); goto fail; } qemu_set_fd_handler(baum->brlapi_fd, baum_chr_read, NULL, baum); return chr; fail: timer_free(baum->cellCount_timer); brlapi__closeConnection(handle); fail_handle: g_free(handle); g_free(chr); g_free(baum); return NULL; }
/* We got some data on the BrlAPI socket */ static void baum_chr_read(void *opaque) { BaumDriverState *baum = opaque; brlapi_keyCode_t code; int ret; if (!baum->brlapi) return; while ((ret = brlapi__readKey(baum->brlapi, 0, &code)) == 1) { DPRINTF("got key %"BRLAPI_PRIxKEYCODE"\n", code); /* Emulate */ switch (code & BRLAPI_KEY_TYPE_MASK) { case BRLAPI_KEY_TYPE_CMD: switch (code & BRLAPI_KEY_CMD_BLK_MASK) { case BRLAPI_KEY_CMD_ROUTE: baum_send_key(baum, BAUM_RSP_RoutingKey, (code & BRLAPI_KEY_CMD_ARG_MASK)+1); baum_send_key(baum, BAUM_RSP_RoutingKey, 0); break; case 0: switch (code & BRLAPI_KEY_CMD_ARG_MASK) { case BRLAPI_KEY_CMD_FWINLT: baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2); baum_send_key(baum, BAUM_RSP_TopKeys, 0); break; case BRLAPI_KEY_CMD_FWINRT: baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TR2); baum_send_key(baum, BAUM_RSP_TopKeys, 0); break; case BRLAPI_KEY_CMD_LNUP: baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TR1); baum_send_key(baum, BAUM_RSP_TopKeys, 0); break; case BRLAPI_KEY_CMD_LNDN: baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TR3); baum_send_key(baum, BAUM_RSP_TopKeys, 0); break; case BRLAPI_KEY_CMD_TOP: baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL1|BAUM_TR1); baum_send_key(baum, BAUM_RSP_TopKeys, 0); break; case BRLAPI_KEY_CMD_BOT: baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL3|BAUM_TR3); baum_send_key(baum, BAUM_RSP_TopKeys, 0); break; case BRLAPI_KEY_CMD_TOP_LEFT: baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2|BAUM_TR1); baum_send_key(baum, BAUM_RSP_TopKeys, 0); break; case BRLAPI_KEY_CMD_BOT_LEFT: baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2|BAUM_TR3); baum_send_key(baum, BAUM_RSP_TopKeys, 0); break; case BRLAPI_KEY_CMD_HOME: baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2|BAUM_TR1|BAUM_TR3); baum_send_key(baum, BAUM_RSP_TopKeys, 0); break; case BRLAPI_KEY_CMD_PREFMENU: baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL1|BAUM_TL3|BAUM_TR1); baum_send_key(baum, BAUM_RSP_TopKeys, 0); break; } } break; case BRLAPI_KEY_TYPE_SYM: break; } } if (ret == -1 && (brlapi_errno != BRLAPI_ERROR_LIBCERR || errno != EINTR)) { brlapi_perror("baum: brlapi_readKey"); brlapi__closeConnection(baum->brlapi); g_free(baum->brlapi); baum->brlapi = NULL; } }
CharDriverState *chr_baum_init(QemuOpts *opts) { BaumDriverState *baum; CharDriverState *chr; brlapi_handle_t *handle; #ifdef CONFIG_SDL SDL_SysWMinfo info; #endif int tty; baum = qemu_mallocz(sizeof(BaumDriverState)); baum->chr = chr = qemu_mallocz(sizeof(CharDriverState)); chr->opaque = baum; chr->chr_write = baum_write; chr->chr_send_event = baum_send_event; chr->chr_accept_input = baum_accept_input; handle = qemu_mallocz(brlapi_getHandleSize()); baum->brlapi = handle; baum->brlapi_fd = brlapi__openConnection(handle, NULL, NULL); if (baum->brlapi_fd == -1) { brlapi_perror("baum_init: brlapi_openConnection"); goto fail_handle; } baum->cellCount_timer = qemu_new_timer(vm_clock, baum_cellCount_timer_cb, baum); if (brlapi__getDisplaySize(handle, &baum->x, &baum->y) == -1) { brlapi_perror("baum_init: brlapi_getDisplaySize"); goto fail; } #ifdef CONFIG_SDL memset(&info, 0, sizeof(info)); SDL_VERSION(&info.version); if (SDL_GetWMInfo(&info)) tty = info.info.x11.wmwindow; else #endif tty = BRLAPI_TTY_DEFAULT; if (brlapi__enterTtyMode(handle, tty, NULL) == -1) { brlapi_perror("baum_init: brlapi_enterTtyMode"); goto fail; } qemu_set_fd_handler(baum->brlapi_fd, baum_chr_read, NULL, baum); qemu_chr_reset(chr); return chr; fail: qemu_free_timer(baum->cellCount_timer); brlapi__closeConnection(handle); fail_handle: free(handle); free(chr); free(baum); return NULL; }
static CharDriverState *chr_baum_init(const char *id, ChardevBackend *backend, ChardevReturn *ret, Error **errp) { ChardevCommon *common = backend->u.braille; BaumDriverState *baum; CharDriverState *chr; brlapi_handle_t *handle; #if defined(CONFIG_SDL) #if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0) SDL_SysWMinfo info; #endif #endif int tty; chr = qemu_chr_alloc(common, errp); if (!chr) { return NULL; } baum = g_malloc0(sizeof(BaumDriverState)); baum->chr = chr; chr->opaque = baum; chr->chr_write = baum_write; chr->chr_accept_input = baum_accept_input; chr->chr_close = baum_close; handle = g_malloc0(brlapi_getHandleSize()); baum->brlapi = handle; baum->brlapi_fd = brlapi__openConnection(handle, NULL, NULL); if (baum->brlapi_fd == -1) { error_setg(errp, "brlapi__openConnection: %s", brlapi_strerror(brlapi_error_location())); goto fail_handle; } baum->cellCount_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, baum_cellCount_timer_cb, baum); if (brlapi__getDisplaySize(handle, &baum->x, &baum->y) == -1) { error_setg(errp, "brlapi__getDisplaySize: %s", brlapi_strerror(brlapi_error_location())); goto fail; } #if defined(CONFIG_SDL) #if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0) memset(&info, 0, sizeof(info)); SDL_VERSION(&info.version); if (SDL_GetWMInfo(&info)) tty = info.info.x11.wmwindow; else #endif #endif tty = BRLAPI_TTY_DEFAULT; if (brlapi__enterTtyMode(handle, tty, NULL) == -1) { error_setg(errp, "brlapi__enterTtyMode: %s", brlapi_strerror(brlapi_error_location())); goto fail; } qemu_set_fd_handler(baum->brlapi_fd, baum_chr_read, NULL, baum); return chr; fail: timer_free(baum->cellCount_timer); brlapi__closeConnection(handle); fail_handle: g_free(handle); g_free(chr); g_free(baum); return NULL; }