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_INPUT_SERVICE_LINUX_H_ | 5 #ifndef DEVICE_HID_INPUT_SERVICE_LINUX_H_ |
6 #define DEVICE_HID_INPUT_SERVICE_LINUX_H_ | 6 #define DEVICE_HID_INPUT_SERVICE_LINUX_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
17 #include "base/threading/thread_checker.h" | 17 |
Ken Rockot(use gerrit already)
2015/02/20 17:15:03
nit: no blank line
merkulova
2015/02/24 09:10:16
Done.
| |
18 #include "device/hid/device_monitor_linux.h" | 18 #include "device/hid/device_monitor_linux.h" |
19 | 19 |
20 namespace device { | 20 namespace device { |
21 | 21 |
22 // This class provides information and notifications about | 22 // This class provides information and notifications about |
23 // connected/disconnected input/HID devices. This class is *NOT* | 23 // connected/disconnected input/HID devices. This class is *NOT* |
24 // thread-safe and all methods must be called from the FILE thread. | 24 // thread-safe and all methods must be called from the FILE thread. |
25 class InputServiceLinux : public base::MessageLoop::DestructionObserver { | 25 class InputServiceLinux : public base::MessageLoop::DestructionObserver { |
26 public: | 26 public: |
27 struct InputDeviceInfo { | 27 struct InputDeviceInfo { |
(...skipping 10 matching lines...) Expand all Loading... | |
38 bool is_accelerometer : 1; | 38 bool is_accelerometer : 1; |
39 bool is_joystick : 1; | 39 bool is_joystick : 1; |
40 bool is_key : 1; | 40 bool is_key : 1; |
41 bool is_keyboard : 1; | 41 bool is_keyboard : 1; |
42 bool is_mouse : 1; | 42 bool is_mouse : 1; |
43 bool is_tablet : 1; | 43 bool is_tablet : 1; |
44 bool is_touchpad : 1; | 44 bool is_touchpad : 1; |
45 bool is_touchscreen : 1; | 45 bool is_touchscreen : 1; |
46 }; | 46 }; |
47 | 47 |
48 typedef base::hash_map<std::string, InputDeviceInfo> DeviceMap; | |
Ken Rockot(use gerrit already)
2015/02/20 17:15:03
nit: alias instead of typedef
merkulova
2015/02/24 09:10:16
Done.
| |
49 | |
48 class Observer { | 50 class Observer { |
49 public: | 51 public: |
50 virtual ~Observer() {} | 52 virtual ~Observer() {} |
51 virtual void OnInputDeviceAdded(const InputDeviceInfo& info) = 0; | 53 virtual void OnInputDeviceAdded(const InputDeviceInfo& info) = 0; |
52 virtual void OnInputDeviceRemoved(const std::string& id) = 0; | 54 virtual void OnInputDeviceRemoved(const std::string& id) = 0; |
53 }; | 55 }; |
54 | 56 |
55 InputServiceLinux(); | 57 InputServiceLinux(); |
58 ~InputServiceLinux() override; | |
56 | 59 |
57 static InputServiceLinux* GetInstance(); | 60 static InputServiceLinux* GetInstance(); |
58 static bool HasInstance(); | 61 static bool HasInstance(); |
59 static void SetForTesting(InputServiceLinux* service); | 62 static void SetForTesting(InputServiceLinux* service); |
60 | 63 |
61 void AddObserver(Observer* observer); | 64 virtual void AddObserver(Observer* observer); |
62 void RemoveObserver(Observer* observer); | 65 virtual void RemoveObserver(Observer* observer); |
63 | 66 |
64 // Returns list of all currently connected input/hid devices. | 67 // Returns list of all currently connected input/hid devices. |
65 void GetDevices(std::vector<InputDeviceInfo>* devices); | 68 virtual void GetDevices(std::vector<InputDeviceInfo>* devices); |
66 | 69 |
67 // Returns an info about input device identified by |id|. When there're | 70 // Returns an info about input device identified by |id|. When there're |
68 // no input or hid device with such id, returns false and doesn't | 71 // no input or hid device with such id, returns false and doesn't |
69 // modify |info|. | 72 // modify |info|. |
70 bool GetDeviceInfo(const std::string& id, InputDeviceInfo* info) const; | 73 virtual bool GetDeviceInfo( |
74 const std::string& id, InputDeviceInfo* info) const; | |
71 | 75 |
72 // Implements base::MessageLoop::DestructionObserver | 76 // Implements base::MessageLoop::DestructionObserver |
73 void WillDestroyCurrentMessageLoop() override; | 77 void WillDestroyCurrentMessageLoop() override; |
74 | 78 |
75 protected: | 79 protected: |
76 ~InputServiceLinux() override; | |
77 | 80 |
78 void AddDevice(const InputDeviceInfo& info); | 81 virtual void AddDevice(const InputDeviceInfo& info); |
79 void RemoveDevice(const std::string& id); | 82 virtual void RemoveDevice(const std::string& id); |
80 | 83 |
81 bool CalledOnValidThread() const; | 84 DeviceMap devices_; |
85 ObserverList<Observer> observers_; | |
82 | 86 |
83 private: | 87 private: |
84 friend struct base::DefaultDeleter<InputServiceLinux>; | 88 friend struct base::DefaultDeleter<InputServiceLinux>; |
85 | 89 |
86 typedef base::hash_map<std::string, InputDeviceInfo> DeviceMap; | |
87 | |
88 DeviceMap devices_; | |
89 ObserverList<Observer> observers_; | |
90 | |
91 base::ThreadChecker thread_checker_; | |
92 | |
93 DISALLOW_COPY_AND_ASSIGN(InputServiceLinux); | 90 DISALLOW_COPY_AND_ASSIGN(InputServiceLinux); |
94 }; | 91 }; |
95 | 92 |
96 } // namespace device | 93 } // namespace device |
97 | 94 |
98 #endif // DEVICE_HID_INPUT_SERVICE_LINUX_H_ | 95 #endif // DEVICE_HID_INPUT_SERVICE_LINUX_H_ |
OLD | NEW |