[email protected] | 26958d1 | 2014-02-27 17:29:10 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 125724f | 2014-01-31 20:13:23 | [diff] [blame] | 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_HID_SERVICE_LINUX_H_ | ||||
6 | #define DEVICE_HID_HID_SERVICE_LINUX_H_ | ||||
7 | |||||
thakis | acd68a2 | 2016-04-11 16:12:23 | [diff] [blame] | 8 | #include <memory> |
9 | |||||
[email protected] | bca53b0 | 2014-04-10 15:11:14 | [diff] [blame] | 10 | #include "base/compiler_specific.h" |
[email protected] | 125724f | 2014-01-31 20:13:23 | [diff] [blame] | 11 | #include "base/macros.h" |
[email protected] | 03b640fd | 2014-07-26 18:25:38 | [diff] [blame] | 12 | #include "base/memory/weak_ptr.h" |
avi | 176e269 | 2015-12-22 19:26:52 | [diff] [blame] | 13 | #include "build/build_config.h" |
[email protected] | 125724f | 2014-01-31 20:13:23 | [diff] [blame] | 14 | #include "device/hid/hid_device_info.h" |
15 | #include "device/hid/hid_service.h" | ||||
16 | |||||
reillyg | e6aead1 | 2015-07-10 21:36:10 | [diff] [blame] | 17 | namespace dbus { |
18 | class FileDescriptor; | ||||
19 | } | ||||
20 | |||||
[email protected] | 125724f | 2014-01-31 20:13:23 | [diff] [blame] | 21 | namespace device { |
22 | |||||
23 | class HidConnection; | ||||
24 | |||||
reillyg | 56868de | 2014-12-04 00:26:27 | [diff] [blame] | 25 | class HidServiceLinux : public HidService { |
[email protected] | 125724f | 2014-01-31 20:13:23 | [diff] [blame] | 26 | public: |
rockot | 1a51b92 | 2014-09-05 08:02:44 | [diff] [blame] | 27 | HidServiceLinux(scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); |
reillyg | 33338fc0 | 2015-08-28 23:41:09 | [diff] [blame] | 28 | ~HidServiceLinux() override; |
[email protected] | 125724f | 2014-01-31 20:13:23 | [diff] [blame] | 29 | |
dcheng | 07c34a1 | 2014-10-29 18:55:10 | [diff] [blame] | 30 | void Connect(const HidDeviceId& device_id, |
31 | const ConnectCallback& callback) override; | ||||
[email protected] | 125724f | 2014-01-31 20:13:23 | [diff] [blame] | 32 | |
[email protected] | 125724f | 2014-01-31 20:13:23 | [diff] [blame] | 33 | private: |
reillyg | 56868de | 2014-12-04 00:26:27 | [diff] [blame] | 34 | struct ConnectParams; |
reillyg | 3497d226 | 2015-01-12 22:05:43 | [diff] [blame] | 35 | class FileThreadHelper; |
reillyg | 56868de | 2014-12-04 00:26:27 | [diff] [blame] | 36 | |
reillyg | 56868de | 2014-12-04 00:26:27 | [diff] [blame] | 37 | // These functions implement the process of locating, requesting access to and |
38 | // opening a device. Because this operation crosses multiple threads these | ||||
39 | // functions are static and the necessary parameters are passed as a single | ||||
40 | // struct. | ||||
41 | #if defined(OS_CHROMEOS) | ||||
thakis | acd68a2 | 2016-04-11 16:12:23 | [diff] [blame] | 42 | static void OnPathOpenComplete(std::unique_ptr<ConnectParams> params, |
reillyg | ef3511f30 | 2016-02-10 01:53:06 | [diff] [blame] | 43 | dbus::FileDescriptor fd); |
44 | static void OnPathOpenError(const std::string& device_path, | ||||
45 | const ConnectCallback& callback, | ||||
46 | const std::string& error_name, | ||||
47 | const std::string& error_message); | ||||
thakis | acd68a2 | 2016-04-11 16:12:23 | [diff] [blame] | 48 | static void ValidateFdOnBlockingThread(std::unique_ptr<ConnectParams> params, |
reillyg | e6aead1 | 2015-07-10 21:36:10 | [diff] [blame] | 49 | dbus::FileDescriptor fd); |
50 | #else | ||||
thakis | acd68a2 | 2016-04-11 16:12:23 | [diff] [blame] | 51 | static void OpenOnBlockingThread(std::unique_ptr<ConnectParams> params); |
reillyg | e6aead1 | 2015-07-10 21:36:10 | [diff] [blame] | 52 | #endif |
thakis | acd68a2 | 2016-04-11 16:12:23 | [diff] [blame] | 53 | static void FinishOpen(std::unique_ptr<ConnectParams> params); |
54 | static void CreateConnection(std::unique_ptr<ConnectParams> params); | ||||
[email protected] | 03b640fd | 2014-07-26 18:25:38 | [diff] [blame] | 55 | |
reillyg | 7832a4e | 2014-10-11 01:52:47 | [diff] [blame] | 56 | scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
reillyg | 56868de | 2014-12-04 00:26:27 | [diff] [blame] | 57 | scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; |
[email protected] | 03b640fd | 2014-07-26 18:25:38 | [diff] [blame] | 58 | |
reillyg | 56868de | 2014-12-04 00:26:27 | [diff] [blame] | 59 | // The helper lives on the FILE thread and holds a weak reference back to the |
60 | // service that owns it. | ||||
reillyg | 87ac8da | 2015-08-25 18:22:50 | [diff] [blame] | 61 | FileThreadHelper* helper_; |
dmichael | 23a804335 | 2014-12-12 19:01:47 | [diff] [blame] | 62 | base::WeakPtrFactory<HidServiceLinux> weak_factory_; |
[email protected] | 03b640fd | 2014-07-26 18:25:38 | [diff] [blame] | 63 | |
[email protected] | 125724f | 2014-01-31 20:13:23 | [diff] [blame] | 64 | DISALLOW_COPY_AND_ASSIGN(HidServiceLinux); |
65 | }; | ||||
66 | |||||
67 | } // namespace device | ||||
68 | |||||
69 | #endif // DEVICE_HID_HID_SERVICE_LINUX_H_ |