1 /* 2 * Copyright (c) 2021-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 OHOS_CAMERA_LOG_H 17 #define OHOS_CAMERA_LOG_H 18 19 #include <cstdio> 20 #include <cinttypes> 21 #include "hilog/log.h" 22 #include "hisysevent.h" 23 #include "hitrace_meter.h" 24 25 #undef LOG_DOMAIN 26 #undef LOG_TAG 27 #define LOG_DOMAIN 0xD002B01 28 #define LOG_TAG "CAMERA" 29 #define MAX_STRING_SIZE 256 30 31 #ifndef IS_RELEASE_VERSION 32 #define DECORATOR_HILOG(op, fmt, args...) \ 33 do { \ 34 op(LOG_CORE, "{%{public}s()-%{public}s:%{public}d} " fmt, __FUNCTION__, __FILE_NAME__, __LINE__, ##args); \ 35 } while (0) 36 #else 37 #define DECORATOR_HILOG(op, fmt, args...) \ 38 do { \ 39 op(LOG_CORE, "{%{public}s():%{public}d} " fmt, __FUNCTION__, __LINE__, ##args); \ 40 } while (0) 41 #endif 42 43 #define MEDIA_DEBUG_LOG(fmt, ...) DECORATOR_HILOG(HILOG_DEBUG, fmt, ##__VA_ARGS__) 44 #define MEDIA_ERR_LOG(fmt, ...) DECORATOR_HILOG(HILOG_ERROR, fmt, ##__VA_ARGS__) 45 #define MEDIA_WARNING_LOG(fmt, ...) DECORATOR_HILOG(HILOG_WARN, fmt, ##__VA_ARGS__) 46 #define MEDIA_INFO_LOG(fmt, ...) DECORATOR_HILOG(HILOG_INFO, fmt, ##__VA_ARGS__) 47 #define MEDIA_FATAL_LOG(fmt, ...) DECORATOR_HILOG(HILOG_FATAL, fmt, ##__VA_ARGS__) 48 49 #define MEDIA_OK 0 50 #define MEDIA_INVALID_PARAM (-1) 51 #define MEDIA_INIT_FAIL (-2) 52 #define MEDIA_ERR (-3) 53 #define MEDIA_PERMISSION_DENIED (-4) 54 55 #define CHECK_ERROR_RETURN_RET_LOG(cond, ret, fmt, ...) \ 56 do { \ 57 if (cond) { \ 58 MEDIA_ERR_LOG(fmt, ##__VA_ARGS__); \ 59 return ret; \ 60 } \ 61 } while (0) 62 63 #define CHECK_ERROR_RETURN(cond) \ 64 do { \ 65 if (cond) { \ 66 return; \ 67 } \ 68 } while (0) 69 70 #define CHECK_ERROR_RETURN_LOG(cond, fmt, ...) \ 71 do { \ 72 if (cond) { \ 73 MEDIA_ERR_LOG(fmt, ##__VA_ARGS__); \ 74 return; \ 75 } \ 76 } while (0) 77 78 #define CHECK_ERROR_PRINT_LOG(cond, fmt, ...) \ 79 do { \ 80 if (cond) { \ 81 MEDIA_ERR_LOG(fmt, ##__VA_ARGS__); \ 82 } \ 83 } while (0) 84 85 #define CHECK_ERROR_RETURN_RET(cond, ret) \ 86 do { \ 87 if (cond) { \ 88 return ret; \ 89 } \ 90 } while (0) 91 92 #define CHECK_WARNING_BREAK_LOG(cond, fmt, ...) \ 93 if (1) { \ 94 if (cond) { \ 95 MEDIA_WARNING_LOG(fmt, ##__VA_ARGS__); \ 96 break; \ 97 } \ 98 } else void (0) 99 100 #define CHECK_WARNING_CONTINUE_LOG(cond, fmt, ...) \ 101 if (1) { \ 102 if (cond) { \ 103 MEDIA_WARNING_LOG(fmt, ##__VA_ARGS__); \ 104 continue; \ 105 } \ 106 } else void (0) 107 108 #define CHECK_EXECUTE(cond, cmd) \ 109 do { \ 110 if (cond) { \ 111 cmd; \ 112 } \ 113 } while (0) 114 115 #define POINTER_MASK 0x00FFFFFF 116 117 #define CAMERA_SYNC_TRACE HITRACE_METER_NAME(HITRACE_TAG_ZCAMERA, __PRETTY_FUNCTION__) 118 119 #define CAMERA_SYSEVENT_STATISTIC(str) \ 120 do { \ 121 HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::CAMERA, "CAMERA_STATISTIC", \ 122 HiviewDFX::HiSysEvent::EventType::STATISTIC, \ 123 "MSG", str); \ 124 } while (0) 125 126 #define CAMERA_SYSEVENT_SECURITY(str) \ 127 do { \ 128 HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::CAMERA, "CAMERA_SECURITY", \ 129 HiviewDFX::HiSysEvent::EventType::SECURITY, \ 130 "MSG", str); \ 131 } while (0) 132 133 #define CAMERA_SYSEVENT_BEHAVIOR(str) \ 134 do { \ 135 HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::CAMERA, "CAMERA_STATE", \ 136 HiviewDFX::HiSysEvent::EventType::BEHAVIOR, \ 137 "MSG", str); \ 138 } while (0) 139 140 #define CAMERA_SYSEVENT_FAULT(str) \ 141 do { \ 142 HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::CAMERA, "CAMERA_ERR", \ 143 HiviewDFX::HiSysEvent::EventType::FAULT, \ 144 "MSG", str); \ 145 } while (0) 146 147 #define POWERMGR_SYSEVENT_CAMERA_CONNECT(pid, uid, camid, name) \ 148 do { \ 149 HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::CAMERA, "CAMERA_CONNECT", \ 150 HiviewDFX::HiSysEvent::EventType::STATISTIC, \ 151 "PID", pid, "UID", uid, "ID", camid, \ 152 "NAME", name); \ 153 } while (0) 154 155 #define POWERMGR_SYSEVENT_CAMERA_DISCONNECT(camid) \ 156 do { \ 157 HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::CAMERA, \ 158 "CAMERA_DISCONNECT", \ 159 HiviewDFX::HiSysEvent::EventType::STATISTIC, \ 160 "ID", camid); \ 161 } while (0) 162 163 #define POWERMGR_SYSEVENT_TORCH_STATE(pid, uid, status) \ 164 do { \ 165 HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::CAMERA, "TORCH_STATE", \ 166 HiviewDFX::HiSysEvent::EventType::STATISTIC, \ 167 "PID", pid, "UID", uid, "STATE", status); \ 168 } while (0) 169 170 #define POWERMGR_SYSEVENT_CAMERA_CONFIG(type, width, height) \ 171 do { \ 172 HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::CAMERA, "CAMERA_CONFIG", \ 173 HiviewDFX::HiSysEvent::EventType::STATISTIC, \ 174 "TYPE", #type, "WIDTH", width, "HEIGHT", height); \ 175 } while (0) 176 177 #define POWERMGR_SYSEVENT_FLASH_ON() \ 178 do { \ 179 HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::CAMERA, "FLASHLIGHT_ON", \ 180 HiviewDFX::HiSysEvent::EventType::STATISTIC); \ 181 } while (0) 182 183 #define POWERMGR_SYSEVENT_FLASH_OFF() \ 184 do { \ 185 HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::CAMERA, "FLASHLIGHT_OFF", \ 186 HiviewDFX::HiSysEvent::EventType::STATISTIC); \ 187 } while (0) 188 189 #define CAMERA_START_ASYNC_TRACE(str, taskId) \ 190 do { \ 191 StartAsyncTrace(HITRACE_TAG_ZCAMERA, str, taskId, -1); \ 192 } while (0) 193 194 #define CAMERA_FINISH_ASYNC_TRACE(str, taskId) \ 195 do { \ 196 FinishAsyncTrace(HITRACE_TAG_ZCAMERA, str, taskId); \ 197 } while (0) 198 199 #endif // OHOS_CAMERA_LOG_H 200