正在显示
2 个修改的文件
包含
82 行增加
和
1 行删除
| @@ -1019,6 +1019,7 @@ int SrsConfig::parse_options(int argc, char** argv) | @@ -1019,6 +1019,7 @@ int SrsConfig::parse_options(int argc, char** argv) | ||
| 1019 | { | 1019 | { |
| 1020 | int ret = ERROR_SUCCESS; | 1020 | int ret = ERROR_SUCCESS; |
| 1021 | 1021 | ||
| 1022 | + // argv | ||
| 1022 | for (int i = 0; i < argc; i++) { | 1023 | for (int i = 0; i < argc; i++) { |
| 1023 | _argv.append(argv[i]); | 1024 | _argv.append(argv[i]); |
| 1024 | 1025 | ||
| @@ -1027,10 +1028,12 @@ int SrsConfig::parse_options(int argc, char** argv) | @@ -1027,10 +1028,12 @@ int SrsConfig::parse_options(int argc, char** argv) | ||
| 1027 | } | 1028 | } |
| 1028 | } | 1029 | } |
| 1029 | 1030 | ||
| 1031 | + // cwd | ||
| 1030 | char cwd[256]; | 1032 | char cwd[256]; |
| 1031 | getcwd(cwd, sizeof(cwd)); | 1033 | getcwd(cwd, sizeof(cwd)); |
| 1032 | _cwd = cwd; | 1034 | _cwd = cwd; |
| 1033 | 1035 | ||
| 1036 | + // config | ||
| 1034 | show_help = true; | 1037 | show_help = true; |
| 1035 | for (int i = 1; i < argc; i++) { | 1038 | for (int i = 1; i < argc; i++) { |
| 1036 | if ((ret = parse_argv(i, argv)) != ERROR_SUCCESS) { | 1039 | if ((ret = parse_argv(i, argv)) != ERROR_SUCCESS) { |
| @@ -218,35 +218,106 @@ private: | @@ -218,35 +218,106 @@ private: | ||
| 218 | */ | 218 | */ |
| 219 | class SrsConfig | 219 | class SrsConfig |
| 220 | { | 220 | { |
| 221 | +// user command | ||
| 221 | private: | 222 | private: |
| 223 | + /** | ||
| 224 | + * whether show help and exit. | ||
| 225 | + */ | ||
| 222 | bool show_help; | 226 | bool show_help; |
| 227 | + /** | ||
| 228 | + * whether test config file and exit. | ||
| 229 | + */ | ||
| 223 | bool test_conf; | 230 | bool test_conf; |
| 231 | + /** | ||
| 232 | + * whether show SRS version and exit. | ||
| 233 | + */ | ||
| 224 | bool show_version; | 234 | bool show_version; |
| 225 | - std::string config_file; | 235 | +// global env variables. |
| 236 | +private: | ||
| 237 | + /** | ||
| 238 | + * the user parameters, the argc and argv. | ||
| 239 | + * the argv is " ".join(argv), where argv is from main(argc, argv). | ||
| 240 | + */ | ||
| 226 | std::string _argv; | 241 | std::string _argv; |
| 242 | + /** | ||
| 243 | + * current working directory. | ||
| 244 | + */ | ||
| 227 | std::string _cwd; | 245 | std::string _cwd; |
| 246 | +// config section | ||
| 247 | +private: | ||
| 248 | + /** | ||
| 249 | + * the last parsed config file. | ||
| 250 | + * if reload, reload the config file. | ||
| 251 | + */ | ||
| 252 | + std::string config_file; | ||
| 253 | + /** | ||
| 254 | + * the directive root. | ||
| 255 | + */ | ||
| 228 | SrsConfDirective* root; | 256 | SrsConfDirective* root; |
| 257 | +// reload section | ||
| 258 | +private: | ||
| 259 | + /** | ||
| 260 | + * the reload subscribers, when reload, callback all handlers. | ||
| 261 | + */ | ||
| 229 | std::vector<ISrsReloadHandler*> subscribes; | 262 | std::vector<ISrsReloadHandler*> subscribes; |
| 230 | public: | 263 | public: |
| 231 | SrsConfig(); | 264 | SrsConfig(); |
| 232 | virtual ~SrsConfig(); | 265 | virtual ~SrsConfig(); |
| 233 | // reload | 266 | // reload |
| 234 | public: | 267 | public: |
| 268 | + /** | ||
| 269 | + * for reload handler to register itself, | ||
| 270 | + * when config service do the reload, callback the handler. | ||
| 271 | + */ | ||
| 235 | virtual void subscribe(ISrsReloadHandler* handler); | 272 | virtual void subscribe(ISrsReloadHandler* handler); |
| 273 | + /** | ||
| 274 | + * for reload handler to unregister itself. | ||
| 275 | + */ | ||
| 236 | virtual void unsubscribe(ISrsReloadHandler* handler); | 276 | virtual void unsubscribe(ISrsReloadHandler* handler); |
| 277 | + /** | ||
| 278 | + * reload the config file. | ||
| 279 | + * @remark, user can test the config before reload it. | ||
| 280 | + */ | ||
| 237 | virtual int reload(); | 281 | virtual int reload(); |
| 238 | private: | 282 | private: |
| 283 | + /** | ||
| 284 | + * reload the http_api section of config. | ||
| 285 | + */ | ||
| 239 | virtual int reload_http_api(SrsConfDirective* old_root); | 286 | virtual int reload_http_api(SrsConfDirective* old_root); |
| 287 | + /** | ||
| 288 | + * reload the http_stream section of config. | ||
| 289 | + */ | ||
| 240 | virtual int reload_http_stream(SrsConfDirective* old_root); | 290 | virtual int reload_http_stream(SrsConfDirective* old_root); |
| 291 | + /** | ||
| 292 | + * reload the vhost section of config. | ||
| 293 | + */ | ||
| 241 | virtual int reload_vhost(SrsConfDirective* old_root); | 294 | virtual int reload_vhost(SrsConfDirective* old_root); |
| 295 | + /** | ||
| 296 | + * reload the transcode section of vhost of config. | ||
| 297 | + */ | ||
| 242 | virtual int reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost); | 298 | virtual int reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost); |
| 299 | + /** | ||
| 300 | + * reload the ingest section of vhost of config. | ||
| 301 | + */ | ||
| 243 | virtual int reload_ingest(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost); | 302 | virtual int reload_ingest(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost); |
| 244 | // parse options and file | 303 | // parse options and file |
| 245 | public: | 304 | public: |
| 305 | + /** | ||
| 306 | + * parse the cli, the main(argc,argv) function. | ||
| 307 | + */ | ||
| 246 | virtual int parse_options(int argc, char** argv); | 308 | virtual int parse_options(int argc, char** argv); |
| 247 | private: | 309 | private: |
| 310 | + /** | ||
| 311 | + * parse each argv. | ||
| 312 | + */ | ||
| 248 | virtual int parse_argv(int& i, char** argv); | 313 | virtual int parse_argv(int& i, char** argv); |
| 314 | + /** | ||
| 315 | + * print help and exit. | ||
| 316 | + */ | ||
| 249 | virtual void print_help(char** argv); | 317 | virtual void print_help(char** argv); |
| 318 | + /** | ||
| 319 | + * parse the config file, which is specified by cli. | ||
| 320 | + */ | ||
| 250 | virtual int parse_file(const char* filename); | 321 | virtual int parse_file(const char* filename); |
| 251 | protected: | 322 | protected: |
| 252 | /** | 323 | /** |
| @@ -255,8 +326,15 @@ protected: | @@ -255,8 +326,15 @@ protected: | ||
| 255 | * @remark, protected for the utest to override with mock. | 326 | * @remark, protected for the utest to override with mock. |
| 256 | */ | 327 | */ |
| 257 | virtual int parse_buffer(_srs_internal::SrsConfigBuffer* buffer); | 328 | virtual int parse_buffer(_srs_internal::SrsConfigBuffer* buffer); |
| 329 | +// global env | ||
| 258 | public: | 330 | public: |
| 331 | + /** | ||
| 332 | + * get the current work directory. | ||
| 333 | + */ | ||
| 259 | virtual std::string cwd(); | 334 | virtual std::string cwd(); |
| 335 | + /** | ||
| 336 | + * get the cli, the main(argc,argv), program start command. | ||
| 337 | + */ | ||
| 260 | virtual std::string argv(); | 338 | virtual std::string argv(); |
| 261 | // global section | 339 | // global section |
| 262 | public: | 340 | public: |
-
请 注册 或 登录 后发表评论