beget_ext.h 3.6 KB
Newer Older
X
xionglei6 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * 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

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

typedef enum InitLogLevel {
    INIT_DEBUG = 0,
    INIT_INFO,
    INIT_WARN,
    INIT_ERROR,
    INIT_FATAL
} InitLogLevel;

#define FILE_NAME   (strrchr((__FILE__), '/') ? strrchr((__FILE__), '/') + 1 : (__FILE__))
X
fix log  
xionglei6 已提交
34 35
void SetInitLogLevel(InitLogLevel logLevel);
void InitLog(InitLogLevel logLevel, const char *domain, const char *fileName, int line, const char *fmt, ...);
X
xionglei6 已提交
36

X
fix log  
xionglei6 已提交
37 38 39 40 41
#define STARTUP_LOGV(domain, fmt, ...) InitLog(INIT_DEBUG, domain, (FILE_NAME), (__LINE__), fmt, ##__VA_ARGS__)
#define STARTUP_LOGI(domain, fmt, ...) InitLog(INIT_INFO, domain, (FILE_NAME), (__LINE__), fmt, ##__VA_ARGS__)
#define STARTUP_LOGW(domain, fmt, ...) InitLog(INIT_WARN, domain, (FILE_NAME), (__LINE__), fmt, ##__VA_ARGS__)
#define STARTUP_LOGE(domain, fmt, ...) InitLog(INIT_ERROR, domain, (FILE_NAME), (__LINE__), fmt, ##__VA_ARGS__)
#define STARTUP_LOGF(domain, fmt, ...) InitLog(INIT_FATAL, domain, (FILE_NAME), (__LINE__), fmt, ##__VA_ARGS__)
X
xionglei6 已提交
42 43

#define BEGET_LABEL "BEGET"
X
fix log  
xionglei6 已提交
44 45 46 47
#define BEGET_LOGI(fmt, ...) STARTUP_LOGI(BEGET_LABEL, fmt, ##__VA_ARGS__)
#define BEGET_LOGE(fmt, ...) STARTUP_LOGE(BEGET_LABEL, fmt, ##__VA_ARGS__)
#define BEGET_LOGV(fmt, ...) STARTUP_LOGV(BEGET_LABEL, fmt, ##__VA_ARGS__)
#define BEGET_LOGW(fmt, ...) STARTUP_LOGW(BEGET_LABEL, fmt, ##__VA_ARGS__)
X
xionglei6 已提交
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98

#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