• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::CAMERA, "CAMERA_STATISTIC", \
73                                      HiviewDFX::HiSysEvent::EventType::STATISTIC,  \
74                                      "MSG", str);                                  \
75     } while (0)
76 
77 #define CAMERA_SYSEVENT_SECURITY(str)                                              \
78     do {                                                                           \
79         HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::CAMERA, "CAMERA_SECURITY",   \
80                                      HiviewDFX::HiSysEvent::EventType::SECURITY,   \
81                                      "MSG", str);                                  \
82     } while (0)
83 
84 #define CAMERA_SYSEVENT_BEHAVIOR(str)                                              \
85     do {                                                                           \
86         HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::CAMERA, "CAMERA_STATE",     \
87                                      HiviewDFX::HiSysEvent::EventType::BEHAVIOR,   \
88                                      "MSG", str);                                  \
89     } while (0)
90 
91 #define CAMERA_SYSEVENT_FAULT(str)                                                 \
92     do {                                                                           \
93         HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::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         HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::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         HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::CAMERA,                     \
109                                      "CAMERA_DISCONNECT",                          \
110                                      HiviewDFX::HiSysEvent::EventType::STATISTIC,  \
111                                      "ID", camid);                                 \
112     } while (0)
113 
114 #define POWERMGR_SYSEVENT_TORCH_STATE(pid, uid, status)                            \
115     do {                                                                           \
116         HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::CAMERA, "TORCH_STATE",      \
117                                      HiviewDFX::HiSysEvent::EventType::STATISTIC,  \
118                                      "PID", pid, "UID", uid, "STATE", status);     \
119     } while (0)
120 
121 #define POWERMGR_SYSEVENT_CAMERA_CONFIG(type, width, height)                           \
122     do {                                                                               \
123         HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::CAMERA, "CAMERA_CONFIG",        \
124                                      HiviewDFX::HiSysEvent::EventType::STATISTIC,      \
125                                      "TYPE", #type, "WIDTH", width, "HEIGHT", height); \
126     } while (0)
127 
128 #define POWERMGR_SYSEVENT_FLASH_ON()                                               \
129     do {                                                                           \
130         HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::CAMERA, "FLASHLIGHT_ON",    \
131                                      HiviewDFX::HiSysEvent::EventType::STATISTIC); \
132     } while (0)
133 
134 #define POWERMGR_SYSEVENT_FLASH_OFF()                                              \
135     do {                                                                           \
136         HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::CAMERA, "FLASHLIGHT_OFF",   \
137                                      HiviewDFX::HiSysEvent::EventType::STATISTIC); \
138     } while (0)
139 
140 #define CAMERA_START_ASYNC_TRACE(str, taskId)                                      \
141     do {                                                                           \
142         StartAsyncTrace(HITRACE_TAG_ZCAMERA, str, taskId, -1);                     \
143     } while (0)
144 
145 #define CAMERA_FINISH_ASYNC_TRACE(str, taskId)                                     \
146     do {                                                                           \
147         FinishAsyncTrace(HITRACE_TAG_ZCAMERA, str, taskId);                        \
148     } while (0)
149 
150 #endif // OHOS_CAMERA_LOG_H
151