From 0b8c4e75e17b9e4b1f0814bf0ab5330f3bb46b06 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Fri, 20 Dec 2019 11:04:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0mk=5Fenv=5Finit1=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/include/common.h | 18 ++++++++++++++++++ api/source/common.cpp | 35 ++++++++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/api/include/common.h b/api/include/common.h index 39198d55..972188c2 100755 --- a/api/include/common.h +++ b/api/include/common.h @@ -71,6 +71,24 @@ typedef struct { */ API_EXPORT void API_CALL mk_env_init(const mk_config *cfg); +/** + * 基础类型参数版本的mk_env_init,为了方便其他语言调用 + */ +API_EXPORT void API_CALL mk_env_init1( // 线程数 + int thread_num, + // 日志级别,支持0~4 + int log_level, + // 配置文件是内容还是路径 + int ini_is_path, + // 配置文件内容或路径,可以为NULL + const char *ini, + // ssl证书是内容还是路径 + int ssl_is_path, + // ssl证书内容或路径,可以为NULL + const char *ssl, + // 证书密码,可以为NULL + const char *ssl_pwd); + /** * 设置配置项 * @param key 配置项名 diff --git a/api/source/common.cpp b/api/source/common.cpp index 27cb2a80..ef89390d 100755 --- a/api/source/common.cpp +++ b/api/source/common.cpp @@ -53,25 +53,42 @@ static TcpServer::Ptr tcpRtpServer(new TcpServer()); //////////////////////////environment init/////////////////////////// API_EXPORT void API_CALL mk_env_init(const mk_config *cfg) { assert(cfg); + mk_env_init1(cfg->thread_num, + cfg->log_level, + cfg->ini_is_path, + cfg->ini, + cfg->ssl_is_path, + cfg->ssl, + cfg->ssl_pwd); +} + +API_EXPORT void API_CALL mk_env_init1( int thread_num, + int log_level, + int ini_is_path, + const char *ini, + int ssl_is_path, + const char *ssl, + const char *ssl_pwd) { + static onceToken token([&]() { - Logger::Instance().add(std::make_shared("console", (LogLevel) cfg->log_level)); + Logger::Instance().add(std::make_shared("console", (LogLevel) log_level)); Logger::Instance().setWriter(std::make_shared()); - EventPollerPool::setPoolSize(cfg->thread_num); - WorkThreadPool::setPoolSize(cfg->thread_num); + EventPollerPool::setPoolSize(thread_num); + WorkThreadPool::setPoolSize(thread_num); - if (cfg->ini) { + if (ini && ini[0]) { //设置配置文件 - if (cfg->ini_is_path) { - mINI::Instance().parseFile(cfg->ini); + if (ini_is_path) { + mINI::Instance().parseFile(ini); } else { - mINI::Instance().parse(cfg->ini); + mINI::Instance().parse(ini); } } - if (cfg->ssl) { + if (ssl && ssl[0]) { //设置ssl证书 - SSL_Initor::Instance().loadCertificate(cfg->ssl, true, cfg->ssl_pwd ? cfg->ssl_pwd : "", cfg->ssl_is_path); + SSL_Initor::Instance().loadCertificate(ssl, true, ssl_pwd ? ssl_pwd : "", ssl_is_path); } }); }