1 /* 2 * Copyright 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_NATIVE_HANDLE_H 18 #define ANDROID_NATIVE_HANDLE_H 19 20 #include <utils/RefBase.h> 21 #include <utils/StrongPointer.h> 22 23 typedef struct native_handle native_handle_t; 24 25 namespace android { 26 27 class NativeHandle : public LightRefBase<NativeHandle> { 28 public: 29 // Create a refcounted wrapper around a native_handle_t, and declare 30 // whether the wrapper owns the handle (so that it should clean up the 31 // handle upon destruction) or not. 32 // If handle is NULL, no NativeHandle will be created. 33 static sp<NativeHandle> create(native_handle_t* handle, bool ownsHandle); 34 handle()35 const native_handle_t* handle() const { 36 return mHandle; 37 } 38 39 private: 40 // for access to the destructor 41 friend class LightRefBase<NativeHandle>; 42 43 NativeHandle(native_handle_t* handle, bool ownsHandle); 44 ~NativeHandle(); 45 46 native_handle_t* mHandle; 47 bool mOwnsHandle; 48 49 // non-copyable 50 NativeHandle(const NativeHandle&); 51 NativeHandle& operator=(const NativeHandle&); 52 }; 53 54 } // namespace android 55 56 #endif // ANDROID_NATIVE_HANDLE_H 57