blob: b82516879ad474807cd38aa276d653dfa9a76070 [file] [log] [blame]
Jesse Hall29cc9ce2014-03-03 10:52:14 -08001/*
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
23typedef struct native_handle native_handle_t;
24
25namespace android {
26
27class NativeHandle: public LightRefBase<NativeHandle> {
28public:
Wonsik Kimc4cc5842014-03-20 15:42:03 +090029 // 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 Hall29cc9ce2014-03-03 10:52:14 -080032 // If handle is NULL, no NativeHandle will be created.
Wonsik Kimc4cc5842014-03-20 15:42:03 +090033 static sp<NativeHandle> create(native_handle_t* handle, bool ownsHandle);
Jesse Hall29cc9ce2014-03-03 10:52:14 -080034
35 const native_handle_t* handle() const {
36 return mHandle;
37 }
38
39private:
40 // for access to the destructor
41 friend class LightRefBase<NativeHandle>;
42
Wonsik Kimc4cc5842014-03-20 15:42:03 +090043 NativeHandle(native_handle_t* handle, bool ownsHandle);
Jesse Hall29cc9ce2014-03-03 10:52:14 -080044 virtual ~NativeHandle();
45
46 native_handle_t* mHandle;
Wonsik Kimc4cc5842014-03-20 15:42:03 +090047 bool mOwnsHandle;
Jesse Hall29cc9ce2014-03-03 10:52:14 -080048
49 // non-copyable
50 NativeHandle(const NativeHandle&);
51 NativeHandle& operator=(const NativeHandle&);
52};
53
54} // namespace android
55
56#endif // ANDROID_NATIVE_HANDLE_H