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 39 #define READ_PARCEL_NO_RET(parcel, type, out) \ 40 do { \ 41 if (!(parcel).Read##type(out)) { \ 42 WS_HILOGE("%{public}s read"#out" failed", __func__); \ 43 return; \ 44 } \ 45 } while (0) 46 } // namespace WorkScheduler 47 48 #define READ_PARCEL_WITHOUT_RET(parcel, type, out) \ 49 do { \ 50 if (!(parcel).Read##type(out)) { \ 51 WS_HILOGE("%{public}s read"#out" failed", __func__); \ 52 } \ 53 } while (0) 54 } // namespace OHOS 55 56 #define WRITE_PARCEL_NO_RET(parcel, type, data) \ 57 do { \ 58 if (!(parcel).Write##type(data)) { \ 59 WS_HILOGE("%{public}s write "#data" failed", __func__); \ 60 return; \ 61 } \ 62 } while (0) 63 64 #define READ_PARCEL_WITH_RET(parcel, type, out, retval) \ 65 do { \ 66 if (!(parcel).Read##type(out)) { \ 67 WS_HILOGE("%{public}s read "#out" failed", __func__); \ 68 return (retval); \ 69 } \ 70 } while (0) 71 72 #define WRITE_PARCEL_WITHOUT_RET(parcel, type, data) \ 73 do { \ 74 if (!(parcel).Write##type(data)) { \ 75 WS_HILOGE("%{public}s write "#data" failed", __func__); \ 76 } \ 77 } while (0) 78 79 #define WRITE_PARCEL_WITH_RET(parcel, type, data, retval) \ 80 do { \ 81 if (!(parcel).Write##type(data)) { \ 82 WS_HILOGE("%{public}s write "#data" failed", __func__); \ 83 return (retval); \ 84 } \ 85 } while (0) 86 87 #endif // FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_UTILS_COMMON_H