Chromium Code Reviews| Index: device/core/device_info_query_win.h |
| diff --git a/device/core/device_info_query_win.h b/device/core/device_info_query_win.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d6adaa5ae2262b319be16440b5343e51fc8b7319 |
| --- /dev/null |
| +++ b/device/core/device_info_query_win.h |
| @@ -0,0 +1,65 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef DEVICE_CORE_DEVICE_INFO_QUERY_WIN_H_ |
| +#define DEVICE_CORE_DEVICE_INFO_QUERY_WIN_H_ |
| + |
| +#include <windows.h> |
| +#include <setupapi.h> |
| + |
| +#include "base/macros.h" |
| + |
| +namespace device { |
| + |
| +// Wrapper around a HDEVINFO and SP_DEVINFO_DATA that automatically destroys |
| +// them. |
| +class DeviceInfoQueryWin { |
| + public: |
| + DeviceInfoQueryWin() |
| + : 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.
|
| + if (device_info_list_ != INVALID_HANDLE_VALUE) |
| + device_info_list_valid_ = true; |
| + 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.
|
| + device_info_data_.cbSize = sizeof(device_info_data_); |
| + } |
| + |
| + ~DeviceInfoQueryWin() { |
| + if (device_info_list_valid_) { |
| + if (device_info_data_valid_) |
| + SetupDiDeleteDeviceInfo(device_info_list_, &device_info_data_); |
| + SetupDiDestroyDeviceInfoList(device_info_list_); |
| + } |
| + } |
| + |
| + bool AddDevice(const char* device_path) { |
| + 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.
|
| + return true; |
| + else |
| + return false; |
| + } |
| + |
| + bool GetDeviceInfo() { |
| + if (SetupDiEnumDeviceInfo(device_info_list_, 0, &device_info_data_)) |
| + 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.
|
| + return device_info_data_valid_; |
| + } |
| + |
| + 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.
|
| + |
| + HDEVINFO device_info_list() { return device_info_list_; } |
| + |
| + PSP_DEVINFO_DATA device_info_data() { return &device_info_data_; } |
| + |
| + private: |
| + HDEVINFO device_info_list_ = INVALID_HANDLE_VALUE; |
| + SP_DEVINFO_DATA device_info_data_; |
| + bool device_info_list_valid_ = false; |
| + bool device_info_data_valid_ = false; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DeviceInfoQueryWin); |
| +}; |
| + |
| +} // namespace device |
| + |
| +#endif // DEVICE_CORE_DEVICE_INFO_QUERY_WIN_H_ |