Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | #pragma once |
| 18 | |
| 19 | #include <android/binder_parcel.h> |
| 20 | |
| 21 | #include <sys/cdefs.h> |
| 22 | |
| 23 | #include <binder/Parcel.h> |
Steven Moreland | 4d5ad49 | 2018-09-13 12:49:16 -0700 | [diff] [blame] | 24 | #include "ibinder_internal.h" |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 25 | |
| 26 | struct AParcel { |
Steven Moreland | f18615b | 2018-09-14 11:43:06 -0700 | [diff] [blame] | 27 | const ::android::Parcel* get() const { return mParcel; } |
| 28 | ::android::Parcel* get() { return mParcel; } |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 29 | |
Steven Moreland | 37aff18 | 2021-03-26 02:04:16 +0000 | [diff] [blame] | 30 | explicit AParcel(AIBinder* binder) : AParcel(binder, new ::android::Parcel, true /*owns*/) {} |
| 31 | AParcel(AIBinder* binder, ::android::Parcel* parcel, bool owns) |
Steven Moreland | 1fda67b | 2021-04-02 18:35:50 +0000 | [diff] [blame^] | 32 | : mBinder(binder), mParcel(parcel), mOwns(owns) {} |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 33 | |
| 34 | ~AParcel() { |
| 35 | if (mOwns) { |
| 36 | delete mParcel; |
| 37 | } |
| 38 | } |
| 39 | |
Steven Moreland | 37aff18 | 2021-03-26 02:04:16 +0000 | [diff] [blame] | 40 | static const AParcel readOnly(AIBinder* binder, const ::android::Parcel* parcel) { |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 41 | return AParcel(binder, const_cast<::android::Parcel*>(parcel), false); |
| 42 | } |
| 43 | |
| 44 | const AIBinder* getBinder() { return mBinder; } |
| 45 | |
Steven Moreland | 6cf66ac | 2018-11-02 18:14:54 -0700 | [diff] [blame] | 46 | private: |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 47 | // This object is associated with a calls to a specific AIBinder object. This is used for sanity |
| 48 | // checking to make sure that a parcel is one that is expected. |
| 49 | const AIBinder* mBinder; |
| 50 | |
| 51 | ::android::Parcel* mParcel; |
| 52 | bool mOwns; |
| 53 | }; |