scoped_pdh_query.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2022 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 SERVICES_DEVICE_COMPUTE_PRESSURE_SCOPED_PDH_QUERY_H_
  5. #define SERVICES_DEVICE_COMPUTE_PRESSURE_SCOPED_PDH_QUERY_H_
  6. #include <pdh.h>
  7. #include "base/scoped_generic.h"
  8. namespace device {
  9. namespace internal {
  10. // Scoped PdhQuery class to maintain lifetime of PDH_HQUERY.
  11. struct ScopedPdhQueryTraits {
  12. static PDH_HQUERY InvalidValue() { return NULL; }
  13. static void Free(PDH_HQUERY query) { PdhCloseQuery(query); }
  14. };
  15. } // namespace internal
  16. // ScopedPdhQuery is a wrapper around a PDH_HQUERY.
  17. //
  18. // Example use:
  19. //
  20. // ScopedPdhQuery pdh_query = ScopedPdhQuery::Create();
  21. //
  22. // Also:
  23. //
  24. // PDH_HQUERY pdh_query;
  25. // PDH_STATUS status = PdhOpenQuery(..., &pdh_query);
  26. // ScopedPdhQuery pdh_query(pdh_query);
  27. class ScopedPdhQuery
  28. : public base::ScopedGeneric<PDH_HQUERY, internal::ScopedPdhQueryTraits> {
  29. public:
  30. // Initializes with a NULL PDH_HQUERY.
  31. ScopedPdhQuery();
  32. // Constructs a ScopedPdhQuery from a PDH_HQUERY, and takes ownership of
  33. // `pdh_query`.
  34. explicit ScopedPdhQuery(PDH_HQUERY pdh_query);
  35. static ScopedPdhQuery Create();
  36. };
  37. } // namespace device
  38. #endif // SERVICES_DEVICE_COMPUTE_PRESSURE_SCOPED_PDH_QUERY_H_