1 /* 2 * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved. 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 16 #ifndef DEFINE_MACRO_H 17 #define DEFINE_MACRO_H 18 19 namespace OHOS::Developtools::NativeDaemon { 20 #ifndef RET_OK 21 #define RET_OK (0) 22 #endif 23 24 #ifndef RET_ERR 25 #define RET_ERR (-1) 26 #endif 27 } // namespace OHOS::Developtools::NativeDaemon 28 29 #define DEFRET_1(data, value, ...) (value) 30 #define DEFRET(...) DEFRET_1(__VA_ARGS__, false) 31 32 #define WRITEBOOL(parcel, data, ...) \ 33 do { \ 34 if (!(parcel).WriteBool(data)) { \ 35 PROFILER_LOG_ERROR(LOG_CORE, "WriteBool "#data" failed"); \ 36 return DEFRET(false, ##__VA_ARGS__); \ 37 } \ 38 } while (0) 39 40 #define WRITEINT32(parcel, data, ...) \ 41 do { \ 42 if (!(parcel).WriteInt32(data)) { \ 43 PROFILER_LOG_ERROR(LOG_CORE, "WriteInt32 "#data" failed"); \ 44 return DEFRET(false, ##__VA_ARGS__); \ 45 } \ 46 } while (0) 47 48 #define WRITEINT64(parcel, data, ...) \ 49 do { \ 50 if (!(parcel).WriteInt64(data)) { \ 51 PROFILER_LOG_ERROR(LOG_CORE, "WriteInt64 "#data" failed"); \ 52 return DEFRET(false, ##__VA_ARGS__); \ 53 } \ 54 } while (0) 55 56 #define WRITEUINT8(parcel, data, ...) \ 57 do { \ 58 if (!(parcel).WriteUint8(data)) { \ 59 PROFILER_LOG_ERROR(LOG_CORE, "WriteUint8 "#data" failed"); \ 60 return DEFRET(false, ##__VA_ARGS__); \ 61 } \ 62 } while (0) 63 64 #define WRITEUINT32(parcel, data, ...) \ 65 do { \ 66 if (!(parcel).WriteUint32(data)) { \ 67 PROFILER_LOG_ERROR(LOG_CORE, "WriteUint32 "#data" failed"); \ 68 return DEFRET(false, ##__VA_ARGS__); \ 69 } \ 70 } while (0) 71 72 #define WRITEUINT64(parcel, data, ...) \ 73 do { \ 74 if (!(parcel).WriteUint64(data)) { \ 75 PROFILER_LOG_ERROR(LOG_CORE, "WriteUint64 "#data" failed"); \ 76 return DEFRET(false, ##__VA_ARGS__); \ 77 } \ 78 } while (0) 79 80 #define WRITESTRING(parcel, data, ...) \ 81 do { \ 82 if (!(parcel).WriteString(data)) { \ 83 PROFILER_LOG_ERROR(LOG_CORE, "WriteString "#data" failed"); \ 84 return DEFRET(false, ##__VA_ARGS__); \ 85 } \ 86 } while (0) 87 88 #define READBOOL(parcel, data, ...) \ 89 do { \ 90 if (!(parcel).ReadBool(data)) { \ 91 PROFILER_LOG_ERROR(LOG_CORE, "ReadBool "#data" failed"); \ 92 return DEFRET(false, ##__VA_ARGS__); \ 93 } \ 94 } while (0) 95 96 #define READINT32(parcel, data, ...) \ 97 do { \ 98 if (!(parcel).ReadInt32(data)) { \ 99 PROFILER_LOG_ERROR(LOG_CORE, "ReadInt32 "#data" failed"); \ 100 return DEFRET(false, ##__VA_ARGS__); \ 101 } \ 102 } while (0) 103 104 #define READINT64(parcel, data, ...) \ 105 do { \ 106 if (!(parcel).ReadInt64(data)) { \ 107 PROFILER_LOG_ERROR(LOG_CORE, "ReadInt64 "#data" failed"); \ 108 return DEFRET(false, ##__VA_ARGS__); \ 109 } \ 110 } while (0) 111 112 #define READUINT8(parcel, data, ...) \ 113 do { \ 114 if (!(parcel).ReadUint8(data)) { \ 115 PROFILER_LOG_ERROR(LOG_CORE, "ReadUint8 "#data" failed"); \ 116 return DEFRET(false, ##__VA_ARGS__); \ 117 } \ 118 } while (0) 119 120 #define READUINT32(parcel, data, ...) \ 121 do { \ 122 if (!(parcel).ReadUint32(data)) { \ 123 PROFILER_LOG_ERROR(LOG_CORE, "ReadUint32 "#data" failed"); \ 124 return DEFRET(false, ##__VA_ARGS__); \ 125 } \ 126 } while (0) 127 128 #define READUINT64(parcel, data, ...) \ 129 do { \ 130 if (!(parcel).ReadUint64(data)) { \ 131 PROFILER_LOG_ERROR(LOG_CORE, "ReadUint64 "#data" failed"); \ 132 return DEFRET(false, ##__VA_ARGS__); \ 133 } \ 134 } while (0) 135 136 #define READSTRING(parcel, data, ...) \ 137 do { \ 138 if (!(parcel).ReadString(data)) { \ 139 PROFILER_LOG_ERROR(LOG_CORE, "ReadString "#data" failed"); \ 140 return DEFRET(false, ##__VA_ARGS__); \ 141 } \ 142 } while (0) 143 144 #endif // DEFINE_MACRO_H