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_SCOPED_DEVICE_INFO_OBJECT_H_ |
| 6 #define DEVICE_CORE_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); |
| 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 }; |
| 43 |
| 44 } // namespace win |
| 45 } // namespace base |
| 46 |
| 47 #endif // DEVICE_CORE_SCOPED_DEVICE_INFO_OBJECT_H_ |
OLD | NEW |