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>
M
Mupceet 已提交
20
#include <string.h>
X
xionglei6 已提交
21 22 23 24 25 26 27

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

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

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

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

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

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 已提交
56

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

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

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

X
xionglei6 已提交
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 130
#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