beget_ext.h 4.7 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>
X
xionglei6 已提交
20 21 22 23 24 25 26

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

X
xionglei6 已提交
27 28 29
#ifndef INIT_LOG_PATH
#define INIT_LOG_PATH "/data/init_agent/"
#endif
L
laiguizhong 已提交
30 31 32

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

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

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

INIT_PUBLIC_API void StartupLog(InitLogLevel logLevel, uint32_t domain, const char *tag, const char *fmt, ...);
INIT_PUBLIC_API void EnableInitLog(InitLogLevel level);
INIT_PUBLIC_API void SetInitCommLog(InitCommLog logFunc);
X
xionglei6 已提交
55

X
xionglei6 已提交
56
#define STARTUP_LOGV(domain, tag, fmt, ...) \
M
Mupceet 已提交
57
    StartupLog(INIT_DEBUG, domain, tag, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
X
xionglei6 已提交
58
#define STARTUP_LOGI(domain, tag, fmt, ...) \
M
Mupceet 已提交
59
    StartupLog(INIT_INFO, domain, tag, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
X
xionglei6 已提交
60
#define STARTUP_LOGW(domain, tag, fmt, ...) \
M
Mupceet 已提交
61
    StartupLog(INIT_WARN, domain, tag, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
X
xionglei6 已提交
62
#define STARTUP_LOGE(domain, tag, fmt, ...) \
M
Mupceet 已提交
63
    StartupLog(INIT_ERROR, domain, tag, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
X
xionglei6 已提交
64
#define STARTUP_LOGF(domain, tag, fmt, ...) \
M
Mupceet 已提交
65
    StartupLog(INIT_FATAL, domain, tag, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
X
xionglei6 已提交
66

X
xionglei6 已提交
67 68
#define BASE_DOMAIN 0xA000
#ifndef BEGET_DOMAIN
X
xionglei6 已提交
69
#define BEGET_DOMAIN (BASE_DOMAIN + 0xb)
X
xionglei6 已提交
70
#endif
X
xionglei6 已提交
71
#define BEGET_LABEL "BEGET"
X
xionglei6 已提交
72 73 74 75
#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 已提交
76

X
xionglei6 已提交
77
#define InitLogPrint(outFileName, logLevel, kLevel, fmt, ...) \
M
Mupceet 已提交
78
    StartupLog(logLevel, BEGET_DOMAIN, kLevel, fmt, ##__VA_ARGS__)
X
xionglei6 已提交
79

X
xionglei6 已提交
80 81 82 83 84 85 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
#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