device_info_query_win.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. #ifndef DEVICE_BASE_DEVICE_INFO_QUERY_WIN_H_
  5. #define DEVICE_BASE_DEVICE_INFO_QUERY_WIN_H_
  6. #include <windows.h>
  7. #include <setupapi.h>
  8. #include <string>
  9. #include "device/base/device_base_export.h"
  10. namespace device {
  11. // Wraps HDEVINFO and SP_DEVINFO_DATA into a class that can automatically
  12. // release them. Provides interfaces that can add a device using its
  13. // device path, get device info and get device string property.
  14. class DEVICE_BASE_EXPORT DeviceInfoQueryWin {
  15. public:
  16. DeviceInfoQueryWin();
  17. DeviceInfoQueryWin(const DeviceInfoQueryWin&) = delete;
  18. DeviceInfoQueryWin& operator=(const DeviceInfoQueryWin&) = delete;
  19. ~DeviceInfoQueryWin();
  20. // Add a device to |device_info_list_| using its |device_path| so that
  21. // its device info can be retrieved.
  22. bool AddDevice(const std::wstring& device_path);
  23. // Get the device info and store it into |device_info_data_|, this function
  24. // should be called at most once.
  25. bool GetDeviceInfo();
  26. // Get device string property and store it into |property_buffer|.
  27. bool GetDeviceStringProperty(const DEVPROPKEY& property,
  28. std::string* property_buffer);
  29. bool device_info_list_valid() {
  30. return device_info_list_ != INVALID_HANDLE_VALUE;
  31. }
  32. private:
  33. HDEVINFO device_info_list_ = INVALID_HANDLE_VALUE;
  34. // When device_info_data_.cbSize != 0, |device_info_data_| is valid.
  35. SP_DEVINFO_DATA device_info_data_;
  36. };
  37. } // namespace device
  38. #endif // DEVICE_BASE_DEVICE_INFO_QUERY_WIN_H_