winlin

refine the config, support directly parse file.

@@ -51,9 +51,9 @@ if [ $SRS_UTEST = YES ]; then SrsUtestMakeEntry="(cd ${SRS_OBJS_DIR}/utest; \$(M @@ -51,9 +51,9 @@ if [ $SRS_UTEST = YES ]; then SrsUtestMakeEntry="(cd ${SRS_OBJS_DIR}/utest; \$(M
51 ##################################################################################### 51 #####################################################################################
52 # finger out modules to install. 52 # finger out modules to install.
53 # where srs module is a dir which contains a config file. 53 # where srs module is a dir which contains a config file.
54 -SRS_MODULES="" 54 +SRS_MODULES=()
55 __mfiles=`find modules -name "config"` && for __mfile in $__mfiles; do 55 __mfiles=`find modules -name "config"` && for __mfile in $__mfiles; do
56 - SRS_MODULES="$SRS_MODULES `dirname $__mfile`" 56 + SRS_MODULES+="`dirname $__mfile`"
57 done 57 done
58 58
59 # variables for makefile for all modules. 59 # variables for makefile for all modules.
@@ -177,6 +177,11 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then @@ -177,6 +177,11 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
177 "srs_app_kbps" "srs_app_heartbeat" "srs_app_empty" "srs_app_http_client" 177 "srs_app_kbps" "srs_app_heartbeat" "srs_app_empty" "srs_app_http_client"
178 "srs_app_recv_thread" "srs_app_security" "srs_app_statistic" 178 "srs_app_recv_thread" "srs_app_security" "srs_app_statistic"
179 "srs_app_mpegts_udp" "srs_app_rtsp" "srs_app_listener") 179 "srs_app_mpegts_udp" "srs_app_rtsp" "srs_app_listener")
  180 + # add each modules for app
  181 + for SRS_MODULE in $SRS_MODULES; do
  182 + . $SRS_MODULE/config
  183 + MODULE_FILES+=($SRS_MODULE_APP)
  184 + done
180 APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh 185 APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh
181 APP_OBJS="${MODULE_OBJS[@]}" 186 APP_OBJS="${MODULE_OBJS[@]}"
182 fi 187 fi
@@ -198,7 +203,7 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then @@ -198,7 +203,7 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
198 # add each modules for main 203 # add each modules for main
199 for SRS_MODULE in $SRS_MODULES; do 204 for SRS_MODULE in $SRS_MODULES; do
200 . $SRS_MODULE/config 205 . $SRS_MODULE/config
201 - MODULE_FILES="${MODULE_FILES[@]} $SRS_MODULE_MAIN" 206 + MODULE_FILES+=($SRS_MODULE_MAIN)
202 done 207 done
203 MAIN_INCS="src/main"; MODULE_DIR=${MAIN_INCS} . auto/modules.sh 208 MAIN_INCS="src/main"; MODULE_DIR=${MAIN_INCS} . auto/modules.sh
204 MAIN_OBJS="${MODULE_OBJS[@]}" 209 MAIN_OBJS="${MODULE_OBJS[@]}"
@@ -215,7 +220,7 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then @@ -215,7 +220,7 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
215 # add each modules for main 220 # add each modules for main
216 for SRS_MODULE in $SRS_MODULES; do 221 for SRS_MODULE in $SRS_MODULES; do
217 . $SRS_MODULE/config 222 . $SRS_MODULE/config
218 - MAIN_ENTRANCES="${MAIN_ENTRANCES[@]} $SRS_MODULE_MAIN" 223 + MAIN_ENTRANCES+=($SRS_MODULE_MAIN)
219 done 224 done
220 # 225 #
221 # all depends libraries 226 # all depends libraries
@@ -6,5 +6,6 @@ SRS模块规则: @@ -6,5 +6,6 @@ SRS模块规则:
6 模块中需要定义变量,例如: 6 模块中需要定义变量,例如:
7 1. SRS_MODULE_NAME:模块名称,用来做Makefile的phony以及执行binary文件名。 7 1. SRS_MODULE_NAME:模块名称,用来做Makefile的phony以及执行binary文件名。
8 2. SRS_MODULE_MAIN:模块的main函数所在的cpp文件,在src/main目录。 8 2. SRS_MODULE_MAIN:模块的main函数所在的cpp文件,在src/main目录。
  9 +3. SRS_MODULE_APP:模块在src/app目录的源文件列表。
