OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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_HID_DEVICE_MONITOR_LINUX_H_ |
| 6 #define DEVICE_HID_DEVICE_MONITOR_LINUX_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/compiler_specific.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/message_loop/message_pump_libevent.h" |
| 13 #include "base/observer_list.h" |
| 14 #include "device/hid/udev_common.h" |
| 15 |
| 16 struct udev_device; |
| 17 |
| 18 namespace device { |
| 19 |
| 20 class DeviceMonitorLinux : public base::MessagePumpLibevent::Watcher { |
| 21 public: |
| 22 typedef base::Callback<void(udev_device* device)> EnumerateCallback; |
| 23 |
| 24 class Observer { |
| 25 public: |
| 26 virtual ~Observer() {} |
| 27 virtual void OnDeviceAdded(udev_device* device) = 0; |
| 28 virtual void OnDeviceRemoved(udev_device* device) = 0; |
| 29 }; |
| 30 |
| 31 DeviceMonitorLinux(); |
| 32 virtual ~DeviceMonitorLinux(); |
| 33 |
| 34 static DeviceMonitorLinux* GetInstance(); |
| 35 static bool HasInstance(); |
| 36 |
| 37 void AddObserver(Observer* observer); |
| 38 void RemoveObserver(Observer* observer); |
| 39 |
| 40 ScopedUdevDevicePtr GetDeviceFromPath(const std::string& path); |
| 41 void Enumerate(const EnumerateCallback& callback); |
| 42 |
| 43 // Implements base::MessagePumpLibevent::Watcher |
| 44 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; |
| 45 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; |
| 46 |
| 47 private: |
| 48 ScopedUdevPtr udev_; |
| 49 ScopedUdevMonitorPtr monitor_; |
| 50 int monitor_fd_; |
| 51 base::MessagePumpLibevent::FileDescriptorWatcher monitor_watcher_; |
| 52 |
| 53 ObserverList<Observer> observers_; |
| 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(DeviceMonitorLinux); |
| 56 }; |
| 57 |
| 58 } // namespace device |
| 59 |
| 60 #endif // DEVICE_HID_DEVICE_MONITOR_LINUX_H_ |
OLD | NEW |