diff --git a/configs/fne-sysview.example.yml b/configs/fne-sysview.example.yml index a565a81c..350c8aa1 100644 --- a/configs/fne-sysview.example.yml +++ b/configs/fne-sysview.example.yml @@ -91,3 +91,6 @@ fne: websocket: # Port number of the WebSocket should listen on. port: 8443 + + # Flag indicating whether or not verbose debug logging is enabled. + debug: false diff --git a/src/sysview/HostWS.cpp b/src/sysview/HostWS.cpp index ce9191f5..07f4f6c1 100644 --- a/src/sysview/HostWS.cpp +++ b/src/sysview/HostWS.cpp @@ -38,7 +38,8 @@ HostWS::HostWS(const std::string& confFile) : m_conf(), m_websocketPort(8443U), m_wsServer(), - m_wsConList() + m_wsConList(), + m_debug(false) { /* stub */ } @@ -133,11 +134,14 @@ int HostWS::run() m_wsServer.set_message_handler(websocketpp::lib::bind(&HostWS::wsOnMessage, this, websocketpp::lib::placeholders::_1, websocketpp::lib::placeholders::_2)); - m_wsServer.set_access_channels(websocketpp::log::alevel::all); - m_wsServer.clear_access_channels(websocketpp::log::alevel::frame_payload); + if (m_debug) { + m_wsServer.set_access_channels(websocketpp::log::alevel::all); + } else { + m_wsServer.set_access_channels(websocketpp::log::alevel::none); + } /** WebSocket Thread */ - if (!Thread::runAsThread(nullptr, threadWebSocket)) + if (!Thread::runAsThread(this, threadWebSocket)) return EXIT_FAILURE; ::LogInfoEx(LOG_HOST, "SysView is up and running"); @@ -261,13 +265,16 @@ int HostWS::run() void HostWS::send(json::object obj) { - json::value v = json::value(obj); - std::string json = std::string(v.serialize()); + try { + json::value v = json::value(obj); + std::string json = std::string(v.serialize()); - wsConList::iterator it; - for (it = m_wsConList.begin(); it != m_wsConList.end(); ++it) { - m_wsServer.send(*it, json, websocketpp::frame::opcode::text); + wsConList::iterator it; + for (it = m_wsConList.begin(); it != m_wsConList.end(); ++it) { + m_wsServer.send(*it, json, websocketpp::frame::opcode::text); + } } + catch (websocketpp::exception) { /* stub */ } } // --------------------------------------------------------------------------- @@ -280,10 +287,15 @@ bool HostWS::readParams() { yaml::Node websocketConf = m_conf["websocket"]; m_websocketPort = websocketConf["port"].as(8443U); + m_debug = websocketConf["debug"].as(false); LogInfo("General Parameters"); LogInfo(" Port: %u", m_websocketPort); + if (m_debug) { + LogInfo(" Debug: yes"); + } + return true; } @@ -337,7 +349,7 @@ void* HostWS::threadWebSocket(void* arg) ::pthread_setname_np(th->thread, threadName.c_str()); #endif // _GNU_SOURCE - ws->m_wsServer.listen(ws->m_websocketPort); + ws->m_wsServer.listen(websocketpp::lib::asio::ip::tcp::v4(), ws->m_websocketPort); ws->m_wsServer.start_accept(); ws->m_wsServer.run(); diff --git a/src/sysview/HostWS.h b/src/sysview/HostWS.h index 635906c4..07e7a401 100644 --- a/src/sysview/HostWS.h +++ b/src/sysview/HostWS.h @@ -76,6 +76,8 @@ private: typedef std::set> wsConList; wsConList m_wsConList; + bool m_debug; + /** * @brief Reads basic configuration parameters from the INI. * @returns bool True, if configuration was read successfully, otherwise false.