winlin

refine reload config

@@ -221,7 +221,7 @@ usr sys idl wai hiq siq| read writ| recv send| in out | int csw @@ -221,7 +221,7 @@ usr sys idl wai hiq siq| read writ| recv send| in out | int csw
221 * nginx v1.5.0: 139524 lines <br/> 221 * nginx v1.5.0: 139524 lines <br/>
222 222
223 ## History 223 ## History
224 -* v1.0, 2014-04-10, support reload ingesters(added/removed/updated). change to 0.9.57. 224 +* v1.0, 2014-04-10, support reload ingesters(add/remov/update). change to 0.9.57.
225 * 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. 225 * 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.
226 * v1.0, 2014-04-07, support [ingest](https://github.com/winlinvip/simple-rtmp-server/wiki/SampleIngest) file/stream/device. 226 * v1.0, 2014-04-07, support [ingest](https://github.com/winlinvip/simple-rtmp-server/wiki/SampleIngest) file/stream/device.
227 * 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). 227 * 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).
@@ -447,6 +447,30 @@ SrsConfig::~SrsConfig() @@ -447,6 +447,30 @@ SrsConfig::~SrsConfig()
447 srs_freep(root); 447 srs_freep(root);
448 } 448 }
449 449
  450 +void SrsConfig::subscribe(ISrsReloadHandler* handler)
  451 +{
  452 + std::vector<ISrsReloadHandler*>::iterator it;
  453 +
  454 + it = std::find(subscribes.begin(), subscribes.end(), handler);
  455 + if (it != subscribes.end()) {
  456 + return;
  457 + }
  458 +
  459 + subscribes.push_back(handler);
  460 +}
  461 +
  462 +void SrsConfig::unsubscribe(ISrsReloadHandler* handler)
  463 +{
  464 + std::vector<ISrsReloadHandler*>::iterator it;
  465 +
  466 + it = std::find(subscribes.begin(), subscribes.end(), handler);
  467 + if (it == subscribes.end()) {
  468 + return;
  469 + }
  470 +
  471 + subscribes.erase(it);
  472 +}
  473 +
