ZLMediaKit/api/include/mk_util.h

257 lines
7.8 KiB
C++
Raw Normal View History

/*
2023-12-09 16:23:51 +08:00
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
*
2023-12-09 16:23:51 +08:00
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
*
2023-12-09 16:23:51 +08:00
* Use of this source code is governed by MIT-like license that can be found in the
2020-04-04 20:30:09 +08:00
* LICENSE file in the root of the source tree. All contributing project authors
* may be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MK_UTIL_H
#define MK_UTIL_H
#include <stdlib.h>
#include "mk_common.h"
#ifdef __cplusplus
extern "C" {
#endif
2023-02-11 11:39:26 +08:00
/**
* mk api内部malloc的资源
* Release resources allocated by mk api internally
* [AUTO-TRANSLATED:92ecfef5]
2023-02-11 11:39:26 +08:00
*/
API_EXPORT void API_CALL mk_free(void *ptr);
/**
*
2023-02-11 11:39:26 +08:00
* @return 使mk_free
* Get the path of the executable file of this program
* @return File path, need to be mk_free after use
* [AUTO-TRANSLATED:5f1fae7f]
*/
API_EXPORT char* API_CALL mk_util_get_exe_path();
/**
*
* @param relative_path ,null
2023-02-11 11:39:26 +08:00
* @return 使mk_free
* Get the absolute path of the file in the same directory as the executable file of this program
* @param relative_path The path of the file in the same directory, can be null
* @return File path, need to be mk_free after use
* [AUTO-TRANSLATED:80442e8e]
*/
2020-02-21 11:35:53 +08:00
API_EXPORT char* API_CALL mk_util_get_exe_dir(const char *relative_path);
/**
* unix标准的系统时间戳
* @return
* Get the Unix standard system timestamp
* @return Current system timestamp
* [AUTO-TRANSLATED:feddaa5b]
*/
2020-02-21 11:35:53 +08:00
API_EXPORT uint64_t API_CALL mk_util_get_current_millisecond();
/**
*
* @param fmt %Y-%m-%d %H:%M:%S
2023-02-11 11:39:26 +08:00
* @return 使mk_free
* Get the time string
* @param fmt Time format, such as %Y-%m-%d %H:%M:%S
* @return Time string, need to be mk_free after use
* [AUTO-TRANSLATED:c5a6c984]
*/
2020-02-21 11:35:53 +08:00
API_EXPORT char* API_CALL mk_util_get_current_time_string(const char *fmt);
/**
*
* @param buf
* @param len
2023-02-11 11:39:26 +08:00
* @return 使mk_free
* Print binary data as string
* @param buf Binary data
* @param len Data length
* @return Printable debug information, need to be mk_free after use
* [AUTO-TRANSLATED:5b76b3a5]
*/
2020-02-21 11:35:53 +08:00
API_EXPORT char* API_CALL mk_util_hex_dump(const void *buf, int len);
2023-02-11 11:39:26 +08:00
///////////////////////////////////////////mk ini/////////////////////////////////////////////
typedef struct mk_ini_t *mk_ini;
2023-02-11 11:39:26 +08:00
/**
* ini配置对象
* Create ini configuration object
* [AUTO-TRANSLATED:b8ce40cc]
2023-02-11 11:39:26 +08:00
*/
API_EXPORT mk_ini API_CALL mk_ini_create();
/**
* ini配置
* @return ini配置mk_ini_release释放它
* Return the global default ini configuration
* @return Global default ini configuration, do not use mk_ini_release to release it
* [AUTO-TRANSLATED:057ea031]
2023-02-11 11:39:26 +08:00
*/
API_EXPORT mk_ini API_CALL mk_ini_default();
/**
* ini配置文件内容
* @param ini ini对象
* @param str
* Load ini configuration file content
* @param ini Ini object
* @param str Configuration file content
* [AUTO-TRANSLATED:b9366be5]
2023-02-11 11:39:26 +08:00
*/
API_EXPORT void API_CALL mk_ini_load_string(mk_ini ini, const char *str);
/**
* ini配置文件
* @param ini ini对象
* @param file
* Load ini configuration file
* @param ini Ini object
* @param file Configuration file path
* [AUTO-TRANSLATED:688e0471]
2023-02-11 11:39:26 +08:00
*/
API_EXPORT void API_CALL mk_ini_load_file(mk_ini ini, const char *file);
/**
* ini配置对象
* Destroy ini configuration object
* [AUTO-TRANSLATED:b6286ab8]
2023-02-11 11:39:26 +08:00
*/
API_EXPORT void API_CALL mk_ini_release(mk_ini ini);
/**
*
* @param ini
* @param key field.key
* @param value
* Add or overwrite configuration item
* @param ini Configuration object
* @param key Configuration name, two-part, such as: field.key
* @param value Configuration value
* [AUTO-TRANSLATED:1b2c8bfa]
2023-02-11 11:39:26 +08:00
*/
API_EXPORT void API_CALL mk_ini_set_option(mk_ini ini, const char *key, const char *value);
API_EXPORT void API_CALL mk_ini_set_option_int(mk_ini ini, const char *key, int value);
/**
*
* @param ini
* @param key field.key
* @return NULL
* Get configuration item
* @param ini Configuration object
* @param key Configuration name, two-part, such as: field.key
* @return NULL if the configuration does not exist, otherwise return the configuration value
* [AUTO-TRANSLATED:4df4bc65]
2023-02-11 11:39:26 +08:00
*/
API_EXPORT const char *API_CALL mk_ini_get_option(mk_ini ini, const char *key);
/**
*
* @param ini
* @param key field.key
* @return 1: 0:
* Delete configuration item
* @param ini Configuration object
* @param key Configuration name, two-part, such as: field.key
* @return 1: Success, 0: The configuration does not exist
* [AUTO-TRANSLATED:dbbbdca3]
2023-02-11 11:39:26 +08:00
*/
API_EXPORT int API_CALL mk_ini_del_option(mk_ini ini, const char *key);
/**
*
* @param ini
* @return mk_free
* Export to configuration file content
* @param ini Configuration object
* @return Configuration file content string, need to be mk_free after use
* [AUTO-TRANSLATED:94620b68]
2023-02-11 11:39:26 +08:00
*/
API_EXPORT char *API_CALL mk_ini_dump_string(mk_ini ini);
/**
*
* @param ini
* @param file
* Export configuration file to file
* @param ini Configuration object
* @param file Configuration file path
* [AUTO-TRANSLATED:8fac58af]
2023-02-11 11:39:26 +08:00
*/
API_EXPORT void API_CALL mk_ini_dump_file(mk_ini ini, const char *file);
// /////////////////////////////////////////统计///////////////////////////////////////////// [AUTO-TRANSLATED:964becb9]
// /////////////////////////////////////////统计/////////////////////////////////////////////
typedef void(API_CALL *on_mk_get_statistic_cb)(void *user_data, mk_ini ini);
/**
*
* @param ini
* Get memory data statistics
* @param ini Store statistical results
* [AUTO-TRANSLATED:48d8035c]
*/
API_EXPORT void API_CALL mk_get_statistic(on_mk_get_statistic_cb cb, void *user_data, on_user_data_free free_cb);
2023-02-11 11:39:26 +08:00
// /////////////////////////////////////////日志///////////////////////////////////////////// [AUTO-TRANSLATED:b1bd4de8]
// /////////////////////////////////////////日志/////////////////////////////////////////////
/**
*
* @param level ,0~4
* @param file __FILE__
* @param function __FUNCTION__
* @param line __LINE__
* @param fmt printf类型的格式控制字符串
* @param ...
* Print log
* @param level Log level, support 0~4
* @param file __FILE__
* @param function __FUNCTION__
* @param line __LINE__
* @param fmt printf type format control string
* @param ... Variable length parameters
* [AUTO-TRANSLATED:f19956e7]
*/
API_EXPORT void API_CALL mk_log_printf(int level, const char *file, const char *function, int line, const char *fmt, ...);
// 以下宏可以替换printf使用 [AUTO-TRANSLATED:73b59437]
// The following macros can replace printf
2021-12-30 15:28:02 +08:00
#define log_printf(lev, ...) mk_log_printf(lev, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define log_trace(...) log_printf(0, ##__VA_ARGS__)
2023-02-11 11:39:26 +08:00
#define log_debug(...) log_printf(1, ##__VA_ARGS__)
#define log_info(...) log_printf(2, ##__VA_ARGS__)
#define log_warn(...) log_printf(3, ##__VA_ARGS__)
2021-12-30 15:28:02 +08:00
#define log_error(...) log_printf(4, ##__VA_ARGS__)
#ifdef __cplusplus
}
#endif
#endif //MK_UTIL_H