• 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 BEGET_EXT_API_H
17 #define BEGET_EXT_API_H
18 #include <stdint.h>
19 #include <stdarg.h>
20 #include <string.h>
21 
22 #ifdef __cplusplus
23 #if __cplusplus
24 extern "C" {
25 #endif
26 #endif
27 
28 #ifndef INIT_LOG_PATH
29 #define INIT_LOG_PATH STARTUP_INIT_UT_PATH"/data/init_agent/"
30 #endif
31 
32 #if defined(__GNUC__) && (__GNUC__ >= 4)
33     #define INIT_PUBLIC_API __attribute__((visibility ("default")))
34     #define INIT_INNER_API __attribute__((visibility ("default")))
35     #define INIT_LOCAL_API __attribute__((visibility("hidden")))
36 #else
37     #define INIT_PUBLIC_API
38     #define INIT_INNER_API
39     #define INIT_LOCAL_API
40 #endif
41 
42 typedef enum InitLogLevel {
43     INIT_DEBUG = 0,
44     INIT_INFO,
45     INIT_WARN,
46     INIT_ERROR,
47     INIT_FATAL
48 } InitLogLevel;
49 
50 #if (defined(STARTUP_INIT_TEST) || defined(APPSPAWN_TEST))
51 #define FILE_NAME   (strrchr((__FILE__), '/')  + 1)
52 #define STATIC
53 #else
54 #define FILE_NAME   (strrchr((__FILE__), '/') ? strrchr((__FILE__), '/') + 1 : (__FILE__))
55 #define STATIC static
56 #endif
57 
58 INIT_PUBLIC_API void StartupLog(InitLogLevel logLevel, uint32_t domain, const char *tag, const char *fmt, ...);
59 INIT_PUBLIC_API void SetInitLogLevel(InitLogLevel level);
60 
61 #define STARTUP_LOGV(domain, tag, fmt, ...) \
62     StartupLog(INIT_DEBUG, domain, tag, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
63 #define STARTUP_LOGI(domain, tag, fmt, ...) \
64     StartupLog(INIT_INFO, domain, tag, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
65 #define STARTUP_LOGW(domain, tag, fmt, ...) \
66     StartupLog(INIT_WARN, domain, tag, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
67 #define STARTUP_LOGE(domain, tag, fmt, ...) \
68     StartupLog(INIT_ERROR, domain, tag, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
69 #define STARTUP_LOGF(domain, tag, fmt, ...) \
70     StartupLog(INIT_FATAL, domain, tag, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
71 
72 #define BASE_DOMAIN 0xD002C00
73 #ifndef BEGET_DOMAIN
74 #define BEGET_DOMAIN (BASE_DOMAIN + 0xb)
75 #endif
76 #define BEGET_LABEL "BEGET"
77 #define BEGET_LOGI(fmt, ...) STARTUP_LOGI(BEGET_DOMAIN, BEGET_LABEL, fmt, ##__VA_ARGS__)
78 #define BEGET_LOGE(fmt, ...) STARTUP_LOGE(BEGET_DOMAIN, BEGET_LABEL, fmt, ##__VA_ARGS__)
79 #define BEGET_LOGV(fmt, ...) STARTUP_LOGV(BEGET_DOMAIN, BEGET_LABEL, fmt, ##__VA_ARGS__)
80 #define BEGET_LOGW(fmt, ...) STARTUP_LOGW(BEGET_DOMAIN, BEGET_LABEL, fmt, ##__VA_ARGS__)
81 
82 #define InitLogPrint(outFileName, logLevel, kLevel, fmt, ...) \
83     StartupLog(logLevel, BEGET_DOMAIN, kLevel, fmt, ##__VA_ARGS__)
84 
85 #define BEGET_ERROR_CHECK(ret, statement, format, ...) \
86     if (!(ret)) {                                     \
87         BEGET_LOGE(format, ##__VA_ARGS__);             \
88         statement;                                    \
89     }                                                 \
90 
91 #define BEGET_INFO_CHECK(ret, statement, format, ...) \
92     if (!(ret)) {                                    \
93         BEGET_LOGI(format, ##__VA_ARGS__);            \
94         statement;                                   \
95     }                                          \
96 
97 #define BEGET_WARNING_CHECK(ret, statement, format, ...) \
98     if (!(ret)) {                                     \
99         BEGET_LOGW(format, ##__VA_ARGS__);             \
100         statement;                                    \
101     }                                                 \
102 
103 #define BEGET_CHECK(ret, statement) \
104     if (!(ret)) {                  \
105         statement;                 \
106     }                         \
107 
108 #define BEGET_CHECK_RETURN_VALUE(ret, result) \
109     do {                                \
110         if (!(ret)) {                            \
111             return result;                       \
112         }                                  \
113     } while (0)
114 
115 #define BEGET_CHECK_ONLY_RETURN(ret) \
116     do {                                \
117         if (!(ret)) {                   \
118             return;                     \
119         } \
120     } while (0)
121 
122 #define BEGET_CHECK_ONLY_ELOG(ret, format, ...) \
123     do {                                       \
124         if (!(ret)) {                          \
125             BEGET_LOGE(format, ##__VA_ARGS__);  \
126         } \
127     } while (0)
128 
129 #ifdef __cplusplus
130 #if __cplusplus
131 }
132 #endif
133 #endif
134 #endif