1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef SENSOR_PARCEL_H 16 #define SENSOR_PARCEL_H 17 18 #include "sensor_errors.h" 19 20 namespace OHOS { 21 namespace Sensors { 22 23 #define WRITEBOOL(parcel, data, ...) \ 24 do { \ 25 if (!(parcel).WriteBool(data)) { \ 26 SEN_HILOGE("Parcel writeBool "#data" failed"); \ 27 return __VA_ARGS__; \ 28 } \ 29 } while (0) 30 31 #define WRITEINT32(parcel, data, ...) \ 32 do { \ 33 if (!(parcel).WriteInt32(data)) { \ 34 SEN_HILOGE("Parcel writeInt32 "#data" failed"); \ 35 return __VA_ARGS__; \ 36 } \ 37 } while (0) 38 39 #define WRITEINT64(parcel, data, ...) \ 40 do { \ 41 if (!(parcel).WriteInt64(data)) { \ 42 SEN_HILOGE("Parcel writeInt64 "#data" failed"); \ 43 return __VA_ARGS__; \ 44 } \ 45 } while (0) 46 47 #define WRITEUINT32(parcel, data, ...) \ 48 do { \ 49 if (!(parcel).WriteUint32(data)) { \ 50 SEN_HILOGE("Parcel writeUint32 "#data" failed"); \ 51 return __VA_ARGS__; \ 52 } \ 53 } while (0) 54 55 #define WRITEDOUBLE(parcel, data, ...) \ 56 do { \ 57 if (!(parcel).WriteDouble(data)) { \ 58 SEN_HILOGE("Parcel writeDouble "#data" failed"); \ 59 return __VA_ARGS__; \ 60 } \ 61 } while (0) 62 63 #define WRITESTRING(parcel, data, ...) \ 64 do { \ 65 if (!(parcel).WriteString(data)) { \ 66 SEN_HILOGE("Parcel writeString "#data" failed"); \ 67 return __VA_ARGS__; \ 68 } \ 69 } while (0) 70 71 #define WRITESTRING16(parcel, data, ...) \ 72 do { \ 73 if (!(parcel).WriteString16(data)) { \ 74 SEN_HILOGE("Parcel writeString16 "#data" failed"); \ 75 return __VA_ARGS__; \ 76 } \ 77 } while (0) 78 79 #define WRITEREMOTEOBJECT(parcel, data, ...) \ 80 do { \ 81 if (!(parcel).WriteRemoteObject(data)) { \ 82 SEN_HILOGE("Parcel writeRemoteObject "#data" failed"); \ 83 return __VA_ARGS__; \ 84 } \ 85 } while (0) 86 87 #define WRITEUINT8VECTOR(parcel, data, ...) \ 88 do { \ 89 if (!(parcel).WriteUInt8Vector(data)) { \ 90 SEN_HILOGE("Parcel writeUInt8Vector "#data" failed"); \ 91 return __VA_ARGS__; \ 92 } \ 93 } while (0) 94 95 #define READBOOL(parcel, data, ...) \ 96 do { \ 97 if (!(parcel).ReadBool(data)) { \ 98 SEN_HILOGE("Parcel readBool "#data" failed"); \ 99 return __VA_ARGS__; \ 100 } \ 101 } while (0) 102 103 #define READINT32(parcel, data, ...) \ 104 do { \ 105 if (!(parcel).ReadInt32(data)) { \ 106 SEN_HILOGE("Parcel readInt32 "#data" failed"); \ 107 return __VA_ARGS__; \ 108 } \ 109 } while (0) 110 111 #define READINT64(parcel, data, ...) \ 112 do { \ 113 if (!(parcel).ReadInt64(data)) { \ 114 SEN_HILOGE("Parcel readInt64 "#data" failed"); \ 115 return __VA_ARGS__; \ 116 } \ 117 } while (0) 118 119 #define READUINT32(parcel, data, ...) \ 120 do { \ 121 if (!(parcel).ReadUint32(data)) { \ 122 SEN_HILOGE("Parcel readUint32 "#data" failed"); \ 123 return __VA_ARGS__; \ 124 } \ 125 } while (0) 126 127 #define READDOUBLE(parcel, data, ...) \ 128 do { \ 129 if (!(parcel).ReadDouble(data)) { \ 130 SEN_HILOGE("Parcel readDouble "#data" failed"); \ 131 return __VA_ARGS__; \ 132 } \ 133 } while (0) 134 135 #define READSTRING(parcel, data, ...) \ 136 do { \ 137 if (!(parcel).ReadString(data)) { \ 138 SEN_HILOGE("Parcel readString "#data" failed"); \ 139 return __VA_ARGS__; \ 140 } \ 141 } while (0) 142 143 #define READUINT8VECTOR(parcel, data, ...) \ 144 do { \ 145 if (!(parcel).ReadUInt8Vector(&data)) { \ 146 SEN_HILOGE("Parcel readUInt8Vector "#data" failed"); \ 147 return __VA_ARGS__; \ 148 } \ 149 } while (0) 150 151 #define READSTRING16(parcel, data, ...) \ 152 do { \ 153 if (!(parcel).ReadString16(data)) { \ 154 SEN_HILOGE("Parcel readString16 "#data" failed"); \ 155 return __VA_ARGS__; \ 156 } \ 157 } while (0) 158 } // namespace Sensors 159 } // namespace OHOS 160 #endif // SENSOR_PARCEL_H