31 #ifdef SDL_USE_LIBUDEV
33 static char* SDL_UDEV_LIBS[] = {
"libudev.so.1",
"libudev.so.0" };
35 #define _THIS SDL_UDEV_PrivateData *_this
40 static SDL_bool SDL_UDEV_load_sym(
const char *fn,
void **
addr);
41 static int SDL_UDEV_load_syms(
void);
42 static SDL_bool SDL_UDEV_hotplug_update_available(
void);
43 static void device_event(SDL_UDEV_deviceevent
type,
struct udev_device *dev);
46 SDL_UDEV_load_sym(
const char *fn,
void **
addr)
58 SDL_UDEV_load_syms(
void)
61 #define SDL_UDEV_SYM(x) \
62 if (!SDL_UDEV_load_sym(#x, (void **) (char *) & _this->x)) return -1
64 SDL_UDEV_SYM(udev_device_get_action);
65 SDL_UDEV_SYM(udev_device_get_devnode);
66 SDL_UDEV_SYM(udev_device_get_subsystem);
67 SDL_UDEV_SYM(udev_device_get_property_value);
68 SDL_UDEV_SYM(udev_device_new_from_syspath);
69 SDL_UDEV_SYM(udev_device_unref);
70 SDL_UDEV_SYM(udev_enumerate_add_match_property);
71 SDL_UDEV_SYM(udev_enumerate_add_match_subsystem);
72 SDL_UDEV_SYM(udev_enumerate_get_list_entry);
73 SDL_UDEV_SYM(udev_enumerate_new);
74 SDL_UDEV_SYM(udev_enumerate_scan_devices);
75 SDL_UDEV_SYM(udev_enumerate_unref);
76 SDL_UDEV_SYM(udev_list_entry_get_name);
77 SDL_UDEV_SYM(udev_list_entry_get_next);
78 SDL_UDEV_SYM(udev_monitor_enable_receiving);
79 SDL_UDEV_SYM(udev_monitor_filter_add_match_subsystem_devtype);
80 SDL_UDEV_SYM(udev_monitor_get_fd);
81 SDL_UDEV_SYM(udev_monitor_new_from_netlink);
82 SDL_UDEV_SYM(udev_monitor_receive_device);
83 SDL_UDEV_SYM(udev_monitor_unref);
84 SDL_UDEV_SYM(udev_new);
85 SDL_UDEV_SYM(udev_unref);
86 SDL_UDEV_SYM(udev_device_new_from_devnum);
87 SDL_UDEV_SYM(udev_device_get_devnum);
94 SDL_UDEV_hotplug_update_available(
void)
97 const int fd =
_this->udev_monitor_get_fd(
_this->udev_mon);
105 if ((select(fd+1, &fds,
NULL,
NULL, &tv) > 0) && (FD_ISSET(fd, &fds))) {
124 retval = SDL_UDEV_LoadLibrary();
140 _this->udev_mon =
_this->udev_monitor_new_from_netlink(
_this->udev,
"udev");
143 return SDL_SetError(
"udev_monitor_new_from_netlink() failed");
146 _this->udev_monitor_filter_add_match_subsystem_devtype(
_this->udev_mon,
"input",
NULL);
147 _this->udev_monitor_filter_add_match_subsystem_devtype(
_this->udev_mon,
"sound",
NULL);
148 _this->udev_monitor_enable_receiving(
_this->udev_mon);
155 _this->ref_count += 1;
163 SDL_UDEV_CallbackList *item;
169 _this->ref_count -= 1;
171 if (
_this->ref_count < 1) {
189 SDL_UDEV_UnloadLibrary();
198 struct udev_enumerate *enumerate =
NULL;
199 struct udev_list_entry *devs =
NULL;
200 struct udev_list_entry *item =
NULL;
206 enumerate =
_this->udev_enumerate_new(
_this->udev);
207 if (enumerate ==
NULL) {
213 _this->udev_enumerate_add_match_subsystem(enumerate,
"input");
214 _this->udev_enumerate_add_match_subsystem(enumerate,
"sound");
216 _this->udev_enumerate_scan_devices(enumerate);
217 devs =
_this->udev_enumerate_get_list_entry(enumerate);
218 for (item = devs; item; item =
_this->udev_list_entry_get_next(item)) {
219 const char *
path =
_this->udev_list_entry_get_name(item);
220 struct udev_device *dev =
_this->udev_device_new_from_syspath(
_this->udev, path);
222 device_event(SDL_UDEV_DEVICEADDED, dev);
223 _this->udev_device_unref(dev);
227 _this->udev_enumerate_unref(enumerate);
232 SDL_UDEV_UnloadLibrary(
void)
245 SDL_UDEV_LoadLibrary(
void)
258 retval = SDL_UDEV_load_syms();
260 SDL_UDEV_UnloadLibrary();
278 device_event(SDL_UDEV_deviceevent
type,
struct udev_device *dev)
280 const char *subsystem;
282 SDL_UDEV_deviceclass devclass = 0;
284 SDL_UDEV_CallbackList *item;
286 path =
_this->udev_device_get_devnode(dev);
291 subsystem =
_this->udev_device_get_subsystem(dev);
293 devclass = SDL_UDEV_DEVICE_SOUND;
295 else if (
SDL_strcmp(subsystem,
"input") == 0) {
296 val =
_this->udev_device_get_property_value(dev,
"ID_INPUT_JOYSTICK");
298 devclass = SDL_UDEV_DEVICE_JOYSTICK;
302 val =
_this->udev_device_get_property_value(dev,
"ID_INPUT_MOUSE");
304 devclass = SDL_UDEV_DEVICE_MOUSE;
309 val =
_this->udev_device_get_property_value(dev,
"ID_INPUT_KEYBOARD");
311 devclass = SDL_UDEV_DEVICE_KEYBOARD;
324 for (item =
_this->first; item !=
NULL; item = item->next) {
325 item->callback(type, devclass, path);
332 struct udev_device *dev =
NULL;
333 const char *action =
NULL;
339 while (SDL_UDEV_hotplug_update_available()) {
340 dev =
_this->udev_monitor_receive_device(
_this->udev_mon);
344 action =
_this->udev_device_get_action(dev);
347 device_event(SDL_UDEV_DEVICEADDED, dev);
348 }
else if (
SDL_strcmp(action,
"remove") == 0) {
349 device_event(SDL_UDEV_DEVICEREMOVED, dev);
352 _this->udev_device_unref(dev);
357 SDL_UDEV_AddCallback(SDL_UDEV_Callback cb)
359 SDL_UDEV_CallbackList *item;
360 item = (SDL_UDEV_CallbackList *)
SDL_calloc(1,
sizeof (SDL_UDEV_CallbackList));
370 _this->last->next = item;
378 SDL_UDEV_DelCallback(SDL_UDEV_Callback cb)
380 SDL_UDEV_CallbackList *item;
381 SDL_UDEV_CallbackList *prev =
NULL;
383 for (item =
_this->first; item !=
NULL; item = item->next) {
385 if (item->callback == cb) {
387 prev->next = item->next;
390 _this->first = item->next;
392 if (item ==
_this->last) {
GLuint const GLfloat * val
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size)
DECLSPEC void SDLCALL SDL_free(void *mem)
GLsizei const GLchar *const * path
static SDL_VideoDevice * _this
DECLSPEC void *SDLCALL SDL_LoadObject(const char *sofile)
DECLSPEC void SDLCALL SDL_UnloadObject(void *handle)
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2)
#define SDL_assert(condition)
#define SDL_OutOfMemory()
#define SDL_arraysize(array)
DECLSPEC void *SDLCALL SDL_LoadFunction(void *handle, const char *name)