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

Unified Diff: content/browser/gamepad/platform_data_fetcher_linux.cc

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: fix typo 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/gamepad/platform_data_fetcher_linux.h ('k') | content/browser/udev_linux.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/gamepad/platform_data_fetcher_linux.cc
===================================================================
--- content/browser/gamepad/platform_data_fetcher_linux.cc (revision 148200)
+++ content/browser/gamepad/platform_data_fetcher_linux.cc (working copy)
@@ -19,6 +19,7 @@
#include "base/string_util.h"
#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
+#include "content/browser/udev_linux.h"
namespace {
@@ -71,30 +72,18 @@
device_fds_[i] = -1;
memset(mappers_, 0, sizeof(mappers_));
- udev_ = udev_new();
- CHECK(udev_);
+ std::vector<UdevLinux::UdevMonitorFilter> filters;
+ filters.push_back(
+ content::UdevLinux::UdevMonitorFilter(kInputSubsystem, NULL));
+ udev_.reset(
+ new UdevLinux(filters,
+ base::Bind(&GamepadPlatformDataFetcherLinux::RefreshDevice,
+ base::Unretained(this))));
- monitor_ = udev_monitor_new_from_netlink(udev_, "udev");
- CHECK(monitor_);
- int ret = udev_monitor_filter_add_match_subsystem_devtype(monitor_,
- kInputSubsystem,
- NULL);
- CHECK_EQ(0, ret);
- ret = udev_monitor_enable_receiving(monitor_);
- CHECK_EQ(0, ret);
- monitor_fd_ = udev_monitor_get_fd(monitor_);
- CHECK_GE(monitor_fd_, 0);
- bool success = MessageLoopForIO::current()->WatchFileDescriptor(monitor_fd_,
- true, MessageLoopForIO::WATCH_READ, &monitor_watcher_, this);
- CHECK(success);
-
EnumerateDevices();
}
GamepadPlatformDataFetcherLinux::~GamepadPlatformDataFetcherLinux() {
- monitor_watcher_.StopWatchingFileDescriptor();
- udev_monitor_unref(monitor_);
- udev_unref(udev_);
for (size_t i = 0; i < WebGamepads::itemsLengthCap; ++i)
CloseFileDescriptorIfValid(device_fds_[i]);
}
@@ -122,21 +111,6 @@
}
}
-void GamepadPlatformDataFetcherLinux::OnFileCanReadWithoutBlocking(int fd) {
- // Events occur when devices attached to the system are added, removed, or
- // change state. udev_monitor_receive_device() will return a device object
- // representing the device which changed and what type of change occured.
- DCHECK_EQ(monitor_fd_, fd);
- udev_device* dev = udev_monitor_receive_device(monitor_);
- if (!dev)
- return;
- RefreshDevice(dev);
- udev_device_unref(dev);
-}
-
-void GamepadPlatformDataFetcherLinux::OnFileCanWriteWithoutBlocking(int fd) {
-}
-
// Used during enumeration, and monitor notifications.
void GamepadPlatformDataFetcherLinux::RefreshDevice(udev_device* dev) {
int index;
@@ -223,7 +197,7 @@
}
void GamepadPlatformDataFetcherLinux::EnumerateDevices() {
- udev_enumerate* enumerate = udev_enumerate_new(udev_);
+ udev_enumerate* enumerate = udev_enumerate_new(udev_->udev_handle());
if (!enumerate)
return;
int ret = udev_enumerate_add_match_subsystem(enumerate, kInputSubsystem);
@@ -240,7 +214,7 @@
// Get the filename of the /sys entry for the device and create a
// udev_device object (dev) representing it
const char* path = udev_list_entry_get_name(dev_list_entry);
- udev_device* dev = udev_device_new_from_syspath(udev_, path);
+ udev_device* dev = udev_device_new_from_syspath(udev_->udev_handle(), path);
if (!dev)
continue;
RefreshDevice(dev);
« no previous file with comments | « content/browser/gamepad/platform_data_fetcher_linux.h ('k') | content/browser/udev_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698