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 <stdio.h> 20 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 0xD002B00 28 #define LOG_TAG "CAMERA" 29 #define MAX_STRING_SIZE 256 30 31 #define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) 32 33 #define DECORATOR_HILOG(op, fmt, args...) \ 34 do { \ 35 op(LOG_CORE, "{%{public}s()-%{public}s:%{public}d} " fmt, __FUNCTION__, __FILENAME__, __LINE__, ##args); \ 36 } while (0) 37 38 #define MEDIA_DEBUG_LOG(fmt, ...) DECORATOR_HILOG(HILOG_DEBUG, fmt, ##__VA_ARGS__) 39 #define MEDIA_ERR_LOG(fmt, ...) DECORATOR_HILOG(HILOG_ERROR, fmt, ##__VA_ARGS__) 40 #define MEDIA_WARNING_LOG(fmt, ...) DECORATOR_HILOG(HILOG_WARN, fmt, ##__VA_ARGS__) 41 #define MEDIA_INFO_LOG(fmt, ...) DECORATOR_HILOG(HILOG_INFO, fmt, ##__VA_ARGS__) 42 #define MEDIA_FATAL_LOG(fmt, ...) DECORATOR_HILOG(HILOG_FATAL, fmt, ##__VA_ARGS__) 43 44 #define MEDIA_OK 0 45 #define MEDIA_INVALID_PARAM (-1) 46 #define MEDIA_INIT_FAIL (-2) 47 #define MEDIA_ERR (-3) 48 #define MEDIA_PERMISSION_DENIED (-4) 49 50 #define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...) \ 51 do { \ 52 if (!(cond)) { \ 53 MEDIA_ERR_LOG(fmt, ##__VA_ARGS__); \ 54 return ret; \ 55 } \ 56 } while (0) 57 58 #define CHECK_AND_RETURN_LOG(cond, fmt, ...) \ 59 do { \ 60 if (!(cond)) { \ 61 MEDIA_ERR_LOG(fmt, ##__VA_ARGS__); \ 62 return; \ 63 } \ 64 } while (0) 65 66 #define POINTER_MASK 0x00FFFFFF 67 68 #define CAMERA_SYNC_TRACE HITRACE_METER_NAME(HITRACE_TAG_ZCAMERA, __PRETTY_FUNCTION__) 69 70 #define CAMERA_SYSEVENT_STATISTIC(str) \ 71 do { \ 72 HiviewDFX::HiSysEvent::Write("CAMERA", "CAMERA_STATISTIC", \ 73 HiviewDFX::HiSysEvent::EventType::STATISTIC, \ 74 "MSG", str); \ 75 } while (0) 76 77 #define CAMERA_SYSEVENT_SECURITY(str) \ 78 do { \ 79 HiviewDFX::HiSysEvent::Write("CAMERA", "CAMERA_SECURITY", \ 80 HiviewDFX::HiSysEvent::EventType::SECURITY, \ 81 "MSG", str); \ 82 } while (0) 83 84 #define CAMERA_SYSEVENT_BEHAVIOR(str) \ 85 do { \ 86 HiviewDFX::HiSysEvent::Write("CAMERA", "CAMERA_STATE", \ 87 HiviewDFX::HiSysEvent::EventType::BEHAVIOR, \ 88 "MSG", str); \ 89 } while (0) 90 91 #define CAMERA_SYSEVENT_FAULT(str) \ 92 do { \ 93 HiviewDFX::HiSysEvent::Write("CAMERA", "CAMERA_ERR", \ 94 HiviewDFX::HiSysEvent::EventType::FAULT, \ 95 "MSG", str); \ 96 } while (0) 97 98 #define POWERMGR_SYSEVENT_CAMERA_CONNECT(pid, uid, camid, name) \ 99 do { \ 100 HiviewDFX::HiSysEvent::Write("CAMERA", "CAMERA_CONNECT", \ 101 HiviewDFX::HiSysEvent::EventType::STATISTIC, \ 102 "PID", pid, "UID", uid, "ID", camid, \ 103 "NAME", name); \ 104 } while (0) 105 106 #define POWERMGR_SYSEVENT_CAMERA_DISCONNECT(camid) \ 107 do { \ 108 HiviewDFX::HiSysEvent::Write("CAMERA", "CAMERA_DISCONNECT", \ 109 HiviewDFX::HiSysEvent::EventType::STATISTIC, \ 110 "ID", camid); \ 111 } while (0) 112 113 #define POWERMGR_SYSEVENT_TORCH_STATE(pid, uid, status) \ 114 do { \ 115 HiviewDFX::HiSysEvent::Write("CAMERA", "TORCH_STATE", \ 116 HiviewDFX::HiSysEvent::EventType::STATISTIC, \ 117 "PID", pid, "UID", uid, "STATE", status); \ 118 } while (0) 119 120 #define POWERMGR_SYSEVENT_CAMERA_CONFIG(type, width, height) \ 121 do { \ 122 HiviewDFX::HiSysEvent::Write("CAMERA", "CAMERA_CONFIG", \ 123 HiviewDFX::HiSysEvent::EventType::STATISTIC, \ 124 "TYPE", #type, "WIDTH", width, "HEIGHT", height); \ 125 } while (0) 126 127 #define POWERMGR_SYSEVENT_FLASH_ON() \ 128 do { \ 129 HiviewDFX::HiSysEvent::Write("CAMERA", "FLASHLIGHT_ON", \ 130 HiviewDFX::HiSysEvent::EventType::STATISTIC); \ 131 } while (0) 132 133 #define POWERMGR_SYSEVENT_FLASH_OFF() \ 134 do { \ 135 HiviewDFX::HiSysEvent::Write("CAMERA", "FLASHLIGHT_OFF", \ 136 HiviewDFX::HiSysEvent::EventType::STATISTIC); \ 137 } while (0) 138 139 #define CAMERA_START_ASYNC_TRACE(str, taskId) \ 140 do { \ 141 StartAsyncTrace(HITRACE_TAG_ZCAMERA, str, taskId, -1); \ 142 } while (0) 143 144 #define CAMERA_FINISH_ASYNC_TRACE(str, taskId) \ 145 do { \ 146 FinishAsyncTrace(HITRACE_TAG_ZCAMERA, str, taskId); \ 147 } while (0) 148 149 #endif // OHOS_CAMERA_LOG_H 150