scoped_ioobject.h 888 B

123456789101112131415161718192021222324252627282930313233343536
  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 {
  9. namespace mac {
  10. namespace internal {
  11. template <typename IOT>
  12. struct ScopedIOObjectTraits {
  13. static IOT InvalidValue() { return IO_OBJECT_NULL; }
  14. static IOT Retain(IOT iot) {
  15. IOObjectRetain(iot);
  16. return iot;
  17. }
  18. static void Release(IOT iot) { IOObjectRelease(iot); }
  19. };
  20. } // namespce internal
  21. // Just like ScopedCFTypeRef but for io_object_t and subclasses.
  22. template <typename IOT>
  23. using ScopedIOObject = ScopedTypeRef<IOT, internal::ScopedIOObjectTraits<IOT>>;
  24. } // namespace mac
  25. } // namespace base
  26. #endif // BASE_MAC_SCOPED_IOOBJECT_H_