static bool linuxraw_joypad_init(void *data) { unsigned i; settings_t *settings = config_get_ptr(); g_epoll = epoll_create(MAX_USERS + 1); if (g_epoll < 0) return false; (void)data; for (i = 0; i < MAX_USERS; i++) { char path[PATH_MAX_LENGTH] = {0}; autoconfig_params_t params = {{0}}; struct linuxraw_joypad *pad = (struct linuxraw_joypad*)&linuxraw_pads[i]; if (!pad) continue; params.idx = i; pad->fd = -1; pad->ident = settings->input.device_names[i]; snprintf(path, sizeof(path), "/dev/input/js%u", i); if (linuxraw_joypad_init_pad(path, pad)) { strlcpy(params.name, pad->ident, sizeof(params.name)); strlcpy(params.driver, "linuxraw", sizeof(params.driver)); /* TODO - implement VID/PID? */ input_config_autoconfigure_joypad(¶ms); linuxraw_poll_pad(pad); } else input_config_autoconfigure_joypad(¶ms); } g_notify = inotify_init(); if (g_notify >= 0) { struct epoll_event event; linuxraw_joypad_setup_notify(); event.events = EPOLLIN; event.data.ptr = NULL; epoll_ctl(g_epoll, EPOLL_CTL_ADD, g_notify, &event); } g_hotplug = true; return true; }
static bool linuxraw_joypad_init(void *data) { unsigned i; settings_t *settings = config_get_ptr(); if (!epoll_new(true)) return false; (void)data; for (i = 0; i < MAX_USERS; i++) { char path[PATH_MAX_LENGTH] = {0}; autoconfig_params_t params = {{0}}; struct linuxraw_joypad *pad = (struct linuxraw_joypad*)&linuxraw_pads[i]; if (!pad) continue; params.idx = i; pad->fd = -1; pad->ident = settings->input.device_names[i]; snprintf(path, sizeof(path), "/dev/input/js%u", i); if (linuxraw_joypad_init_pad(path, pad)) { strlcpy(params.name, pad->ident, sizeof(params.name)); strlcpy(params.driver, "linuxraw", sizeof(params.driver)); /* TODO - implement VID/PID? */ input_config_autoconfigure_joypad(¶ms); linuxraw_poll_pad(pad); } else input_config_autoconfigure_joypad(¶ms); } g_inotify = inotify_init(); if (g_inotify >= 0) { fcntl(g_inotify, F_SETFL, fcntl(g_inotify, F_GETFL) | O_NONBLOCK); inotify_add_watch(g_inotify, "/dev/input", IN_DELETE | IN_CREATE | IN_ATTRIB); epoll_add(g_inotify, NULL); } g_hotplug = true; return true; }
static void linuxraw_joypad_poll(void) { int i, ret; struct epoll_event events[MAX_USERS + 1]; retry: ret = epoll_wait(g_epoll, events, MAX_USERS + 1, 0); if (ret < 0 && errno == EINTR) goto retry; for (i = 0; i < ret; i++) { if (events[i].data.ptr) linuxraw_poll_pad((struct linuxraw_joypad*)events[i].data.ptr); else handle_plugged_pad(); } }