remove unused code.
This commit is contained in:
parent
c600c509be
commit
eb512ca18e
18
.vscode/c_cpp_properties.json
vendored
Normal file
18
.vscode/c_cpp_properties.json
vendored
Normal file
@ -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
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
#include "AlarmClockServer.h"
|
||||
#include "ServiceManager.h"
|
||||
#include <boost/json/object.hpp>
|
||||
#include <boost/json/serialize.hpp>
|
||||
|
||||
AlarmClockServer::AlarmClockServer(boost::asio::io_context &context)
|
||||
: m_publisher(context, ZeroMQ::SocketType::Pub), m_timer(context) {
|
||||
auto manager = Amass::Singleton<ServiceManager>::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;
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
#ifndef __ALARMCLOCKSERVER_H__
|
||||
#define __ALARMCLOCKSERVER_H__
|
||||
|
||||
#include "ZeroMQSocket.h"
|
||||
#include <Singleton.h>
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
|
||||
class AlarmClockServer {
|
||||
friend class Amass::Singleton<AlarmClockServer>;
|
||||
|
||||
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__
|
@ -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}
|
||||
)
|
||||
|
||||
|
@ -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<ServiceManager>::instance<Amass::Construct>();
|
||||
|
||||
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<AlarmClockServer>::instance<Amass::Construct>(*ioContext->ioContext());
|
||||
alarmClockServer->listen(server, "8089");
|
||||
|
||||
auto wechatContext = Amass::Singleton<WeChatContext>::instance<Amass::Construct>(*ioContext->ioContext());
|
||||
auto corpContext = Amass::Singleton<CorporationContext>::instance<Amass::Construct>(*ioContext->ioContext());
|
||||
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user