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.
5 #include "content/browser/udev_linux.h"
9 #include "base/message_loop/message_loop.h"
13 UdevLinux::UdevLinux(const std::vector
<UdevMonitorFilter
>& filters
,
14 const UdevNotificationCallback
& callback
)
16 monitor_(udev_monitor_new_from_netlink(udev_
.get(), "udev")),
22 for (size_t i
= 0; i
< filters
.size(); ++i
) {
23 int ret
= udev_monitor_filter_add_match_subsystem_devtype(
24 monitor_
.get(), filters
[i
].subsystem
, filters
[i
].devtype
);
28 int ret
= udev_monitor_enable_receiving(monitor_
.get());
30 monitor_fd_
= udev_monitor_get_fd(monitor_
.get());
31 CHECK_GE(monitor_fd_
, 0);
33 bool success
= base::MessageLoopForIO::current()->WatchFileDescriptor(
36 base::MessageLoopForIO::WATCH_READ
,
42 UdevLinux::~UdevLinux() {
43 monitor_watcher_
.StopWatchingFileDescriptor();
46 udev
* UdevLinux::udev_handle() {
50 void UdevLinux::OnFileCanReadWithoutBlocking(int fd
) {
51 // Events occur when devices attached to the system are added, removed, or
52 // change state. udev_monitor_receive_device() will return a device object
53 // representing the device which changed and what type of change occured.
54 DCHECK_EQ(monitor_fd_
, fd
);
55 device::ScopedUdevDevicePtr
dev(
56 udev_monitor_receive_device(monitor_
.get()));
60 callback_
.Run(dev
.get());
63 void UdevLinux::OnFileCanWriteWithoutBlocking(int fd
) {
66 } // namespace content