OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 DEVICE_UDEV_LINUX_UDEV_WATCHER_H_ |
| 6 #define DEVICE_UDEV_LINUX_UDEV_WATCHER_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/files/file_descriptor_watcher_posix.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/sequence_checker.h" |
| 13 #include "device/udev_linux/scoped_udev.h" |
| 14 |
| 15 namespace device { |
| 16 |
| 17 // This class wraps an instance of udev_monitor, watching for devices that are |
| 18 // added and removed from the system. This class has sequence affinity. |
| 19 class UdevWatcher { |
| 20 public: |
| 21 class Observer { |
| 22 public: |
| 23 virtual ~Observer(); |
| 24 virtual void OnDeviceAdded(ScopedUdevDevicePtr device); |
| 25 virtual void OnDeviceRemoved(ScopedUdevDevicePtr device); |
| 26 }; |
| 27 |
| 28 static std::unique_ptr<UdevWatcher> StartWatching(Observer* observer); |
| 29 |
| 30 ~UdevWatcher(); |
| 31 |
| 32 // Synchronously enumerates the all devices known to udev, calling |
| 33 // OnDeviceAdded on the provided Observer for each. |
| 34 void EnumerateExistingDevices(); |
| 35 |
| 36 private: |
| 37 UdevWatcher(ScopedUdevPtr udev, |
| 38 ScopedUdevMonitorPtr udev_monitor, |
| 39 int monitor_fd, |
| 40 Observer* observer); |
| 41 |
| 42 void OnMonitorReadable(); |
| 43 |
| 44 ScopedUdevPtr udev_; |
| 45 ScopedUdevMonitorPtr udev_monitor_; |
| 46 Observer* observer_; |
| 47 std::unique_ptr<base::FileDescriptorWatcher::Controller> file_watcher_; |
| 48 base::SequenceChecker sequence_checker_; |
| 49 |
| 50 DISALLOW_COPY_AND_ASSIGN(UdevWatcher); |
| 51 }; |
| 52 |
| 53 } // namespace device |
| 54 |
| 55 #endif // DEVICE_UDEV_LINUX_UDEV_WATCHER_H_ |
OLD | NEW |