| 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: | 
| Wonsik Kim | c4cc584 | 2014-03-20 15:42:03 +0900 | [diff] [blame] | 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. | 
| Jesse Hall | 29cc9ce | 2014-03-03 10:52:14 -0800 | [diff] [blame] | 32 | // If handle is NULL, no NativeHandle will be created. | 
| Wonsik Kim | c4cc584 | 2014-03-20 15:42:03 +0900 | [diff] [blame] | 33 | static sp<NativeHandle> create(native_handle_t* handle, bool ownsHandle); | 
| Jesse Hall | 29cc9ce | 2014-03-03 10:52:14 -0800 | [diff] [blame] | 34 |  | 
|  | 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 |  | 
| Wonsik Kim | c4cc584 | 2014-03-20 15:42:03 +0900 | [diff] [blame] | 43 | NativeHandle(native_handle_t* handle, bool ownsHandle); | 
| Jesse Hall | 29cc9ce | 2014-03-03 10:52:14 -0800 | [diff] [blame] | 44 | virtual ~NativeHandle(); | 
|  | 45 |  | 
|  | 46 | native_handle_t* mHandle; | 
| Wonsik Kim | c4cc584 | 2014-03-20 15:42:03 +0900 | [diff] [blame] | 47 | bool mOwnsHandle; | 
| Jesse Hall | 29cc9ce | 2014-03-03 10:52:14 -0800 | [diff] [blame] | 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 |