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_HID_SERVICE_WIN_H_ | 5 #ifndef DEVICE_HID_HID_SERVICE_WIN_H_ |
6 #define DEVICE_HID_HID_SERVICE_WIN_H_ | 6 #define DEVICE_HID_HID_SERVICE_WIN_H_ |
7 | 7 |
8 #include <map> | |
9 | |
10 #include "device/hid/hid_device_info.h" | |
11 #include "device/hid/hid_service.h" | |
12 | |
13 #if defined(OS_WIN) | |
14 | |
15 #include <windows.h> | 8 #include <windows.h> |
16 #include <hidclass.h> | 9 #include <hidclass.h> |
17 | 10 |
18 extern "C" { | 11 extern "C" { |
19 #include <hidsdi.h> | 12 #include <hidsdi.h> |
20 #include <hidpi.h> | 13 #include <hidpi.h> |
21 } | 14 } |
22 | 15 |
23 #endif // defined(OS_WIN) | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/win/scoped_handle.h" |
| 18 #include "device/hid/hid_device_info.h" |
| 19 #include "device/hid/hid_service.h" |
| 20 |
| 21 namespace base { |
| 22 namespace win { |
| 23 class MessageWindow; |
| 24 } |
| 25 } |
24 | 26 |
25 namespace device { | 27 namespace device { |
26 | 28 |
27 class HidConnection; | |
28 | |
29 class HidServiceWin : public HidService { | 29 class HidServiceWin : public HidService { |
30 public: | 30 public: |
31 HidServiceWin(); | 31 HidServiceWin(); |
32 | 32 |
33 virtual void GetDevices(std::vector<HidDeviceInfo>* devices) override; | |
34 | |
35 virtual void Connect(const HidDeviceId& device_id, | 33 virtual void Connect(const HidDeviceId& device_id, |
36 const ConnectCallback& callback) override; | 34 const ConnectCallback& callback) override; |
37 | 35 |
38 private: | 36 private: |
39 virtual ~HidServiceWin(); | 37 virtual ~HidServiceWin(); |
40 | 38 |
41 void Enumerate(); | 39 void RegisterForDeviceNotifications(); |
| 40 bool HandleMessage(UINT message, |
| 41 WPARAM wparam, |
| 42 LPARAM lparam, |
| 43 LRESULT* result); |
| 44 void DoInitialEnumeration(); |
42 static void CollectInfoFromButtonCaps(PHIDP_PREPARSED_DATA preparsed_data, | 45 static void CollectInfoFromButtonCaps(PHIDP_PREPARSED_DATA preparsed_data, |
43 HIDP_REPORT_TYPE report_type, | 46 HIDP_REPORT_TYPE report_type, |
44 USHORT button_caps_length, | 47 USHORT button_caps_length, |
45 HidCollectionInfo* collection_info); | 48 HidCollectionInfo* collection_info); |
46 static void CollectInfoFromValueCaps(PHIDP_PREPARSED_DATA preparsed_data, | 49 static void CollectInfoFromValueCaps(PHIDP_PREPARSED_DATA preparsed_data, |
47 HIDP_REPORT_TYPE report_type, | 50 HIDP_REPORT_TYPE report_type, |
48 USHORT value_caps_length, | 51 USHORT value_caps_length, |
49 HidCollectionInfo* collection_info); | 52 HidCollectionInfo* collection_info); |
50 void PlatformAddDevice(const std::string& device_path); | 53 void PlatformAddDevice(const std::string& device_path); |
51 void PlatformRemoveDevice(const std::string& device_path); | 54 void PlatformRemoveDevice(const std::string& device_path); |
52 | 55 |
| 56 // Tries to open the device read-write and falls back to read-only. |
| 57 base::win::ScopedHandle OpenDevice(const std::string& device_path); |
| 58 |
53 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 59 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 60 scoped_ptr<base::win::MessageWindow> window_; |
| 61 HDEVNOTIFY notify_handle_; |
54 | 62 |
55 DISALLOW_COPY_AND_ASSIGN(HidServiceWin); | 63 DISALLOW_COPY_AND_ASSIGN(HidServiceWin); |
56 }; | 64 }; |
57 | 65 |
58 } // namespace device | 66 } // namespace device |
59 | 67 |
60 #endif // DEVICE_HID_HID_SERVICE_WIN_H_ | 68 #endif // DEVICE_HID_HID_SERVICE_WIN_H_ |
OLD | NEW |