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

Side by Side Diff: base/win/scoped_device_info_object.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: address reillgy@'s comments 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 unified diff | Download patch
« no previous file with comments | « base/win/scoped_device_info_list.h ('k') | device/serial/serial_io_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 BASE_WIN_SCOPED_DEVICE_INFO_OBJECT_H_
6 #define BASE_WIN_SCOPED_DEVICE_INFO_OBJECT_H_
7
8 #include <windows.h>
9 #include <setupapi.h>
10
11 namespace base {
12 namespace win {
13
14 // Wrapper around an SP_DEVINFO_DATA that initializes it properly and
15 // automatically deletes it.
16 class ScopedDeviceInfo {
17 public:
18 ScopedDeviceInfo() {
19 memset(&dev_info_data_, 0, sizeof(dev_info_data_));
20 dev_info_data_.cbSize = sizeof(dev_info_data_);
21 }
22
23 ~ScopedDeviceInfo() {
24 if (dev_info_set_ != INVALID_HANDLE_VALUE) {
25 SetupDiDeleteDeviceInfo(dev_info_set_, &dev_info_data_);
26 }
27 }
28
29 // Once the SP_DEVINFO_DATA has been populated it must be freed using the
30 // HDEVINFO it was created from.
31 void set_valid(HDEVINFO dev_info_set) {
32 DCHECK(dev_info_set_ == INVALID_HANDLE_VALUE);
Lei Zhang 2015/11/13 01:38:25 DCHECK_EQ / DCHECK_NE
33 DCHECK(dev_info_set != INVALID_HANDLE_VALUE);
34 dev_info_set_ = dev_info_set;
35 }
36
37 PSP_DEVINFO_DATA get() { return &dev_info_data_; }
38
39 private:
40 HDEVINFO dev_info_set_ = INVALID_HANDLE_VALUE;
41 SP_DEVINFO_DATA dev_info_data_;
42 };
Lei Zhang 2015/11/13 01:38:25 DISALLOW_COPY_AND_ASSIGN?
43
44 } // namespace win
45 } // namespace base
46
47 #endif // BASE_WIN_SCOPED_DEVICE_INFO_OBJECT_H_
OLDNEW
« no previous file with comments | « base/win/scoped_device_info_list.h ('k') | device/serial/serial_io_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698