1 // Copyright 2012 The Chromium Authors 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::mac { 13 14 namespace internal { 15 16 template <typename IOT> 17 struct ScopedIOObjectTraits { InvalidValueScopedIOObjectTraits18 static IOT InvalidValue() { return IO_OBJECT_NULL; } RetainScopedIOObjectTraits19 static IOT Retain(IOT iot) { 20 IOObjectRetain(iot); 21 return iot; 22 } ReleaseScopedIOObjectTraits23 static void Release(IOT iot) { IOObjectRelease(iot); } 24 }; 25 26 } // namespace internal 27 28 // Just like ScopedCFTypeRef but for io_object_t and subclasses. 29 template <typename IOT> 30 using ScopedIOObject = ScopedTypeRef<IOT, internal::ScopedIOObjectTraits<IOT>>; 31 32 } // namespace base::mac 33 34 #endif // BASE_MAC_SCOPED_IOOBJECT_H_ 35