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.
5 #ifndef DEVICE_HID_INPUT_SERVICE_LINUX_H_
6 #define DEVICE_HID_INPUT_SERVICE_LINUX_H_
11 #include "base/compiler_specific.h"
12 #include "base/containers/hash_tables.h"
13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop/message_loop.h"
16 #include "base/observer_list.h"
17 #include "base/threading/thread_checker.h"
18 #include "device/hid/device_monitor_linux.h"
22 // This class provides information and notifications about
23 // connected/disconnected input/HID devices. This class is *NOT*
24 // thread-safe and all methods must be called from the FILE thread.
25 class InputServiceLinux
: public base::MessageLoop::DestructionObserver
{
27 struct InputDeviceInfo
{
28 enum Subsystem
{ SUBSYSTEM_HID
, SUBSYSTEM_INPUT
, SUBSYSTEM_UNKNOWN
};
29 enum Type
{ TYPE_BLUETOOTH
, TYPE_USB
, TYPE_SERIO
, TYPE_UNKNOWN
};
38 bool is_accelerometer
: 1;
45 bool is_touchscreen
: 1;
49 using DeviceMap
= base::hash_map
<std::string
, InputDeviceInfo
>;
53 virtual ~Observer() {}
54 virtual void OnInputDeviceAdded(const InputDeviceInfo
& info
) = 0;
55 virtual void OnInputDeviceRemoved(const std::string
& id
) = 0;
59 ~InputServiceLinux() override
;
61 static InputServiceLinux
* GetInstance();
62 static bool HasInstance();
63 static void SetForTesting(InputServiceLinux
* service
);
65 void AddObserver(Observer
* observer
);
66 void RemoveObserver(Observer
* observer
);
68 // Returns list of all currently connected input/hid devices.
69 void GetDevices(std::vector
<InputDeviceInfo
>* devices
);
71 // Returns an info about input device identified by |id|. When there're
72 // no input or hid device with such id, returns false and doesn't
74 bool GetDeviceInfo(const std::string
& id
, InputDeviceInfo
* info
) const;
76 // Implements base::MessageLoop::DestructionObserver
77 void WillDestroyCurrentMessageLoop() override
;
81 void AddDevice(const InputDeviceInfo
& info
);
82 void RemoveDevice(const std::string
& id
);
84 bool CalledOnValidThread() const;
87 base::ObserverList
<Observer
> observers_
;
90 friend struct base::DefaultDeleter
<InputServiceLinux
>;
92 base::ThreadChecker thread_checker_
;
94 DISALLOW_COPY_AND_ASSIGN(InputServiceLinux
);
99 #endif // DEVICE_HID_INPUT_SERVICE_LINUX_H_