• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_errors.h"
24 #include "work_sched_hilog.h"
25 
26 namespace OHOS {
27 namespace WorkScheduler {
28 #define TEST_LOG_FILE_PATH "/data/test_log_file"
29 #define RETURN_IF_WITH_RET(cond, retval) if (cond) {return (retval);}
30 #define RETURN_IF(cond) if (cond) {return;}
31 
32 #define RETURN_IF_WITH_LOG(cond, loginfo)                                           \
33     do {                                                                            \
34         if (cond) {                                                                 \
35             WS_HILOGE("%{public}s "#loginfo" ", __func__);           \
36             return;                                                                 \
37         }                                                                           \
38     } while (0)
39 
40 #define READ_PARCEL_NO_RET(parcel, type, out)                                       \
41     do {                                                                            \
42         if (!(parcel).Read##type(out)) {                                            \
43             WS_HILOGE("%{public}s read"#out" failed", __func__);     \
44             return;                                                                 \
45         }                                                                           \
46     } while (0)
47 }
48 
49 #define READ_PARCEL_WITHOUT_RET(parcel, type, out)                                       \
50     do {                                                                            \
51         if (!(parcel).Read##type(out)) {                                            \
52             WS_HILOGE("%{public}s read"#out" failed", __func__);     \
53         }                                                                           \
54     } while (0)
55 }
56 
57 #define WRITE_PARCEL_NO_RET(parcel, type, data)                                     \
58     do {                                                                            \
59         if (!(parcel).Write##type(data)) {                                          \
60             WS_HILOGE("%{public}s write "#data" failed", __func__);  \
61             return;                                                                 \
62         }                                                                           \
63     } while (0)
64 
65 #define READ_PARCEL_WITH_RET(parcel, type, out, retval)                             \
66     do {                                                                            \
67         if (!(parcel).Read##type(out)) {                                            \
68             WS_HILOGE("%{public}s read "#out" failed", __func__);    \
69             return (retval);                                                        \
70         }                                                                           \
71     } while (0)
72 
73 #define WRITE_PARCEL_WITHOUT_RET(parcel, type, data)                           \
74     do {                                                                            \
75         if (!(parcel).Write##type(data)) {                                          \
76             WS_HILOGE("%{public}s write "#data" failed", __func__);  \
77         }                                                                           \
78     } while (0)
79 
80 #define WRITE_PARCEL_WITH_RET(parcel, type, data, retval)                           \
81     do {                                                                            \
82         if (!(parcel).Write##type(data)) {                                          \
83             WS_HILOGE("%{public}s write "#data" failed", __func__);  \
84             return (retval);                                                        \
85         }                                                                           \
86     } while (0)
87 
88 #endif // FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_UTILS_COMMON_H