From fbbe46d272a515b8e72be8f912cf49b56d300cf7 Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 7 Mar 2015 22:25:43 +0800 Subject: [PATCH] refine the config, support directly parse file. --- trunk/configure | 13 +++-- trunk/modules/readme.txt | 1 + trunk/src/app/srs_app_config.hpp | 2 +- trunk/src/app/srs_app_server.cpp | 93 ++++++++++++++++-------------- trunk/src/app/srs_app_server.hpp | 1 + trunk/src/main/srs_main_server.cpp | 4 ++ 6 files changed, 66 insertions(+), 48 deletions(-) diff --git a/trunk/configure b/trunk/configure index 124662a51..8ca5d357d 100755 --- a/trunk/configure +++ b/trunk/configure @@ -51,9 +51,9 @@ if [ $SRS_UTEST = YES ]; then SrsUtestMakeEntry="(cd ${SRS_OBJS_DIR}/utest; \$(M ##################################################################################### # finger out modules to install. # where srs module is a dir which contains a config file. -SRS_MODULES="" +SRS_MODULES=() __mfiles=`find modules -name "config"` && for __mfile in $__mfiles; do - SRS_MODULES="$SRS_MODULES `dirname $__mfile`" + SRS_MODULES+="`dirname $__mfile`" done # variables for makefile for all modules. @@ -177,6 +177,11 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then "srs_app_kbps" "srs_app_heartbeat" "srs_app_empty" "srs_app_http_client" "srs_app_recv_thread" "srs_app_security" "srs_app_statistic" "srs_app_mpegts_udp" "srs_app_rtsp" "srs_app_listener") + # add each modules for app + for SRS_MODULE in $SRS_MODULES; do + . $SRS_MODULE/config + MODULE_FILES+=($SRS_MODULE_APP) + done APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh APP_OBJS="${MODULE_OBJS[@]}" fi @@ -198,7 +203,7 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then # add each modules for main for SRS_MODULE in $SRS_MODULES; do . $SRS_MODULE/config - MODULE_FILES="${MODULE_FILES[@]} $SRS_MODULE_MAIN" + MODULE_FILES+=($SRS_MODULE_MAIN) done MAIN_INCS="src/main"; MODULE_DIR=${MAIN_INCS} . auto/modules.sh MAIN_OBJS="${MODULE_OBJS[@]}" @@ -215,7 +220,7 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then # add each modules for main for SRS_MODULE in $SRS_MODULES; do . $SRS_MODULE/config - MAIN_ENTRANCES="${MAIN_ENTRANCES[@]} $SRS_MODULE_MAIN" + MAIN_ENTRANCES+=($SRS_MODULE_MAIN) done # # all depends libraries diff --git a/trunk/modules/readme.txt b/trunk/modules/readme.txt index ece687b03..18be774ed 100644 --- a/trunk/modules/readme.txt +++ b/trunk/modules/readme.txt @@ -6,5 +6,6 @@ SRS模块规则: 模块中需要定义变量,例如: 1. SRS_MODULE_NAME:模块名称,用来做Makefile的phony以及执行binary文件名。 2. SRS_MODULE_MAIN:模块的main函数所在的cpp文件,在src/main目录。 +3. SRS_MODULE_APP:模块在src/app目录的源文件列表。 winlin, 2015.3 diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index e79f333ed..9e748b563 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -351,11 +351,11 @@ private: * print help and exit. */ virtual void print_help(char** argv); +public: /** * parse the config file, which is specified by cli. */ virtual int parse_file(const char* filename); -public: /** * check the parsed config. */ diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index c04bcf340..84cbfca75 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -487,49 +487,6 @@ int SrsServer::initialize() return ret; } #endif - -#ifdef SRS_AUTO_HTTP_API - srs_assert(http_api_mux); - if ((ret = http_api_mux->handle("/", new SrsGoApiRoot())) != ERROR_SUCCESS) { - return ret; - } - if ((ret = http_api_mux->handle("/api", new SrsGoApiApi())) != ERROR_SUCCESS) { - return ret; - } - if ((ret = http_api_mux->handle("/api/v1", new SrsGoApiV1())) != ERROR_SUCCESS) { - return ret; - } - if ((ret = http_api_mux->handle("/api/v1/versions", new SrsGoApiVersion())) != ERROR_SUCCESS) { - return ret; - } - if ((ret = http_api_mux->handle("/api/v1/summaries", new SrsGoApiSummaries())) != ERROR_SUCCESS) { - return ret; - } - if ((ret = http_api_mux->handle("/api/v1/rusages", new SrsGoApiRusages())) != ERROR_SUCCESS) { - return ret; - } - if ((ret = http_api_mux->handle("/api/v1/self_proc_stats", new SrsGoApiSelfProcStats())) != ERROR_SUCCESS) { - return ret; - } - if ((ret = http_api_mux->handle("/api/v1/system_proc_stats", new SrsGoApiSystemProcStats())) != ERROR_SUCCESS) { - return ret; - } - if ((ret = http_api_mux->handle("/api/v1/meminfos", new SrsGoApiMemInfos())) != ERROR_SUCCESS) { - return ret; - } - if ((ret = http_api_mux->handle("/api/v1/authors", new SrsGoApiAuthors())) != ERROR_SUCCESS) { - return ret; - } - if ((ret = http_api_mux->handle("/api/v1/requests", new SrsGoApiRequests())) != ERROR_SUCCESS) { - return ret; - } - if ((ret = http_api_mux->handle("/api/v1/vhosts", new SrsGoApiVhosts())) != ERROR_SUCCESS) { - return ret; - } - if ((ret = http_api_mux->handle("/api/v1/streams", new SrsGoApiStreams())) != ERROR_SUCCESS) { - return ret; - } -#endif #ifdef SRS_AUTO_HTTP_SERVER srs_assert(http_stream_mux); @@ -689,6 +646,56 @@ int SrsServer::register_signal() return signal_manager->start(); } +int SrsServer::http_handle() +{ + int ret = ERROR_SUCCESS; + +#ifdef SRS_AUTO_HTTP_API + srs_assert(http_api_mux); + if ((ret = http_api_mux->handle("/", new SrsGoApiRoot())) != ERROR_SUCCESS) { + return ret; + } + if ((ret = http_api_mux->handle("/api", new SrsGoApiApi())) != ERROR_SUCCESS) { + return ret; + } + if ((ret = http_api_mux->handle("/api/v1", new SrsGoApiV1())) != ERROR_SUCCESS) { + return ret; + } + if ((ret = http_api_mux->handle("/api/v1/versions", new SrsGoApiVersion())) != ERROR_SUCCESS) { + return ret; + } + if ((ret = http_api_mux->handle("/api/v1/summaries", new SrsGoApiSummaries())) != ERROR_SUCCESS) { + return ret; + } + if ((ret = http_api_mux->handle("/api/v1/rusages", new SrsGoApiRusages())) != ERROR_SUCCESS) { + return ret; + } + if ((ret = http_api_mux->handle("/api/v1/self_proc_stats", new SrsGoApiSelfProcStats())) != ERROR_SUCCESS) { + return ret; + } + if ((ret = http_api_mux->handle("/api/v1/system_proc_stats", new SrsGoApiSystemProcStats())) != ERROR_SUCCESS) { + return ret; + } + if ((ret = http_api_mux->handle("/api/v1/meminfos", new SrsGoApiMemInfos())) != ERROR_SUCCESS) { + return ret; + } + if ((ret = http_api_mux->handle("/api/v1/authors", new SrsGoApiAuthors())) != ERROR_SUCCESS) { + return ret; + } + if ((ret = http_api_mux->handle("/api/v1/requests", new SrsGoApiRequests())) != ERROR_SUCCESS) { + return ret; + } + if ((ret = http_api_mux->handle("/api/v1/vhosts", new SrsGoApiVhosts())) != ERROR_SUCCESS) { + return ret; + } + if ((ret = http_api_mux->handle("/api/v1/streams", new SrsGoApiStreams())) != ERROR_SUCCESS) { + return ret; + } +#endif + + return ret; +} + int SrsServer::ingest() { int ret = ERROR_SUCCESS; diff --git a/trunk/src/app/srs_app_server.hpp b/trunk/src/app/srs_app_server.hpp index 50ac3c78d..cf8e3dea6 100644 --- a/trunk/src/app/srs_app_server.hpp +++ b/trunk/src/app/srs_app_server.hpp @@ -236,6 +236,7 @@ public: virtual int initialize_st(); virtual int listen(); virtual int register_signal(); + virtual int http_handle(); virtual int ingest(); virtual int cycle(); // server utility diff --git a/trunk/src/main/srs_main_server.cpp b/trunk/src/main/srs_main_server.cpp index 783c9a7b9..c82a8edbe 100644 --- a/trunk/src/main/srs_main_server.cpp +++ b/trunk/src/main/srs_main_server.cpp @@ -336,6 +336,10 @@ int run_master() return ret; } + if ((ret = _srs_server->http_handle()) != ERROR_SUCCESS) { + return ret; + } + if ((ret = _srs_server->ingest()) != ERROR_SUCCESS) { return ret; }