scoped_ioobject.h 863 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright (c) 2012 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 BASE_MAC_SCOPED_IOOBJECT_H_
  5. #define BASE_MAC_SCOPED_IOOBJECT_H_
  6. #include <IOKit/IOKitLib.h>
  7. #include "base/mac/scoped_typeref.h"
  8. namespace base::mac {
  9. namespace internal {
  10. template <typename IOT>
  11. struct ScopedIOObjectTraits {
  12. static IOT InvalidValue() { return IO_OBJECT_NULL; }
  13. static IOT Retain(IOT iot) {
  14. IOObjectRetain(iot);
  15. return iot;
  16. }
  17. static void Release(IOT iot) { IOObjectRelease(iot); }
  18. };
  19. } // namespace internal
  20. // Just like ScopedCFTypeRef but for io_object_t and subclasses.
  21. template <typename IOT>
  22. using ScopedIOObject = ScopedTypeRef<IOT, internal::ScopedIOObjectTraits<IOT>>;
  23. } // namespace base::mac
  24. #endif // BASE_MAC_SCOPED_IOOBJECT_H_