2023-07-13 03:54:02 +02:00
|
|
|
// Copyright 2019 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-09-11 22:00:12 +02:00
|
|
|
#include <functional>
|
2019-01-29 23:28:50 +01:00
|
|
|
#include "core/rpc/packet.h"
|
2018-09-11 22:00:12 +02:00
|
|
|
#include "core/rpc/rpc_server.h"
|
|
|
|
#include "core/rpc/server.h"
|
2019-01-29 23:28:50 +01:00
|
|
|
#include "core/rpc/udp_server.h"
|
2018-09-11 22:00:12 +02:00
|
|
|
|
2023-07-13 03:54:02 +02:00
|
|
|
namespace Core::RPC {
|
2019-01-29 23:28:50 +01:00
|
|
|
|
2023-07-13 03:54:02 +02:00
|
|
|
Server::Server(RPCServer& rpc_server) : rpc_server(rpc_server) {
|
2019-01-29 23:28:50 +01:00
|
|
|
const auto callback = [this](std::unique_ptr<Packet> new_request) {
|
2018-09-11 22:00:12 +02:00
|
|
|
NewRequestCallback(std::move(new_request));
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
2019-01-29 23:28:50 +01:00
|
|
|
udp_server = std::make_unique<UDPServer>(callback);
|
2018-09-11 22:00:12 +02:00
|
|
|
} catch (...) {
|
2019-01-29 23:28:50 +01:00
|
|
|
LOG_ERROR(RPC_Server, "Error starting UDP server");
|
2018-09-11 22:00:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-13 03:54:02 +02:00
|
|
|
Server::~Server() {
|
2019-01-29 23:28:50 +01:00
|
|
|
udp_server.reset();
|
2019-03-04 17:05:07 +01:00
|
|
|
NewRequestCallback(nullptr); // Notify the RPC server to end
|
2018-09-11 22:00:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Server::NewRequestCallback(std::unique_ptr<RPC::Packet> new_request) {
|
2018-10-08 23:49:07 +02:00
|
|
|
if (new_request) {
|
|
|
|
LOG_INFO(RPC_Server, "Received request version={} id={} type={} size={}",
|
2020-12-29 06:39:21 +01:00
|
|
|
new_request->GetVersion(), new_request->GetId(), new_request->GetPacketType(),
|
|
|
|
new_request->GetPacketDataSize());
|
2018-10-08 23:49:07 +02:00
|
|
|
} else {
|
|
|
|
LOG_INFO(RPC_Server, "Received end packet");
|
|
|
|
}
|
2018-09-11 22:00:12 +02:00
|
|
|
rpc_server.QueueRequest(std::move(new_request));
|
|
|
|
}
|
|
|
|
|
2023-07-13 03:54:02 +02:00
|
|
|
}; // namespace Core::RPC
|