From eb512ca18ea25acdb830b0cc4d7a90c194d00d08 Mon Sep 17 00:00:00 2001 From: amass <168062547@qq.com> Date: Sat, 30 Dec 2023 00:10:51 +0800 Subject: [PATCH] remove unused code. --- .vscode/c_cpp_properties.json | 18 +++++++ Server/AlarmClockServer.cpp | 92 ----------------------------------- Server/AlarmClockServer.h | 28 ----------- Server/CMakeLists.txt | 2 - Server/main.cpp | 6 +-- resource/deploy.sh | 3 +- 6 files changed, 20 insertions(+), 129 deletions(-) create mode 100644 .vscode/c_cpp_properties.json delete mode 100644 Server/AlarmClockServer.cpp delete mode 100644 Server/AlarmClockServer.h diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..b7d94f2 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**", + "${workspaceFolder}/build/_deps/kylin-src/Universal", + "/opt/Libraries/boost_1_84_0/include" + ], + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "c17", + "cppStandard": "gnu++17", + "intelliSenseMode": "linux-gcc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/Server/AlarmClockServer.cpp b/Server/AlarmClockServer.cpp deleted file mode 100644 index 79b9645..0000000 --- a/Server/AlarmClockServer.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include "AlarmClockServer.h" -#include "ServiceManager.h" -#include -#include - -AlarmClockServer::AlarmClockServer(boost::asio::io_context &context) - : m_publisher(context, ZeroMQ::SocketType::Pub), m_timer(context) { - auto manager = Amass::Singleton::instance(); - manager->registerTopic(SetAlarmClock, [this](uint8_t hour, uint8_t minute) { setAlarmTime(hour, minute); }); - manager->registerTopic(TextToSpeech, [this](const std::string &text) { textToSpeech(text); }); - manager->registerTopic(CurrentDatetime, [this]() { currentDatatime(); }); - manager->registerTopic(PlayRandomMusic, [this]() { playRandomMusic(); }); - manager->registerTopic(StopPlayMusic, [this]() { stopPlayMusic(); }); -} - -void AlarmClockServer::startPublishHeartBeat() { - m_timer.expires_after(std::chrono::seconds(25)); - m_timer.async_wait([this](const boost::system::error_code &error) { - if (error) { - LOG(error) << error.message(); - return; - } - boost::json::object obj; - obj["type"] = HeartBeat; - ZeroMQ::Message message(boost::json::serialize(obj)); - auto size = m_publisher.send(std::move(message), ZeroMQ::SendFlags::Dontwait); - startPublishHeartBeat(); - }); -} - -void AlarmClockServer::listen(const std::string_view &host, const std::string_view &port) { - std::ostringstream oss; - oss << "tcp://" << host << ":" << port; - boost::system::error_code error; - auto address = oss.str(); - m_publisher.bind(address, error); - if (error) { - LOG(error) << error.message(); - return; - } - startPublishHeartBeat(); - LOG(info) << "AlarmClockServer bind address: " << address; -} - -void AlarmClockServer::setAlarmTime(uint8_t hour, uint8_t minute) { - boost::json::object obj; - obj["type"] = SetAlarmClock; - obj["hour"] = hour; - obj["minute"] = minute; - - auto body = boost::json::serialize(obj); - ZeroMQ::Message message(body); - auto size = m_publisher.send(std::move(message), ZeroMQ::SendFlags::Dontwait); - LOG(info) << "send to client: " << body << ", size: " << size; -} - -void AlarmClockServer::textToSpeech(const std::string_view &text) { - boost::json::object obj; - obj["type"] = TextToSpeech.topic; - obj["text"] = text.data(); - auto body = boost::json::serialize(obj); - ZeroMQ::Message message(body); - auto size = m_publisher.send(std::move(message), ZeroMQ::SendFlags::Dontwait); - LOG(info) << "text:[" << text << "].\nsend to client: " << body << ", size: " << size; -} - -void AlarmClockServer::currentDatatime() { - boost::json::object obj; - obj["type"] = CurrentDatetime; - auto body = boost::json::serialize(obj); - ZeroMQ::Message message(body); - auto size = m_publisher.send(std::move(message), ZeroMQ::SendFlags::Dontwait); - LOG(info) << "send to client: " << body << ", size: " << size; -} - -void AlarmClockServer::playRandomMusic() { - boost::json::object obj; - obj["type"] = PlayRandomMusic; - auto body = boost::json::serialize(obj); - ZeroMQ::Message message(body); - auto size = m_publisher.send(std::move(message), ZeroMQ::SendFlags::Dontwait); - LOG(info) << "send to client: " << body << ", size: " << size; -} - -void AlarmClockServer::stopPlayMusic() { - boost::json::object obj; - obj["type"] = StopPlayMusic.topic; - auto body = boost::json::serialize(obj); - ZeroMQ::Message message(body); - auto size = m_publisher.send(std::move(message), ZeroMQ::SendFlags::Dontwait); - LOG(info) << "send to client: " << body << ", size: " << size; -} diff --git a/Server/AlarmClockServer.h b/Server/AlarmClockServer.h deleted file mode 100644 index a3b4ae9..0000000 --- a/Server/AlarmClockServer.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef __ALARMCLOCKSERVER_H__ -#define __ALARMCLOCKSERVER_H__ - -#include "ZeroMQSocket.h" -#include -#include - -class AlarmClockServer { - friend class Amass::Singleton; - -public: - void listen(const std::string_view &host, const std::string_view &port); - void setAlarmTime(uint8_t hour, uint8_t minute); - void textToSpeech(const std::string_view &text); - void currentDatatime(); - -protected: - AlarmClockServer(boost::asio::io_context &context); - void startPublishHeartBeat(); - void playRandomMusic(); - void stopPlayMusic(); - -private: - ZeroMQ::Socket m_publisher; - boost::asio::steady_timer m_timer; -}; - -#endif // __ALARMCLOCKSERVER_H__ \ No newline at end of file diff --git a/Server/CMakeLists.txt b/Server/CMakeLists.txt index d88f31e..8db33f8 100644 --- a/Server/CMakeLists.txt +++ b/Server/CMakeLists.txt @@ -1,7 +1,6 @@ find_package(Boost COMPONENTS program_options json REQUIRED) add_executable(Server main.cpp - AlarmClockServer.h AlarmClockServer.cpp HttpSession.h HttpSession.cpp Listener.h Listener.cpp ResponseUtility.h ResponseUtility.cpp @@ -18,7 +17,6 @@ add_executable(Server main.cpp target_link_libraries(Server PRIVATE Universal PRIVATE HttpProxy - PRIVATE AsioZeroMQ PRIVATE ${Boost_LIBRARIES} ) diff --git a/Server/main.cpp b/Server/main.cpp index 8e065d3..479aa7e 100644 --- a/Server/main.cpp +++ b/Server/main.cpp @@ -1,4 +1,3 @@ -#include "AlarmClockServer.h" #include "BoostLog.h" #include "IoContext.h" #include "Listener.h" @@ -16,7 +15,7 @@ void initSettings(); int main(int argc, char const *argv[]) { - initBoostLog("HttpServer"); + boost::log::initialize("logs/HttpServer"); auto manager = Amass::Singleton::instance(); boost::program_options::options_description description("Allowed options"); @@ -113,9 +112,6 @@ int main(int argc, char const *argv[]) { state->setFileRoot(fileRoot); state->setNotebookRoot(notebookRoot); - auto alarmClockServer = Amass::Singleton::instance(*ioContext->ioContext()); - alarmClockServer->listen(server, "8089"); - auto wechatContext = Amass::Singleton::instance(*ioContext->ioContext()); auto corpContext = Amass::Singleton::instance(*ioContext->ioContext()); diff --git a/resource/deploy.sh b/resource/deploy.sh index 5c11944..cfc2a62 100755 --- a/resource/deploy.sh +++ b/resource/deploy.sh @@ -14,8 +14,7 @@ function cmake_scan() { -S ${base_path} \ -B ${build_path} \ -DCMAKE_BUILD_TYPE=Debug \ - -DBOOST_ROOT=${libraries_root}/boost_1_82_0 \ - -DZeroMQ_ROOT=${libraries_root}/zeromq-4.3.4_debug + -DBOOST_ROOT=${libraries_root}/boost_1_84_0 } function build() {