9 10
10 winlin, 2015.3 11 winlin, 2015.3
@@ -351,11 +351,11 @@ private: @@ -351,11 +351,11 @@ private:
351 * print help and exit. 351 * print help and exit.
352 */ 352 */
353 virtual void print_help(char** argv); 353 virtual void print_help(char** argv);
  354 +public:
354 /** 355 /**
355 * parse the config file, which is specified by cli. 356 * parse the config file, which is specified by cli.
356 */ 357 */
357 virtual int parse_file(const char* filename); 358 virtual int parse_file(const char* filename);
358 -public:  
359 /** 359 /**
360 * check the parsed config. 360 * check the parsed config.
361 */ 361 */
@@ -487,49 +487,6 @@ int SrsServer::initialize() @@ -487,49 +487,6 @@ int SrsServer::initialize()
487 return ret; 487 return ret;
488 } 488 }
489 #endif 489 #endif
490 -  
491 -#ifdef SRS_AUTO_HTTP_API  
492 - srs_assert(http_api_mux);  
493 - if ((ret = http_api_mux->handle("/", new SrsGoApiRoot())) != ERROR_SUCCESS) {  
494 - return ret;  
495 - }  
496 - if ((ret = http_api_mux->handle("/api", new SrsGoApiApi())) != ERROR_SUCCESS) {  
497 - return ret;  
498 - }  
499 - if ((ret = http_api_mux->handle("/api/v1", new SrsGoApiV1())) != ERROR_SUCCESS) {  
500 - return ret;  
501 - }  
502 - if ((ret = http_api_mux->handle("/api/v1/versions", new SrsGoApiVersion())) != ERROR_SUCCESS) {  
503 - return ret;  
504 - }  
505 - if ((ret = http_api_mux->handle("/api/v1/summaries", new SrsGoApiSummaries())) != ERROR_SUCCESS) {  
506 - return ret;  
507 - }  
508 - if ((ret = http_api_mux->handle("/api/v1/rusages", new SrsGoApiRusages())) != ERROR_SUCCESS) {  
509 - return ret;  
510 - }  
511 - if ((ret = http_api_mux->handle("/api/v1/self_proc_stats", new SrsGoApiSelfProcStats())) != ERROR_SUCCESS) {  
512 - return ret;  
513 - }  
514 - if ((ret = http_api_mux->handle("/api/v1/system_proc_stats", new SrsGoApiSystemProcStats())) != ERROR_SUCCESS) {  
515 - return ret;  
516 - }  
517 - if ((ret = http_api_mux->handle("/api/v1/meminfos", new SrsGoApiMemInfos())) != ERROR_SUCCESS) {  
518 - return ret;  
519 - }  
520 - if ((ret = http_api_mux->handle("/api/v1/authors", new SrsGoApiAuthors())) != ERROR_SUCCESS) {  
521 - return ret;  
522 - }  
523 - if ((ret = http_api_mux->handle("/api/v1/requests", new SrsGoApiRequests())) != ERROR_SUCCESS) {  
524 - return ret;  
525 - }  
526 - if ((ret = http_api_mux->handle("/api/v1/vhosts", new SrsGoApiVhosts())) != ERROR_SUCCESS) {  
527 - return ret;  
528 - }  
529 - if ((ret = http_api_mux->handle("/api/v1/streams", new SrsGoApiStreams())) != ERROR_SUCCESS) {  
530 - return ret;  
531 - }  
532 -#endif  
533 490
534 #ifdef SRS_AUTO_HTTP_SERVER 491 #ifdef SRS_AUTO_HTTP_SERVER
535 srs_assert(http_stream_mux); 492 srs_assert(http_stream_mux);
@@ -689,6 +646,56 @@ int SrsServer::register_signal() @@ -689,6 +646,56 @@ int SrsServer::register_signal()
689 return signal_manager->start(); 646 return signal_manager->start();
690 } 647 }
691 648
  649 +int SrsServer::http_handle()
  650 +{
  651 + int ret = ERROR_SUCCESS;
  652 +
  653 +#ifdef SRS_AUTO_HTTP_API
  654 + srs_assert(http_api_mux);
  655 + if ((ret = http_api_mux->handle("/", new SrsGoApiRoot())) != ERROR_SUCCESS) {
  656 + return ret;
  657 + }
  658 + if ((ret = http_api_mux->handle("/api", new SrsGoApiApi())) != ERROR_SUCCESS) {
  659 + return ret;
  660 + }
  661 + if ((ret = http_api_mux->handle("/api/v1", new SrsGoApiV1())) != ERROR_SUCCESS) {
  662 + return ret;
  663 + }
  664 + if ((ret = http_api_mux->handle("/api/v1/versions", new SrsGoApiVersion())) != ERROR_SUCCESS) {
  665 + return ret;
  666 + }
  667 + if ((ret = http_api_mux->handle("/api/v1/summaries", new SrsGoApiSummaries())) != ERROR_SUCCESS) {
  668 + return ret;
  669 + }
  670 + if ((ret = http_api_mux->handle("/api/v1/rusages", new SrsGoApiRusages())) != ERROR_SUCCESS) {
  671 + return ret;
  672 + }
  673 + if ((ret = http_api_mux->handle("/api/v1/self_proc_stats", new SrsGoApiSelfProcStats())) != ERROR_SUCCESS) {
  674 + return ret;
  675 + }
  676 + if ((ret = http_api_mux->handle("/api/v1/system_proc_stats", new SrsGoApiSystemProcStats())) != ERROR_SUCCESS) {
  677 + return ret;
  678 + }
  679 + if ((ret = http_api_mux->handle("/api/v1/meminfos", new SrsGoApiMemInfos())) != ERROR_SUCCESS) {
  680 + return ret;
  681 + }
  682 + if ((ret = http_api_mux->handle("/api/v1/authors", new SrsGoApiAuthors())) != ERROR_SUCCESS) {
  683 + return ret;
  684 + }
  685 + if ((ret = http_api_mux->handle("/api/v1/requests", new SrsGoApiRequests())) != ERROR_SUCCESS) {
  686 + return ret;
  687 + }
  688 + if ((ret = http_api_mux->handle("/api/v1/vhosts", new SrsGoApiVhosts())) != ERROR_SUCCESS) {
  689 + return ret;
  690 + }
  691 + if ((ret = http_api_mux->handle("/api/v1/streams", new SrsGoApiStreams())) != ERROR_SUCCESS) {
  692 + return ret;
  693 + }
  694 +#endif
  695 +
  696 + return ret;
  697 +}
  698 +
692 int SrsServer::ingest() 699 int SrsServer::ingest()
693 { 700 {
694 int ret = ERROR_SUCCESS; 701 int ret = ERROR_SUCCESS;
@@ -236,6 +236,7 @@ public: @@ -236,6 +236,7 @@ public:
236 virtual int initialize_st(); 236 virtual int initialize_st();
237 virtual int listen(); 237 virtual int listen();
238 virtual int register_signal(); 238 virtual int register_signal();
  239 + virtual int http_handle();
239 virtual int ingest(); 240 virtual int ingest();
240 virtual int cycle(); 241 virtual int cycle();
241 // server utility 242 // server utility
@@ -336,6 +336,10 @@ int run_master() @@ -336,6 +336,10 @@ int run_master()
336 return ret; 336 return ret;
337 } 337 }
338 338
  339 + if ((ret = _srs_server->http_handle()) != ERROR_SUCCESS) {
  340 + return ret;
  341 + }
  342 +
339 if ((ret = _srs_server->ingest()) != ERROR_SUCCESS) { 343 if ((ret = _srs_server->ingest()) != ERROR_SUCCESS) {
340 return ret; 344 return ret;
341 } 345 }