SDL_udev.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "SDL_internal.h"
  19. #ifndef SDL_udev_h_
  20. #define SDL_udev_h_
  21. #if defined(HAVE_LIBUDEV_H) && defined(HAVE_LINUX_INPUT_H)
  22. #ifndef SDL_USE_LIBUDEV
  23. #define SDL_USE_LIBUDEV 1
  24. #endif
  25. #include <libudev.h>
  26. #include <sys/time.h>
  27. #include <sys/types.h>
  28. /**
  29. * Device type
  30. */
  31. typedef enum
  32. {
  33. SDL_UDEV_DEVICEADDED = 1,
  34. SDL_UDEV_DEVICEREMOVED
  35. } SDL_UDEV_deviceevent;
  36. typedef void (*SDL_UDEV_Callback)(SDL_UDEV_deviceevent udev_type, int udev_class, const char *devpath);
  37. typedef struct SDL_UDEV_CallbackList
  38. {
  39. SDL_UDEV_Callback callback;
  40. struct SDL_UDEV_CallbackList *next;
  41. } SDL_UDEV_CallbackList;
  42. typedef struct SDL_UDEV_Symbols
  43. {
  44. const char *(*udev_device_get_action)(struct udev_device *);
  45. const char *(*udev_device_get_devnode)(struct udev_device *);
  46. const char *(*udev_device_get_syspath)(struct udev_device *);
  47. const char *(*udev_device_get_subsystem)(struct udev_device *);
  48. struct udev_device *(*udev_device_get_parent_with_subsystem_devtype)(struct udev_device *udev_device, const char *subsystem, const char *devtype);
  49. const char *(*udev_device_get_property_value)(struct udev_device *, const char *);
  50. const char *(*udev_device_get_sysattr_value)(struct udev_device *udev_device, const char *sysattr);
  51. struct udev_device *(*udev_device_new_from_syspath)(struct udev *, const char *);
  52. void (*udev_device_unref)(struct udev_device *);
  53. int (*udev_enumerate_add_match_property)(struct udev_enumerate *, const char *, const char *);
  54. int (*udev_enumerate_add_match_subsystem)(struct udev_enumerate *, const char *);
  55. struct udev_list_entry *(*udev_enumerate_get_list_entry)(struct udev_enumerate *);
  56. struct udev_enumerate *(*udev_enumerate_new)(struct udev *);
  57. int (*udev_enumerate_scan_devices)(struct udev_enumerate *);
  58. void (*udev_enumerate_unref)(struct udev_enumerate *);
  59. const char *(*udev_list_entry_get_name)(struct udev_list_entry *);
  60. struct udev_list_entry *(*udev_list_entry_get_next)(struct udev_list_entry *);
  61. int (*udev_monitor_enable_receiving)(struct udev_monitor *);
  62. int (*udev_monitor_filter_add_match_subsystem_devtype)(struct udev_monitor *, const char *, const char *);
  63. int (*udev_monitor_get_fd)(struct udev_monitor *);
  64. struct udev_monitor *(*udev_monitor_new_from_netlink)(struct udev *, const char *);
  65. struct udev_device *(*udev_monitor_receive_device)(struct udev_monitor *);
  66. void (*udev_monitor_unref)(struct udev_monitor *);
  67. struct udev *(*udev_new)(void);
  68. void (*udev_unref)(struct udev *);
  69. struct udev_device *(*udev_device_new_from_devnum)(struct udev *udev, char type, dev_t devnum);
  70. dev_t (*udev_device_get_devnum)(struct udev_device *udev_device);
  71. } SDL_UDEV_Symbols;
  72. typedef struct SDL_UDEV_PrivateData
  73. {
  74. const char *udev_library;
  75. SDL_SharedObject *udev_handle;
  76. struct udev *udev;
  77. struct udev_monitor *udev_mon;
  78. int ref_count;
  79. SDL_UDEV_CallbackList *first, *last;
  80. // Function pointers
  81. SDL_UDEV_Symbols syms;
  82. } SDL_UDEV_PrivateData;
  83. extern bool SDL_UDEV_Init(void);
  84. extern void SDL_UDEV_Quit(void);
  85. extern void SDL_UDEV_UnloadLibrary(void);
  86. extern bool SDL_UDEV_LoadLibrary(void);
  87. extern void SDL_UDEV_Poll(void);
  88. extern bool SDL_UDEV_Scan(void);
  89. extern bool SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16 *product, Uint16 *version, int *class);
  90. extern bool SDL_UDEV_AddCallback(SDL_UDEV_Callback cb);
  91. extern void SDL_UDEV_DelCallback(SDL_UDEV_Callback cb);
  92. extern const SDL_UDEV_Symbols *SDL_UDEV_GetUdevSyms(void);
  93. extern void SDL_UDEV_ReleaseUdevSyms(void);
  94. #endif // HAVE_LIBUDEV_H && HAVE_LINUX_INPUT_H
  95. #endif // SDL_udev_h_