From 6c5d8b485150a9e244de23eb1b3e2c2dc06e08fa Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 10 Apr 2014 14:05:01 +0800 Subject: [PATCH] refine reload config --- README.md | 2 +- trunk/src/app/srs_app_config.cpp | 112 ++++++++++++++-------------- trunk/src/app/srs_app_config.hpp | 7 +- trunk/src/kernel/srs_kernel_log.hpp | 4 +- 4 files changed, 63 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index de3abbbf0..5e8af7ee2 100755 --- a/README.md +++ b/README.md @@ -221,7 +221,7 @@ usr sys idl wai hiq siq| read writ| recv send| in out | int csw * nginx v1.5.0: 139524 lines
## History -* v1.0, 2014-04-10, support reload ingesters(added/removed/updated). change to 0.9.57. +* v1.0, 2014-04-10, support reload ingesters(add/remov/update). change to 0.9.57. * v1.0, 2014-04-07, [1.0 mainline(0.9.55)](https://github.com/winlinvip/simple-rtmp-server/releases/tag/1.0.mainline) released. 30000 lines. * v1.0, 2014-04-07, support [ingest](https://github.com/winlinvip/simple-rtmp-server/wiki/SampleIngest) file/stream/device. * v1.0, 2014-04-05, support [http api](https://github.com/winlinvip/simple-rtmp-server/wiki/HTTPApi) and [http server](https://github.com/winlinvip/simple-rtmp-server/wiki/HTTPServer). diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 04f28c0b5..72e873ec2 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -447,6 +447,30 @@ SrsConfig::~SrsConfig() srs_freep(root); } +void SrsConfig::subscribe(ISrsReloadHandler* handler) +{ + std::vector::iterator it; + + it = std::find(subscribes.begin(), subscribes.end(), handler); + if (it != subscribes.end()) { + return; + } + + subscribes.push_back(handler); +} + +void SrsConfig::unsubscribe(ISrsReloadHandler* handler) +{ + std::vector::iterator it; + + it = std::find(subscribes.begin(), subscribes.end(), handler); + if (it == subscribes.end()) { + return; + } + + subscribes.erase(it); +} + int SrsConfig::reload() { int ret = ERROR_SUCCESS; @@ -630,62 +654,6 @@ int SrsConfig::reload() return ret; } -void SrsConfig::subscribe(ISrsReloadHandler* handler) -{ - std::vector::iterator it; - - it = std::find(subscribes.begin(), subscribes.end(), handler); - if (it != subscribes.end()) { - return; - } - - subscribes.push_back(handler); -} - -void SrsConfig::unsubscribe(ISrsReloadHandler* handler) -{ - std::vector::iterator it; - - it = std::find(subscribes.begin(), subscribes.end(), handler); - if (it == subscribes.end()) { - return; - } - - subscribes.erase(it); -} - -// see: ngx_get_options -int SrsConfig::parse_options(int argc, char** argv) -{ - int ret = ERROR_SUCCESS; - - for (int i = 1; i < argc; i++) { - if ((ret = parse_argv(i, argv)) != ERROR_SUCCESS) { - return ret; - } - } - - if (show_help) { - print_help(argv); - } - - if (show_version) { - fprintf(stderr, "%s\n", RTMP_SIG_SRS_VERSION); - } - - if (show_help || show_version) { - exit(0); - } - - if (config_file.empty()) { - ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("config file not specified, see help: %s -h, ret=%d", argv[0], ret); - return ret; - } - - return parse_file(config_file.c_str()); -} - int SrsConfig::reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost) { int ret = ERROR_SUCCESS; @@ -870,6 +838,38 @@ int SrsConfig::reload_ingest(SrsConfDirective* new_vhost, SrsConfDirective* old_ return ret; } +// see: ngx_get_options +int SrsConfig::parse_options(int argc, char** argv) +{ + int ret = ERROR_SUCCESS; + + for (int i = 1; i < argc; i++) { + if ((ret = parse_argv(i, argv)) != ERROR_SUCCESS) { + return ret; + } + } + + if (show_help) { + print_help(argv); + } + + if (show_version) { + fprintf(stderr, "%s\n", RTMP_SIG_SRS_VERSION); + } + + if (show_help || show_version) { + exit(0); + } + + if (config_file.empty()) { + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("config file not specified, see help: %s -h, ret=%d", argv[0], ret); + return ret; + } + + return parse_file(config_file.c_str()); +} + int SrsConfig::parse_file(const char* filename) { int ret = ERROR_SUCCESS; diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 98524101b..d8148440f 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -119,14 +119,15 @@ public: SrsConfig(); virtual ~SrsConfig(); public: - virtual int reload(); virtual void subscribe(ISrsReloadHandler* handler); virtual void unsubscribe(ISrsReloadHandler* handler); + virtual int reload(); +private: + virtual int reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost); + virtual int reload_ingest(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost); public: virtual int parse_options(int argc, char** argv); private: - virtual int reload_ingest(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost); - virtual int reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost); virtual int parse_file(const char* filename); virtual int parse_argv(int& i, char** argv); virtual void print_help(char** argv); diff --git a/trunk/src/kernel/srs_kernel_log.hpp b/trunk/src/kernel/srs_kernel_log.hpp index 7574c25ba..65d7cf19b 100644 --- a/trunk/src/kernel/srs_kernel_log.hpp +++ b/trunk/src/kernel/srs_kernel_log.hpp @@ -131,11 +131,11 @@ extern ISrsThreadContext* _srs_context; #define srs_error(msg, ...) _srs_log->error(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__) #endif -#if 1 +#if 0 #undef srs_verbose #define srs_verbose(msg, ...) (void)0 #endif -#if 1 +#if 0 #undef srs_info #define srs_info(msg, ...) (void)0 #endif