1 /*
2  * Copyright (c) 2022 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 FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_UTILS_COMMON_H
17 #define FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_UTILS_COMMON_H
18 
19 #include <fstream>
20 
21 #include <refbase.h>
22 
23 #include "work_sched_hilog.h"
24 
25 namespace OHOS {
26 namespace WorkScheduler {
27 #define TEST_LOG_FILE_PATH "/data/test_log_file"
28 #define RETURN_IF_WITH_RET(cond, retval) if (cond) {return (retval);}
29 #define RETURN_IF(cond) if (cond) {return;}
30 
31 #define RETURN_IF_WITH_LOG(cond, loginfo)                                           \
32     do {                                                                            \
33         if (cond) {                                                                 \
34             WS_HILOGE("%{public}s "#loginfo" ", __func__);           \
35             return;                                                                 \
36         }                                                                           \
37     } while (0)
38 } // namespace WorkScheduler
39 
40 #define READ_PARCEL_WITHOUT_RET(parcel, type, out)                                       \
41     do {                                                                            \
42         if (!(parcel).Read##type(out)) {                                            \
43             WS_HILOGE("%{public}s read"#out" failed", __func__);     \
44         }                                                                           \
45     } while (0)
46 } // namespace OHOS
47 
48 #define WRITE_PARCEL_WITHOUT_RET(parcel, type, data)                           \
49     do {                                                                            \
50         if (!(parcel).Write##type(data)) {                                          \
51             WS_HILOGE("%{public}s write "#data" failed", __func__);  \
52         }                                                                           \
53     } while (0)
54 #endif // FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_UTILS_COMMON_H