OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 |
| 5 #ifndef CONTENT_BROWSER_GAMEPAD_DATA_FETCHER_LINUX_H_ |
| 6 #define CONTENT_BROWSER_GAMEPAD_DATA_FETCHER_LINUX_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/compiler_specific.h" |
| 11 #include "base/message_pump_libevent.h" |
| 12 #include "build/build_config.h" |
| 13 #include "content/browser/gamepad/data_fetcher.h" |
| 14 #include "content/browser/gamepad/gamepad_standard_mappings_linux.h" |
| 15 #include "content/common/gamepad_hardware_buffer.h" |
| 16 |
| 17 extern "C" { |
| 18 struct udev; |
| 19 struct udev_device; |
| 20 struct udev_monitor; |
| 21 } |
| 22 |
| 23 namespace content { |
| 24 |
| 25 class GamepadPlatformDataFetcherLinux : |
| 26 public GamepadDataFetcher, |
| 27 public base::MessagePumpLibevent::Watcher { |
| 28 public: |
| 29 GamepadPlatformDataFetcherLinux(); |
| 30 virtual ~GamepadPlatformDataFetcherLinux(); |
| 31 |
| 32 // GamepadDataFetcher: |
| 33 virtual void GetGamepadData(WebKit::WebGamepads* pads, |
| 34 bool devices_changed_hint) OVERRIDE; |
| 35 |
| 36 // base::MessagePump:Libevent::Watcher: |
| 37 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; |
| 38 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; |
| 39 |
| 40 private: |
| 41 bool IsGamepad(udev_device* dev, int& index, std::string& path); |
| 42 void RefreshDevice(udev_device* dev); |
| 43 void EnumerateDevices(); |
| 44 void ReadDeviceData(size_t index); |
| 45 |
| 46 // libudev-related items, the main context, and the monitoring context to be |
| 47 // notified about changes to device states. |
| 48 udev* udev_; |
| 49 udev_monitor* monitor_; |
| 50 int monitor_fd_; |
| 51 base::MessagePumpLibevent::FileDescriptorWatcher monitor_watcher_; |
| 52 |
| 53 // File descriptors for the /dev/input/js* devices. -1 if not in use. |
| 54 int device_fds_[WebKit::WebGamepads::itemsLengthCap]; |
| 55 |
| 56 // Functions to map from device data to standard layout, if available. May |
| 57 // be null if no mapping is available. |
| 58 GamepadStandardMappingFunction mappers_[WebKit::WebGamepads::itemsLengthCap]; |
| 59 |
| 60 // Data that's returned to the consumer. |
| 61 WebKit::WebGamepads data_; |
| 62 }; |
| 63 |
| 64 } // namespace content |
| 65 |
| 66 #endif // CONTENT_BROWSER_GAMEPAD_DATA_FETCHER_LINUX_H_ |
OLD | NEW |