blob: 314a2496c37daf6f056bb728b22d477744d01f33 [file] [log] [blame]
[email protected]26958d12014-02-27 17:29:101// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]125724f2014-01-31 20:13:232// 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
thakisacd68a22016-04-11 16:12:238#include <memory>
9
[email protected]bca53b02014-04-10 15:11:1410#include "base/compiler_specific.h"
[email protected]125724f2014-01-31 20:13:2311#include "base/macros.h"
[email protected]03b640fd2014-07-26 18:25:3812#include "base/memory/weak_ptr.h"
avi176e2692015-12-22 19:26:5213#include "build/build_config.h"
[email protected]125724f2014-01-31 20:13:2314#include "device/hid/hid_device_info.h"
15#include "device/hid/hid_service.h"
16
reillyge6aead12015-07-10 21:36:1017namespace dbus {
18class FileDescriptor;
19}
20
[email protected]125724f2014-01-31 20:13:2321namespace device {
22
23class HidConnection;
24
reillyg56868de2014-12-04 00:26:2725class HidServiceLinux : public HidService {
[email protected]125724f2014-01-31 20:13:2326 public:
rockot1a51b922014-09-05 08:02:4427 HidServiceLinux(scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner);
reillyg33338fc02015-08-28 23:41:0928 ~HidServiceLinux() override;
[email protected]125724f2014-01-31 20:13:2329
dcheng07c34a12014-10-29 18:55:1030 void Connect(const HidDeviceId& device_id,
31 const ConnectCallback& callback) override;
[email protected]125724f2014-01-31 20:13:2332
[email protected]125724f2014-01-31 20:13:2333 private:
reillyg56868de2014-12-04 00:26:2734 struct ConnectParams;
reillyg3497d2262015-01-12 22:05:4335 class FileThreadHelper;
reillyg56868de2014-12-04 00:26:2736
reillyg56868de2014-12-04 00:26:2737 // 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)
thakisacd68a22016-04-11 16:12:2342 static void OnPathOpenComplete(std::unique_ptr<ConnectParams> params,
reillygef3511f302016-02-10 01:53:0643 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);
thakisacd68a22016-04-11 16:12:2348 static void ValidateFdOnBlockingThread(std::unique_ptr<ConnectParams> params,
reillyge6aead12015-07-10 21:36:1049 dbus::FileDescriptor fd);
50#else
thakisacd68a22016-04-11 16:12:2351 static void OpenOnBlockingThread(std::unique_ptr<ConnectParams> params);
reillyge6aead12015-07-10 21:36:1052#endif
thakisacd68a22016-04-11 16:12:2353 static void FinishOpen(std::unique_ptr<ConnectParams> params);
54 static void CreateConnection(std::unique_ptr<ConnectParams> params);
[email protected]03b640fd2014-07-26 18:25:3855
reillyg7832a4e2014-10-11 01:52:4756 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
reillyg56868de2014-12-04 00:26:2757 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
[email protected]03b640fd2014-07-26 18:25:3858
reillyg56868de2014-12-04 00:26:2759 // The helper lives on the FILE thread and holds a weak reference back to the
60 // service that owns it.
reillyg87ac8da2015-08-25 18:22:5061 FileThreadHelper* helper_;
dmichael23a8043352014-12-12 19:01:4762 base::WeakPtrFactory<HidServiceLinux> weak_factory_;
[email protected]03b640fd2014-07-26 18:25:3863
[email protected]125724f2014-01-31 20:13:2364 DISALLOW_COPY_AND_ASSIGN(HidServiceLinux);
65};
66
67} // namespace device
68
69#endif // DEVICE_HID_HID_SERVICE_LINUX_H_