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