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

Side by Side Diff: content/browser/udev_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: Created 8 years, 4 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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 #include "content/browser/udev_linux.h"
6
7 #include <libudev.h>
8
9 #include "base/message_loop.h"
10
11 namespace content {
12
13 UdevLinux::UdevLinux() {
14 udev_ = udev_new();
15 CHECK(udev_);
16
17 monitor_ = udev_monitor_new_from_netlink(udev_, "udev");
18 CHECK(monitor_);
19 }
20
21 UdevLinux::~UdevLinux() {
22 monitor_watcher_.StopWatchingFileDescriptor();
23 udev_monitor_unref(monitor_);
24 udev_unref(udev_);
25 }
26
27 void UdevLinux::StartMonitoring() {
28 int ret = udev_monitor_enable_receiving(monitor_);
29 CHECK_EQ(0, ret);
30 monitor_fd_ = udev_monitor_get_fd(monitor_);
31 CHECK_GE(monitor_fd_, 0);
32 bool success = MessageLoopForIO::current()->WatchFileDescriptor(monitor_fd_,
33 true, MessageLoopForIO::WATCH_READ, &monitor_watcher_, this);
34 CHECK(success);
35 }
36
37 udev* UdevLinux::udev_handle() {
38 return udev_;
39 }
40
41 udev_monitor* UdevLinux::monitor() {
42 return monitor_;
43 }
44
45 void UdevLinux::OnFileCanReadWithoutBlocking(int fd) {
46 // Events occur when devices attached to the system are added, removed, or
47 // change state. udev_monitor_receive_device() will return a device object
48 // representing the device which changed and what type of change occured.
49 DCHECK_EQ(monitor_fd_, fd);
50 udev_device* dev = udev_monitor_receive_device(monitor_);
51 if (!dev) {
52 NOTREACHED();
53 return;
54 }
55 Notify(dev);
56 udev_device_unref(dev);
57 }
58
59 void UdevLinux::OnFileCanWriteWithoutBlocking(int fd) {
60 }
61
62 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698