xref: /aosp_15_r20/external/cronet/base/mac/scoped_ioobject.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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/apple/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 =
31     apple::ScopedTypeRef<IOT, internal::ScopedIOObjectTraits<IOT>>;
32 
33 }  // namespace base::mac
34 
35 #endif  // BASE_MAC_SCOPED_IOOBJECT_H_
36