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 
5 #ifndef BASE_MAC_SCOPED_IOOBJECT_H_
6 #define BASE_MAC_SCOPED_IOOBJECT_H_
7 
8 #include <IOKit/IOKitLib.h>
9 
10 #include "base/mac/scoped_typeref.h"
11 
12 namespace base {
13 namespace mac {
14 
15 namespace internal {
16 
17 template <typename IOT>
18 struct ScopedIOObjectTraits {
InvalidValueScopedIOObjectTraits19   static IOT InvalidValue() { return IO_OBJECT_NULL; }
RetainScopedIOObjectTraits20   static IOT Retain(IOT iot) {
21     IOObjectRetain(iot);
22     return iot;
23   }
ReleaseScopedIOObjectTraits24   static void Release(IOT iot) { IOObjectRelease(iot); }
25 };
26 
27 }  // namespce internal
28 
29 // Just like ScopedCFTypeRef but for io_object_t and subclasses.
30 template <typename IOT>
31 using ScopedIOObject = ScopedTypeRef<IOT, internal::ScopedIOObjectTraits<IOT>>;
32 
33 }  // namespace mac
34 }  // namespace base
35 
36 #endif  // BASE_MAC_SCOPED_IOOBJECT_H_
37