Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(802)

Unified Diff: device/core/device_info_query_win.h

Issue 1439443002: Reland: Add code to deal with serial device disconnection detection on Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: changed some DVPLOG back to VPLOG Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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_

Powered by Google App Engine
This is Rietveld 408576698