OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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. | |
4 | |
5 #ifndef DEVICE_CORE_DEVICE_INFO_QUERY_WIN_H_ | |
6 #define DEVICE_CORE_DEVICE_INFO_QUERY_WIN_H_ | |
7 | |
8 #include <windows.h> | |
9 #include <setupapi.h> | |
10 | |
11 #include "base/macros.h" | |
12 | |
13 namespace device { | |
14 | |
15 // Wrapper around a HDEVINFO and SP_DEVINFO_DATA that automatically destroys | |
16 // them. | |
17 class DeviceInfoQueryWin { | |
18 public: | |
19 DeviceInfoQueryWin() | |
20 : device_info_list_(SetupDiCreateDeviceInfoList(NULL, NULL)) { | |
grt (UTC plus 2)
2015/11/16 16:14:16
nullptr in place of NULL throughout
juncai
2015/11/16 21:10:33
Done.
| |
21 if (device_info_list_ != INVALID_HANDLE_VALUE) | |
22 device_info_list_valid_ = true; | |
23 memset(&device_info_data_, 0, sizeof(device_info_data_)); | |
grt (UTC plus 2)
2015/11/16 16:14:16
#include <string.h> for memset
juncai
2015/11/16 21:10:34
Done.
| |
24 device_info_data_.cbSize = sizeof(device_info_data_); | |
25 } | |
26 | |
27 ~DeviceInfoQueryWin() { | |
28 if (device_info_list_valid_) { | |
29 if (device_info_data_valid_) | |
30 SetupDiDeleteDeviceInfo(device_info_list_, &device_info_data_); | |
31 SetupDiDestroyDeviceInfoList(device_info_list_); | |
32 } | |
33 } | |
34 | |
35 bool AddDevice(const char* device_path) { | |
36 if (SetupDiOpenDeviceInterfaceA(device_info_list_, device_path, 0, NULL)) | |
grt (UTC plus 2)
2015/11/16 16:14:16
return SetupDiOpenDeviceInterfaceA(...) != FALSE;
juncai
2015/11/16 21:10:33
Done.
| |
37 return true; | |
38 else | |
39 return false; | |
40 } | |
41 | |
42 bool GetDeviceInfo() { | |
43 if (SetupDiEnumDeviceInfo(device_info_list_, 0, &device_info_data_)) | |
44 device_info_data_valid_ = true; | |
grt (UTC plus 2)
2015/11/16 16:14:16
remove device_info_data_valid_ and use "device_inf
juncai
2015/11/16 21:10:34
Done.
| |
45 return device_info_data_valid_; | |
46 } | |
47 | |
48 bool device_info_list_valid() { return device_info_list_valid_; } | |
grt (UTC plus 2)
2015/11/16 16:14:16
remove device_info_list_valid_ and change this to
juncai
2015/11/16 21:10:33
Done.
| |
49 | |
50 HDEVINFO device_info_list() { return device_info_list_; } | |
51 | |
52 PSP_DEVINFO_DATA device_info_data() { return &device_info_data_; } | |
53 | |
54 private: | |
55 HDEVINFO device_info_list_ = INVALID_HANDLE_VALUE; | |
56 SP_DEVINFO_DATA device_info_data_; | |
57 bool device_info_list_valid_ = false; | |
58 bool device_info_data_valid_ = false; | |
59 | |
60 DISALLOW_COPY_AND_ASSIGN(DeviceInfoQueryWin); | |
61 }; | |
62 | |
63 } // namespace device | |
64 | |
65 #endif // DEVICE_CORE_DEVICE_INFO_QUERY_WIN_H_ | |
OLD | NEW |