You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
2.0 KiB

3 years ago
3 years ago
  1. #include "main_control_service.hpp"
  2. #include "version.hpp"
  3. using namespace iflytop;
  4. using namespace core;
  5. using namespace std;
  6. void MainControlService::initialize() {
  7. GET_TO_SERVICE(m_zwebService);
  8. // 监听从webservice来的websocket消息
  9. m_zwebService->startWork([this](const json& command, json& receipt) {
  10. try {
  11. processReceiveMessage(kzwebService, command, receipt);
  12. } catch (const std::exception& e) {
  13. logger->error("process message fail {}", string(e.what()));
  14. } catch (...) {
  15. logger->error("process message fail {}", "catch unknown exception");
  16. }
  17. });
  18. };
  19. void MainControlService::processReceiveMessage(fromwhere_t fromwhere, const json& in, json& receipt) {
  20. logger->info("process receive message from {},{}", fromwhere2str(fromwhere), in.dump());
  21. if (in["command"] == "getVersion") {
  22. receipt["version"] = VERSION;
  23. }
  24. /*********************************************************************************************************************
  25. * ================================================================================================= *
  26. *********************************************************************************************************************/
  27. else if (in["command"] == "loggerSetLevel") {
  28. int loggerLevel = in["loggerLevel"];
  29. string loggerName = in["loggerName"];
  30. logger->info("loggerSetLevel {} {}", loggerName, loggerLevel);
  31. SpdLoggerFactory::Instance().createLogger(loggerName)->set_level((level::level_enum)loggerLevel);
  32. } else if (in["command"] == "loggerGetAllLoggers") {
  33. receipt["loggers"] = SpdLoggerFactory::Instance().loggerNames();
  34. }
  35. /*********************************************************************************************************************
  36. * ============================================================================================================= *
  37. *********************************************************************************************************************/
  38. }