udev_gamepad_linux.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef DEVICE_GAMEPAD_UDEV_GAMEPAD_LINUX_H_
  5. #define DEVICE_GAMEPAD_UDEV_GAMEPAD_LINUX_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/strings/string_piece.h"
  9. extern "C" {
  10. struct udev_device;
  11. }
  12. namespace device {
  13. class UdevGamepadLinux {
  14. public:
  15. enum class Type {
  16. JOYDEV,
  17. EVDEV,
  18. HIDRAW,
  19. };
  20. static const char kInputSubsystem[];
  21. static const char kHidrawSubsystem[];
  22. UdevGamepadLinux(Type type,
  23. int index,
  24. base::StringPiece path,
  25. base::StringPiece syspath_prefix);
  26. ~UdevGamepadLinux() = default;
  27. // Factory method for creating UdevGamepadLinux instances. Extracts info
  28. // about the device and returns a UdevGamepadLinux describing it, or nullptr
  29. // if the device cannot be a gamepad.
  30. static std::unique_ptr<UdevGamepadLinux> Create(udev_device* dev);
  31. // The kernel interface used to communicate with this device.
  32. const Type type;
  33. // The index of this device node among nodes of this type. For instance, a
  34. // device with |path| /dev/input/js3 has |index| 3.
  35. const int index;
  36. // The filesystem path of the device node representing this device.
  37. const std::string path;
  38. // A string identifier used to identify device nodes that refer to the same
  39. // physical device. For nodes in the input subsystem (joydev and evdev), the
  40. // |syspath_prefix| is a prefix of the syspath of the parent node. For hidraw
  41. // nodes, it is a prefix of the node's syspath. |syspath_prefix| is empty if
  42. // the syspath could not be queried (usually this indicates the device has
  43. // been disconnected).
  44. const std::string syspath_prefix;
  45. };
  46. } // namespace device
  47. #endif // DEVICE_GAMEPAD_UDEV_GAMEPAD_LINUX_H_