1 /*
2  * Copyright (c) 2024 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 
16 #ifndef OHOS_ABILITY_RUNTIME_PARCEL_UTIL_H
17 #define OHOS_ABILITY_RUNTIME_PARCEL_UTIL_H
18 
19 #include "hilog_tag_wrapper.h"
20 
21 namespace OHOS {
22 namespace AppExecFwk {
23 #define PARCEL_UTIL_WRITE_NORET(parcel, type, value) \
24     do { \
25         if (!(parcel).Write##type(value)) { \
26             TAG_LOGE(AAFwkTag::APPMGR, "failed to write %{public}s", #value); \
27             return; \
28         } \
29     } while (0)
30 
31 #define PARCEL_UTIL_WRITE_RET_INT(parcel, type, value) \
32     do { \
33         if (!(parcel).Write##type(value)) { \
34             TAG_LOGE(AAFwkTag::APPMGR, "failed to write %{public}s", #value); \
35             return IPC_PROXY_ERR; \
36         } \
37     } while (0)
38 
39 #define PARCEL_UTIL_SENDREQ_NORET(code, data, reply, option) \
40     do { \
41         int32_t ret = SendRequest(code, data, reply, option); \
42         if (ret != NO_ERROR) { \
43             TAG_LOGE(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); \
44         } \
45     } while (0)
46 
47 #define PARCEL_UTIL_SENDREQ_RET_INT(code, data, reply, option) \
48     do { \
49         int32_t ret = SendRequest(code, data, reply, option); \
50         if (ret != NO_ERROR) { \
51             TAG_LOGE(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); \
52             return ret; \
53         } \
54     } while (0)
55 } // namespace AppExecFwk
56 } // namespace OHOS
57 #endif // OHOS_ABILITY_RUNTIME_PARCEL_UTIL_H
58