Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: content/browser/gamepad/platform_data_fetcher_linux.h

Issue 10824036: Linux: Refactor udev device monitoring code into its own class so it can be reused more easily. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_GAMEPAD_PLATFORM_DATA_FETCHER_LINUX_H_ 5 #ifndef CONTENT_BROWSER_GAMEPAD_PLATFORM_DATA_FETCHER_LINUX_H_
6 #define CONTENT_BROWSER_GAMEPAD_PLATFORM_DATA_FETCHER_LINUX_H_ 6 #define CONTENT_BROWSER_GAMEPAD_PLATFORM_DATA_FETCHER_LINUX_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/message_pump_libevent.h"
13 #include "build/build_config.h"
14 #include "content/browser/gamepad/data_fetcher.h" 12 #include "content/browser/gamepad/data_fetcher.h"
15 #include "content/browser/gamepad/gamepad_standard_mappings.h" 13 #include "content/browser/gamepad/gamepad_standard_mappings.h"
14 #include "content/browser/udev_linux.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads. h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads. h"
17 16
18 extern "C" {
19 struct udev;
20 struct udev_device;
21 struct udev_monitor;
22 }
23
24 namespace content { 17 namespace content {
25 18
26 class GamepadPlatformDataFetcherLinux : 19 class GamepadPlatformDataFetcherLinux : public GamepadDataFetcher,
27 public GamepadDataFetcher, 20 public UdevLinux {
28 public base::MessagePumpLibevent::Watcher {
29 public: 21 public:
30 GamepadPlatformDataFetcherLinux(); 22 GamepadPlatformDataFetcherLinux();
31 virtual ~GamepadPlatformDataFetcherLinux(); 23 virtual ~GamepadPlatformDataFetcherLinux();
32 24
33 // GamepadDataFetcher: 25 // GamepadDataFetcher implementation.
34 virtual void GetGamepadData(WebKit::WebGamepads* pads, 26 virtual void GetGamepadData(WebKit::WebGamepads* pads,
35 bool devices_changed_hint) OVERRIDE; 27 bool devices_changed_hint) OVERRIDE;
36 28
37 // base::MessagePump:Libevent::Watcher: 29 // UdevLinux implementation.
38 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; 30 virtual void Notify(udev_device* device) OVERRIDE;
39 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
40 31
41 private: 32 private:
42 void RefreshDevice(udev_device* dev); 33 void RefreshDevice(udev_device* dev);
43 void EnumerateDevices(); 34 void EnumerateDevices();
44 void ReadDeviceData(size_t index); 35 void ReadDeviceData(size_t index);
45 36
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. 37 // File descriptors for the /dev/input/js* devices. -1 if not in use.
54 int device_fds_[WebKit::WebGamepads::itemsLengthCap]; 38 int device_fds_[WebKit::WebGamepads::itemsLengthCap];
55 39
56 // Functions to map from device data to standard layout, if available. May 40 // Functions to map from device data to standard layout, if available. May
57 // be null if no mapping is available. 41 // be null if no mapping is available.
58 GamepadStandardMappingFunction mappers_[WebKit::WebGamepads::itemsLengthCap]; 42 GamepadStandardMappingFunction mappers_[WebKit::WebGamepads::itemsLengthCap];
59 43
60 // Data that's returned to the consumer. 44 // Data that's returned to the consumer.
61 WebKit::WebGamepads data_; 45 WebKit::WebGamepads data_;
62 46
63 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherLinux); 47 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherLinux);
64 }; 48 };
65 49
66 } // namespace content 50 } // namespace content
67 51
68 #endif // CONTENT_BROWSER_GAMEPAD_PLATFORM_DATA_FETCHER_LINUX_H_ 52 #endif // CONTENT_BROWSER_GAMEPAD_PLATFORM_DATA_FETCHER_LINUX_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/gamepad/platform_data_fetcher_linux.cc » ('j') | content/browser/udev_linux.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698