beget_ext.h 4.9 KB
Newer Older
X
xionglei6 已提交
1
/*
M
Mupceet 已提交
2
 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
X
xionglei6 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef BEGET_EXT_API_H
#define BEGET_EXT_API_H
M
Mupceet 已提交
18
#include <stdint.h>
M
Mupceet 已提交
19
#include <stdarg.h>
M
Mupceet 已提交
20
#include <string.h>
X
xionglei6 已提交
21 22 23 24 25 26 27

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif

C
cheng_jinsong 已提交
28 29
#define INIT_DEBUG_LEVEL "persist.init.debug.loglevel"

X
xionglei6 已提交
30 31 32
#ifndef INIT_LOG_PATH
#define INIT_LOG_PATH "/data/init_agent/"
#endif
L
laiguizhong 已提交
33 34 35

#if defined(__GNUC__) && (__GNUC__ >= 4)
    #define INIT_PUBLIC_API __attribute__((visibility ("default")))
M
Mupceet 已提交
36
    #define INIT_INNER_API __attribute__((visibility ("default")))
L
laiguizhong 已提交
37 38 39
    #define INIT_LOCAL_API __attribute__((visibility("hidden")))
#else
    #define INIT_PUBLIC_API
M
Mupceet 已提交
40
    #define INIT_INNER_API
L
laiguizhong 已提交
41 42 43
    #define INIT_LOCAL_API
#endif

X
xionglei6 已提交
44 45 46 47 48 49 50 51
typedef enum InitLogLevel {
    INIT_DEBUG = 0,
    INIT_INFO,
    INIT_WARN,
    INIT_ERROR,
    INIT_FATAL
} InitLogLevel;

M
Mupceet 已提交
52
typedef void (*InitCommLog)(int logLevel, uint32_t domain, const char *tag, const char *fmt, va_list vargs);
X
xionglei6 已提交
53
#define FILE_NAME   (strrchr((__FILE__), '/') ? strrchr((__FILE__), '/') + 1 : (__FILE__))
M
Mupceet 已提交
54 55

INIT_PUBLIC_API void StartupLog(InitLogLevel logLevel, uint32_t domain, const char *tag, const char *fmt, ...);
C
cheng_jinsong 已提交
56
INIT_PUBLIC_API void EnableInitLog(InitLogLevel level);
C
cheng_jinsong 已提交
57 58
INIT_PUBLIC_API void SetInitLogLevel(InitLogLevel level);
INIT_PUBLIC_API int GetInitLogLevel(void);
M
Mupceet 已提交
59
INIT_PUBLIC_API void SetInitCommLog(InitCommLog logFunc);
C
cheng_jinsong 已提交
60
INIT_PUBLIC_API void EnableInitLogFromCmdline(void);
X
xionglei6 已提交
61

X
xionglei6 已提交
62
#define STARTUP_LOGV(domain, tag, fmt, ...) \
M
Mupceet 已提交
63
    StartupLog(INIT_DEBUG, domain, tag, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
X
xionglei6 已提交
64
#define STARTUP_LOGI(domain, tag, fmt, ...) \
M
Mupceet 已提交
65
    StartupLog(INIT_INFO, domain, tag, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
X
xionglei6 已提交
66
#define STARTUP_LOGW(domain, tag, fmt, ...) \
M
Mupceet 已提交
67
    StartupLog(INIT_WARN, domain, tag, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
X
xionglei6 已提交
68
#define STARTUP_LOGE(domain, tag, fmt, ...) \
M
Mupceet 已提交
69
    StartupLog(INIT_ERROR, domain, tag, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
X
xionglei6 已提交
70
#define STARTUP_LOGF(domain, tag, fmt, ...) \
M
Mupceet 已提交
71
    StartupLog(INIT_FATAL, domain, tag, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
X
xionglei6 已提交
72

L
laiguizhong 已提交
73
#define BASE_DOMAIN 0xD002C00
X
xionglei6 已提交
74
#ifndef BEGET_DOMAIN
X
xionglei6 已提交
75
#define BEGET_DOMAIN (BASE_DOMAIN + 0xb)
X
xionglei6 已提交
76
#endif
X
xionglei6 已提交
77
#define BEGET_LABEL "BEGET"
X
xionglei6 已提交
78 79 80 81
#define BEGET_LOGI(fmt, ...) STARTUP_LOGI(BEGET_DOMAIN, BEGET_LABEL, fmt, ##__VA_ARGS__)
#define BEGET_LOGE(fmt, ...) STARTUP_LOGE(BEGET_DOMAIN, BEGET_LABEL, fmt, ##__VA_ARGS__)
#define BEGET_LOGV(fmt, ...) STARTUP_LOGV(BEGET_DOMAIN, BEGET_LABEL, fmt, ##__VA_ARGS__)
#define BEGET_LOGW(fmt, ...) STARTUP_LOGW(BEGET_DOMAIN, BEGET_LABEL, fmt, ##__VA_ARGS__)
X
xionglei6 已提交
82

X
xionglei6 已提交
83
#define InitLogPrint(outFileName, logLevel, kLevel, fmt, ...) \
M
Mupceet 已提交
84
    StartupLog(logLevel, BEGET_DOMAIN, kLevel, fmt, ##__VA_ARGS__)
X
xionglei6 已提交
85

X
xionglei6 已提交
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
#define BEGET_ERROR_CHECK(ret, statement, format, ...) \
    if (!(ret)) {                                     \
        BEGET_LOGE(format, ##__VA_ARGS__);             \
        statement;                                    \
    }                                                 \

#define BEGET_INFO_CHECK(ret, statement, format, ...) \
    if (!(ret)) {                                    \
        BEGET_LOGI(format, ##__VA_ARGS__);            \
        statement;                                   \
    }                                          \

#define BEGET_WARNING_CHECK(ret, statement, format, ...) \
    if (!(ret)) {                                     \
        BEGET_LOGW(format, ##__VA_ARGS__);             \
        statement;                                    \
    }                                                 \

#define BEGET_CHECK(ret, statement) \
    if (!(ret)) {                  \
        statement;                 \
    }                         \

#define BEGET_CHECK_RETURN_VALUE(ret, result) \
    do {                                \
        if (!(ret)) {                            \
            return result;                       \
        }                                  \
    } while (0)

#define BEGET_CHECK_ONLY_RETURN(ret) \
    do {                                \
        if (!(ret)) {                   \
            return;                     \
        } \
    } while (0)

#define BEGET_CHECK_ONLY_ELOG(ret, format, ...) \
    do {                                       \
        if (!(ret)) {                          \
            BEGET_LOGE(format, ##__VA_ARGS__);  \
        } \
    } while (0)

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
#endif