ZLMediaKit/src/Shell/ShellCMD.h

65 lines
2.7 KiB
C++
Raw Normal View History

2020-04-04 20:30:09 +08:00
/*
2023-12-09 16:23:51 +08:00
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
2020-04-04 20:30:09 +08:00
*
2023-12-09 16:23:51 +08:00
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
2020-04-04 20:30:09 +08:00
*
2023-12-09 16:23:51 +08:00
* Use of this source code is governed by MIT-like license that can be found in the
2020-04-04 20:30:09 +08:00
* LICENSE file in the root of the source tree. All contributing project authors
* may be found in the AUTHORS file in the root of the source tree.
*/
2017-12-01 11:42:49 +08:00
2019-05-31 09:06:30 +08:00
#ifndef SRC_SHELL_SHELLCMD_H_
#define SRC_SHELL_SHELLCMD_H_
2017-12-01 11:42:49 +08:00
#include "Util/CMD.h"
#include "Common/MediaSource.h"
2017-12-01 11:42:49 +08:00
2018-10-24 17:17:55 +08:00
namespace mediakit {
2017-12-01 11:42:49 +08:00
class CMD_media : public toolkit::CMD {
2017-12-01 11:42:49 +08:00
public:
CMD_media() {
_parser.reset(new toolkit::OptionParser([](const std::shared_ptr<std::ostream> &stream, toolkit::mINI &ini) {
MediaSource::for_each_media([&](const MediaSource::Ptr &media) {
if (ini.find("list") != ini.end()) {
//列出源
(*stream) << "\t" << media->getUrl() << "\r\n";
return;
}
toolkit::EventPollerPool::Instance().getPoller()->async([ini, media, stream]() {
if (ini.find("kick") != ini.end()) {
2019-05-28 10:02:12 +08:00
//踢出源
do {
if (!media) {
2019-05-28 10:02:12 +08:00
break;
}
if (!media->close(true)) {
2019-05-28 10:02:12 +08:00
break;
}
(*stream) << "\t踢出成功:" << media->getUrl() << "\r\n";
2019-05-28 10:02:12 +08:00
return;
} while (0);
(*stream) << "\t踢出失败:" << media->getUrl() << "\r\n";
2019-05-28 10:02:12 +08:00
}
}, false);
2019-05-28 10:02:12 +08:00
2021-06-30 21:06:29 +08:00
}, ini["schema"], ini["vhost"], ini["app"], ini["stream"]);
}));
(*_parser) << toolkit::Option('k', "kick", toolkit::Option::ArgNone, nullptr, false, "踢出媒体源", nullptr);
(*_parser) << toolkit::Option('l', "list", toolkit::Option::ArgNone, nullptr, false, "列出媒体源", nullptr);
(*_parser) << toolkit::Option('S', "schema", toolkit::Option::ArgRequired, nullptr, false, "协议筛选", nullptr);
(*_parser) << toolkit::Option('v', "vhost", toolkit::Option::ArgRequired, nullptr, false, "虚拟主机筛选", nullptr);
(*_parser) << toolkit::Option('a', "app", toolkit::Option::ArgRequired, nullptr, false, "应用名筛选", nullptr);
(*_parser) << toolkit::Option('s', "stream", toolkit::Option::ArgRequired, nullptr, false, "流id筛选", nullptr);
2017-12-01 11:42:49 +08:00
}
2017-12-01 11:42:49 +08:00
const char *description() const override {
return "媒体源相关操作.";
2017-12-01 11:42:49 +08:00
}
};
2019-05-31 09:06:30 +08:00
} /* namespace mediakit */
2019-05-27 18:39:43 +08:00
2019-05-31 09:06:30 +08:00
#endif //SRC_SHELL_SHELLCMD_H_