OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef DEVICE_HID_DEVICE_MONITOR_LINUX_H_ | 5 #ifndef DEVICE_HID_DEVICE_MONITOR_LINUX_H_ |
6 #define DEVICE_HID_DEVICE_MONITOR_LINUX_H_ | 6 #define DEVICE_HID_DEVICE_MONITOR_LINUX_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/message_loop/message_pump_libevent.h" | 14 #include "base/message_loop/message_pump_libevent.h" |
15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
| 17 #include "device/core/device_core_export.h" |
17 #include "device/udev_linux/scoped_udev.h" | 18 #include "device/udev_linux/scoped_udev.h" |
18 | 19 |
19 struct udev_device; | 20 struct udev_device; |
20 | 21 |
21 namespace device { | 22 namespace device { |
22 | 23 |
23 // This class listends for notifications from libudev about | 24 // This class listends for notifications from libudev about |
24 // connected/disconnected devices. This class is *NOT* thread-safe and | 25 // connected/disconnected devices. This class is *NOT* thread-safe and |
25 // all methods must be accessed from the FILE thread. | 26 // all methods must be accessed from the FILE thread. |
26 class DeviceMonitorLinux : public base::MessageLoop::DestructionObserver, | 27 class DEVICE_CORE_EXPORT DeviceMonitorLinux |
27 public base::MessagePumpLibevent::Watcher { | 28 : public base::MessageLoop::DestructionObserver, |
| 29 public base::MessagePumpLibevent::Watcher { |
28 public: | 30 public: |
29 typedef base::Callback<void(udev_device* device)> EnumerateCallback; | 31 typedef base::Callback<void(udev_device* device)> EnumerateCallback; |
30 | 32 |
31 class Observer { | 33 class Observer { |
32 public: | 34 public: |
33 virtual ~Observer() {} | 35 virtual ~Observer() {} |
34 virtual void OnDeviceAdded(udev_device* device) = 0; | 36 virtual void OnDeviceAdded(udev_device* device) = 0; |
35 virtual void OnDeviceRemoved(udev_device* device) = 0; | 37 virtual void OnDeviceRemoved(udev_device* device) = 0; |
| 38 virtual void WillDestroyMonitorMessageLoop() = 0; |
36 }; | 39 }; |
37 | 40 |
38 DeviceMonitorLinux(); | 41 DeviceMonitorLinux(); |
39 | 42 |
40 static DeviceMonitorLinux* GetInstance(); | 43 static DeviceMonitorLinux* GetInstance(); |
41 static bool HasInstance(); | |
42 | 44 |
43 void AddObserver(Observer* observer); | 45 void AddObserver(Observer* observer); |
44 void RemoveObserver(Observer* observer); | 46 void RemoveObserver(Observer* observer); |
45 | 47 |
46 ScopedUdevDevicePtr GetDeviceFromPath(const std::string& path); | 48 ScopedUdevDevicePtr GetDeviceFromPath(const std::string& path); |
47 void Enumerate(const EnumerateCallback& callback); | 49 void Enumerate(const EnumerateCallback& callback); |
48 | 50 |
49 // Implements base::MessageLoop::DestructionObserver | 51 // Implements base::MessageLoop::DestructionObserver |
50 void WillDestroyCurrentMessageLoop() override; | 52 void WillDestroyCurrentMessageLoop() override; |
51 | 53 |
(...skipping 14 matching lines...) Expand all Loading... |
66 base::ObserverList<Observer, true> observers_; | 68 base::ObserverList<Observer, true> observers_; |
67 | 69 |
68 base::ThreadChecker thread_checker_; | 70 base::ThreadChecker thread_checker_; |
69 | 71 |
70 DISALLOW_COPY_AND_ASSIGN(DeviceMonitorLinux); | 72 DISALLOW_COPY_AND_ASSIGN(DeviceMonitorLinux); |
71 }; | 73 }; |
72 | 74 |
73 } // namespace device | 75 } // namespace device |
74 | 76 |
75 #endif // DEVICE_HID_DEVICE_MONITOR_LINUX_H_ | 77 #endif // DEVICE_HID_DEVICE_MONITOR_LINUX_H_ |
OLD | NEW |