blob: 66cfbd3a4412a8982c4cff06666b2f35f09e4800 [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
[email protected]bca53b02014-04-10 15:11:148#include "base/compiler_specific.h"
[email protected]125724f2014-01-31 20:13:239#include "base/macros.h"
[email protected]03b640fd2014-07-26 18:25:3810#include "base/memory/weak_ptr.h"
[email protected]125724f2014-01-31 20:13:2311#include "device/hid/hid_device_info.h"
12#include "device/hid/hid_service.h"
13
reillyge6aead12015-07-10 21:36:1014namespace dbus {
15class FileDescriptor;
16}
17
[email protected]125724f2014-01-31 20:13:2318namespace device {
19
20class HidConnection;
21
reillyg56868de2014-12-04 00:26:2722class HidServiceLinux : public HidService {
[email protected]125724f2014-01-31 20:13:2323 public:
rockot1a51b922014-09-05 08:02:4424 HidServiceLinux(scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner);
[email protected]125724f2014-01-31 20:13:2325
dcheng07c34a12014-10-29 18:55:1026 void Connect(const HidDeviceId& device_id,
27 const ConnectCallback& callback) override;
[email protected]125724f2014-01-31 20:13:2328
[email protected]125724f2014-01-31 20:13:2329 private:
reillyg56868de2014-12-04 00:26:2730 struct ConnectParams;
reillyg3497d2262015-01-12 22:05:4331 class FileThreadHelper;
reillyg56868de2014-12-04 00:26:2732
dcheng07c34a12014-10-29 18:55:1033 ~HidServiceLinux() override;
[email protected]125724f2014-01-31 20:13:2334
reillyg56868de2014-12-04 00:26:2735 // Constructs this services helper object that lives on the FILE thread.
36 static void StartHelper(
37 base::WeakPtr<HidServiceLinux> weak_ptr,
38 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
39
40 // These functions implement the process of locating, requesting access to and
41 // opening a device. Because this operation crosses multiple threads these
42 // functions are static and the necessary parameters are passed as a single
43 // struct.
44#if defined(OS_CHROMEOS)
reillyge6aead12015-07-10 21:36:1045 static void OnPathOpened(scoped_ptr<ConnectParams> params,
46 dbus::FileDescriptor fd);
47 static void ValidateFdOnBlockingThread(scoped_ptr<ConnectParams> params,
48 dbus::FileDescriptor fd);
49#else
50 static void OpenOnBlockingThread(scoped_ptr<ConnectParams> params);
51#endif
52 static void FinishOpen(scoped_ptr<ConnectParams> params);
53 static void CreateConnection(scoped_ptr<ConnectParams> params);
[email protected]03b640fd2014-07-26 18:25:3854
reillyg7832a4e2014-10-11 01:52:4755 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
reillyg56868de2014-12-04 00:26:2756 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
[email protected]03b640fd2014-07-26 18:25:3857
reillyg56868de2014-12-04 00:26:2758 // The helper lives on the FILE thread and holds a weak reference back to the
59 // service that owns it.
reillyg3497d2262015-01-12 22:05:4360 scoped_ptr<FileThreadHelper> helper_;
dmichael23a8043352014-12-12 19:01:4761 base::WeakPtrFactory<HidServiceLinux> weak_factory_;
[email protected]03b640fd2014-07-26 18:25:3862
[email protected]125724f2014-01-31 20:13:2363 DISALLOW_COPY_AND_ASSIGN(HidServiceLinux);
64};
65
66} // namespace device
67
68#endif // DEVICE_HID_HID_SERVICE_LINUX_H_