xref: /aosp_15_r20/external/cronet/base/mac/scoped_ioplugininterface.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1*6777b538SAndroid Build Coastguard Worker // Copyright 2012 The Chromium Authors
2*6777b538SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*6777b538SAndroid Build Coastguard Worker // found in the LICENSE file.
4*6777b538SAndroid Build Coastguard Worker 
5*6777b538SAndroid Build Coastguard Worker #ifndef BASE_MAC_SCOPED_IOPLUGININTERFACE_H_
6*6777b538SAndroid Build Coastguard Worker #define BASE_MAC_SCOPED_IOPLUGININTERFACE_H_
7*6777b538SAndroid Build Coastguard Worker 
8*6777b538SAndroid Build Coastguard Worker #include <IOKit/IOKitLib.h>
9*6777b538SAndroid Build Coastguard Worker 
10*6777b538SAndroid Build Coastguard Worker #include "base/apple/scoped_typeref.h"
11*6777b538SAndroid Build Coastguard Worker 
12*6777b538SAndroid Build Coastguard Worker namespace base::mac {
13*6777b538SAndroid Build Coastguard Worker 
14*6777b538SAndroid Build Coastguard Worker namespace internal {
15*6777b538SAndroid Build Coastguard Worker 
16*6777b538SAndroid Build Coastguard Worker template <typename T>
17*6777b538SAndroid Build Coastguard Worker struct ScopedIOPluginInterfaceTraits {
InvalidValueScopedIOPluginInterfaceTraits18*6777b538SAndroid Build Coastguard Worker   static T InvalidValue() { return nullptr; }
RetainScopedIOPluginInterfaceTraits19*6777b538SAndroid Build Coastguard Worker   static T Retain(T t) {
20*6777b538SAndroid Build Coastguard Worker     (*t)->AddRef(t);
21*6777b538SAndroid Build Coastguard Worker     return t;
22*6777b538SAndroid Build Coastguard Worker   }
ReleaseScopedIOPluginInterfaceTraits23*6777b538SAndroid Build Coastguard Worker   static void Release(T t) { (*t)->Release(t); }
24*6777b538SAndroid Build Coastguard Worker };
25*6777b538SAndroid Build Coastguard Worker 
26*6777b538SAndroid Build Coastguard Worker }  // namespace internal
27*6777b538SAndroid Build Coastguard Worker 
28*6777b538SAndroid Build Coastguard Worker // Just like ScopedCFTypeRef but for IOCFPlugInInterface and friends
29*6777b538SAndroid Build Coastguard Worker // (IOUSBInterfaceStruct and IOUSBDeviceStruct320 in particular).
30*6777b538SAndroid Build Coastguard Worker template <typename T>
31*6777b538SAndroid Build Coastguard Worker using ScopedIOPluginInterface =
32*6777b538SAndroid Build Coastguard Worker     apple::ScopedTypeRef<T**, internal::ScopedIOPluginInterfaceTraits<T**>>;
33*6777b538SAndroid Build Coastguard Worker 
34*6777b538SAndroid Build Coastguard Worker }  // namespace base::mac
35*6777b538SAndroid Build Coastguard Worker 
36*6777b538SAndroid Build Coastguard Worker #endif  // BASE_MAC_SCOPED_IOPLUGININTERFACE_H_
37