blob: b4f63588415666657ea04467f7549859b111fa14 [file] [log] [blame]
Steven Moreland2e87adc2018-08-20 19:47:00 -07001/*
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 Moreland4d5ad492018-09-13 12:49:16 -070024#include "ibinder_internal.h"
Steven Moreland2e87adc2018-08-20 19:47:00 -070025
26struct AParcel {
Steven Morelandf18615b2018-09-14 11:43:06 -070027 const ::android::Parcel* get() const { return mParcel; }
28 ::android::Parcel* get() { return mParcel; }
Steven Moreland2e87adc2018-08-20 19:47:00 -070029
Steven Moreland37aff182021-03-26 02:04:16 +000030 explicit AParcel(AIBinder* binder) : AParcel(binder, new ::android::Parcel, true /*owns*/) {}
31 AParcel(AIBinder* binder, ::android::Parcel* parcel, bool owns)
Steven Moreland1fda67b2021-04-02 18:35:50 +000032 : mBinder(binder), mParcel(parcel), mOwns(owns) {}
Steven Moreland2e87adc2018-08-20 19:47:00 -070033
34 ~AParcel() {
35 if (mOwns) {
36 delete mParcel;
37 }
38 }
39
Steven Moreland37aff182021-03-26 02:04:16 +000040 static const AParcel readOnly(AIBinder* binder, const ::android::Parcel* parcel) {
Steven Moreland2e87adc2018-08-20 19:47:00 -070041 return AParcel(binder, const_cast<::android::Parcel*>(parcel), false);
42 }
43
44 const AIBinder* getBinder() { return mBinder; }
45
Steven Moreland6cf66ac2018-11-02 18:14:54 -070046 private:
Steven Moreland2e87adc2018-08-20 19:47:00 -070047 // 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};