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 | #include <android/binder_parcel.h> |
| 18 | #include "AParcel_internal.h" |
| 19 | |
| 20 | #include "AIBinder_internal.h" |
| 21 | |
| 22 | #include <binder/Parcel.h> |
| 23 | |
| 24 | using ::android::IBinder; |
| 25 | using ::android::Parcel; |
| 26 | using ::android::sp; |
| 27 | |
Steven Moreland | caa776c | 2018-09-04 13:48:11 -0700 | [diff] [blame] | 28 | void AParcel_delete(AParcel** parcel) { |
| 29 | if (parcel == nullptr) { |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | delete *parcel; |
| 34 | *parcel = nullptr; |
| 35 | } |
| 36 | |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 37 | binder_status_t AParcel_writeStrongBinder(AParcel* parcel, AIBinder* binder) { |
Steven Moreland | c0e46d3 | 2018-09-12 15:40:49 -0700 | [diff] [blame^] | 38 | sp<IBinder> writeBinder = binder != nullptr ? binder->getBinder() : nullptr; |
| 39 | return (*parcel)->writeStrongBinder(writeBinder); |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 40 | } |
| 41 | binder_status_t AParcel_readStrongBinder(const AParcel* parcel, AIBinder** binder) { |
| 42 | sp<IBinder> readBinder = nullptr; |
| 43 | binder_status_t status = (*parcel)->readStrongBinder(&readBinder); |
| 44 | if (status != EX_NONE) { |
| 45 | return status; |
| 46 | } |
Steven Moreland | 9496895 | 2018-09-05 14:42:59 -0700 | [diff] [blame] | 47 | sp<AIBinder> ret = ABpBinder::lookupOrCreateFromBinder(readBinder); |
Steven Moreland | 71cddc3 | 2018-08-30 23:39:22 -0700 | [diff] [blame] | 48 | AIBinder_incStrong(ret.get()); |
| 49 | *binder = ret.get(); |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 50 | return status; |
| 51 | } |
| 52 | binder_status_t AParcel_readNullableStrongBinder(const AParcel* parcel, AIBinder** binder) { |
| 53 | sp<IBinder> readBinder = nullptr; |
| 54 | binder_status_t status = (*parcel)->readNullableStrongBinder(&readBinder); |
| 55 | if (status != EX_NONE) { |
| 56 | return status; |
| 57 | } |
Steven Moreland | 9496895 | 2018-09-05 14:42:59 -0700 | [diff] [blame] | 58 | sp<AIBinder> ret = ABpBinder::lookupOrCreateFromBinder(readBinder); |
Steven Moreland | 71cddc3 | 2018-08-30 23:39:22 -0700 | [diff] [blame] | 59 | AIBinder_incStrong(ret.get()); |
| 60 | *binder = ret.get(); |
Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 61 | return status; |
| 62 | } |
| 63 | |
| 64 | // See gen_parcel_helper.py. These auto-generated read/write methods use the same types for |
| 65 | // libbinder and this library. |
| 66 | // @START |
| 67 | binder_status_t AParcel_writeInt32(AParcel* parcel, int32_t value) { |
| 68 | return (*parcel)->writeInt32(value); |
| 69 | } |
| 70 | |
| 71 | binder_status_t AParcel_writeUint32(AParcel* parcel, uint32_t value) { |
| 72 | return (*parcel)->writeUint32(value); |
| 73 | } |
| 74 | |
| 75 | binder_status_t AParcel_writeInt64(AParcel* parcel, int64_t value) { |
| 76 | return (*parcel)->writeInt64(value); |
| 77 | } |
| 78 | |
| 79 | binder_status_t AParcel_writeUint64(AParcel* parcel, uint64_t value) { |
| 80 | return (*parcel)->writeUint64(value); |
| 81 | } |
| 82 | |
| 83 | binder_status_t AParcel_writeFloat(AParcel* parcel, float value) { |
| 84 | return (*parcel)->writeFloat(value); |
| 85 | } |
| 86 | |
| 87 | binder_status_t AParcel_writeDouble(AParcel* parcel, double value) { |
| 88 | return (*parcel)->writeDouble(value); |
| 89 | } |
| 90 | |
| 91 | binder_status_t AParcel_writeBool(AParcel* parcel, bool value) { |
| 92 | return (*parcel)->writeBool(value); |
| 93 | } |
| 94 | |
| 95 | binder_status_t AParcel_writeChar(AParcel* parcel, char16_t value) { |
| 96 | return (*parcel)->writeChar(value); |
| 97 | } |
| 98 | |
| 99 | binder_status_t AParcel_writeByte(AParcel* parcel, int8_t value) { |
| 100 | return (*parcel)->writeByte(value); |
| 101 | } |
| 102 | |
| 103 | binder_status_t AParcel_readInt32(const AParcel* parcel, int32_t* value) { |
| 104 | return (*parcel)->readInt32(value); |
| 105 | } |
| 106 | |
| 107 | binder_status_t AParcel_readUint32(const AParcel* parcel, uint32_t* value) { |
| 108 | return (*parcel)->readUint32(value); |
| 109 | } |
| 110 | |
| 111 | binder_status_t AParcel_readInt64(const AParcel* parcel, int64_t* value) { |
| 112 | return (*parcel)->readInt64(value); |
| 113 | } |
| 114 | |
| 115 | binder_status_t AParcel_readUint64(const AParcel* parcel, uint64_t* value) { |
| 116 | return (*parcel)->readUint64(value); |
| 117 | } |
| 118 | |
| 119 | binder_status_t AParcel_readFloat(const AParcel* parcel, float* value) { |
| 120 | return (*parcel)->readFloat(value); |
| 121 | } |
| 122 | |
| 123 | binder_status_t AParcel_readDouble(const AParcel* parcel, double* value) { |
| 124 | return (*parcel)->readDouble(value); |
| 125 | } |
| 126 | |
| 127 | binder_status_t AParcel_readBool(const AParcel* parcel, bool* value) { |
| 128 | return (*parcel)->readBool(value); |
| 129 | } |
| 130 | |
| 131 | binder_status_t AParcel_readChar(const AParcel* parcel, char16_t* value) { |
| 132 | return (*parcel)->readChar(value); |
| 133 | } |
| 134 | |
| 135 | binder_status_t AParcel_readByte(const AParcel* parcel, int8_t* value) { |
| 136 | return (*parcel)->readByte(value); |
| 137 | } |
| 138 | |
| 139 | // @END |