450 int SrsConfig::reload() 474 int SrsConfig::reload()
451 { 475 {
452 int ret = ERROR_SUCCESS; 476 int ret = ERROR_SUCCESS;
@@ -630,62 +654,6 @@ int SrsConfig::reload() @@ -630,62 +654,6 @@ int SrsConfig::reload()
630 return ret; 654 return ret;
631 } 655 }
632 656
633 -void SrsConfig::subscribe(ISrsReloadHandler* handler)  
634 -{  
635 - std::vector<ISrsReloadHandler*>::iterator it;  
636 -  
637 - it = std::find(subscribes.begin(), subscribes.end(), handler);  
638 - if (it != subscribes.end()) {  
639 - return;  
640 - }  
641 -  
642 - subscribes.push_back(handler);  
643 -}  
644 -  
645 -void SrsConfig::unsubscribe(ISrsReloadHandler* handler)  
646 -{  
647 - std::vector<ISrsReloadHandler*>::iterator it;  
648 -  
649 - it = std::find(subscribes.begin(), subscribes.end(), handler);  
650 - if (it == subscribes.end()) {  
651 - return;  
652 - }  
653 -  
654 - subscribes.erase(it);  
655 -}  
656 -  
657 -// see: ngx_get_options  
658 -int SrsConfig::parse_options(int argc, char** argv)  
659 -{  
660 - int ret = ERROR_SUCCESS;  
661 -  
662 - for (int i = 1; i < argc; i++) {  
663 - if ((ret = parse_argv(i, argv)) != ERROR_SUCCESS) {  
664 - return ret;  
665 - }  
666 - }  
667 -  
668 - if (show_help) {  
669 - print_help(argv);  
670 - }  
671 -  
672 - if (show_version) {  
673 - fprintf(stderr, "%s\n", RTMP_SIG_SRS_VERSION);  
674 - }  
675 -  
676 - if (show_help || show_version) {  
677 - exit(0);  
678 - }  
679 -  
680 - if (config_file.empty()) {  
681 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
682 - srs_error("config file not specified, see help: %s -h, ret=%d", argv[0], ret);  
683 - return ret;  
684 - }  
685 -  
686 - return parse_file(config_file.c_str());  
687 -}  
688 -  
689 int SrsConfig::reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost) 657 int SrsConfig::reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost)
690 { 658 {
691 int ret = ERROR_SUCCESS; 659 int ret = ERROR_SUCCESS;
@@ -870,6 +838,38 @@ int SrsConfig::reload_ingest(SrsConfDirective* new_vhost, SrsConfDirective* old_ @@ -870,6 +838,38 @@ int SrsConfig::reload_ingest(SrsConfDirective* new_vhost, SrsConfDirective* old_
870 return ret; 838 return ret;
871 } 839 }
872 840
  841 +// see: ngx_get_options
  842 +int SrsConfig::parse_options(int argc, char** argv)
  843 +{
  844 + int ret = ERROR_SUCCESS;
  845 +
  846 + for (int i = 1; i < argc; i++) {
  847 + if ((ret = parse_argv(i, argv)) != ERROR_SUCCESS) {
  848 + return ret;
  849 + }
  850 + }
  851 +
  852 + if (show_help) {
  853 + print_help(argv);
  854 + }
  855 +
  856 + if (show_version) {
  857 + fprintf(stderr, "%s\n", RTMP_SIG_SRS_VERSION);
  858 + }
  859 +
  860 + if (show_help || show_version) {
  861 + exit(0);
  862 + }
  863 +
  864 + if (config_file.empty()) {
  865 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  866 + srs_error("config file not specified, see help: %s -h, ret=%d", argv[0], ret);
  867 + return ret;
  868 + }
  869 +
  870 + return parse_file(config_file.c_str());
  871 +}
  872 +
873 int SrsConfig::parse_file(const char* filename) 873 int SrsConfig::parse_file(const char* filename)
874 { 874 {
875 int ret = ERROR_SUCCESS; 875 int ret = ERROR_SUCCESS;
@@ -119,14 +119,15 @@ public: @@ -119,14 +119,15 @@ public:
119 SrsConfig(); 119 SrsConfig();
120 virtual ~SrsConfig(); 120 virtual ~SrsConfig();
121 public: 121 public:
122 - virtual int reload();  
123 virtual void subscribe(ISrsReloadHandler* handler); 122 virtual void subscribe(ISrsReloadHandler* handler);
124 virtual void unsubscribe(ISrsReloadHandler* handler); 123 virtual void unsubscribe(ISrsReloadHandler* handler);
  124 + virtual int reload();
  125 +private:
  126 + virtual int reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost);
  127 + virtual int reload_ingest(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost);
125 public: 128 public:
126 virtual int parse_options(int argc, char** argv); 129 virtual int parse_options(int argc, char** argv);
127 private: 130 private:
128 - virtual int reload_ingest(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost);  
129 - virtual int reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost);  
130 virtual int parse_file(const char* filename); 131 virtual int parse_file(const char* filename);
131 virtual int parse_argv(int& i, char** argv); 132 virtual int parse_argv(int& i, char** argv);
132 virtual void print_help(char** argv); 133 virtual void print_help(char** argv);
@@ -131,11 +131,11 @@ extern ISrsThreadContext* _srs_context; @@ -131,11 +131,11 @@ extern ISrsThreadContext* _srs_context;
131 #define srs_error(msg, ...) _srs_log->error(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__) 131 #define srs_error(msg, ...) _srs_log->error(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
132 #endif 132 #endif
133 133
134 -#if 1 134 +#if 0
135 #undef srs_verbose 135 #undef srs_verbose
136 #define srs_verbose(msg, ...) (void)0 136 #define srs_verbose(msg, ...) (void)0
137 #endif 137 #endif
138 -#if 1 138 +#if 0
139 #undef srs_info 139 #undef srs_info
140 #define srs_info(msg, ...) (void)0 140 #define srs_info(msg, ...) (void)0
141 #endif 141 #endif