Jesse Hall | 29cc9ce | 2014-03-03 10:52:14 -0800 | [diff] [blame] | 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. |
| 30 | // If handle is NULL, no NativeHandle will be created. |
| 31 | static sp<NativeHandle> create(native_handle_t* handle); |
| 32 | |
| 33 | const native_handle_t* handle() const { |
| 34 | return mHandle; |
| 35 | } |
| 36 | |
| 37 | private: |
| 38 | // for access to the destructor |
| 39 | friend class LightRefBase<NativeHandle>; |
| 40 | |
| 41 | NativeHandle(native_handle_t* handle); |
| 42 | virtual ~NativeHandle(); |
| 43 | |
| 44 | native_handle_t* mHandle; |
| 45 | |
| 46 | // non-copyable |
| 47 | NativeHandle(const NativeHandle&); |
| 48 | NativeHandle& operator=(const NativeHandle&); |
| 49 | }; |
| 50 | |
| 51 | } // namespace android |
| 52 | |
| 53 | #endif // ANDROID_NATIVE_HANDLE_H |