From b39a611a3d79912476161da4efffa259c2dd0223 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 3 Feb 2020 09:09:06 -0500 Subject: [PATCH 1/8] input_common/udp: Add missing header guard --- src/input_common/udp/udp.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/input_common/udp/udp.h b/src/input_common/udp/udp.h index ea3de60bb4..0e56e431b3 100644 --- a/src/input_common/udp/udp.h +++ b/src/input_common/udp/udp.h @@ -2,6 +2,8 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#pragma once + #include #include #include "input_common/main.h" From d7a58fe24dd0170a8920df3d8bf20e7c9745f2e8 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 3 Feb 2020 09:10:59 -0500 Subject: [PATCH 2/8] input_common/udp: Remove unnecessary inclusions --- src/input_common/udp/client.h | 1 - src/input_common/udp/protocol.h | 1 - src/input_common/udp/udp.cpp | 4 +++- src/input_common/udp/udp.h | 6 +----- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/input_common/udp/client.h b/src/input_common/udp/client.h index 5177f46be1..82bdb68d94 100644 --- a/src/input_common/udp/client.h +++ b/src/input_common/udp/client.h @@ -11,7 +11,6 @@ #include #include #include -#include #include "common/common_types.h" #include "common/thread.h" #include "common/vector_math.h" diff --git a/src/input_common/udp/protocol.h b/src/input_common/udp/protocol.h index d31bbeb899..5b1852d559 100644 --- a/src/input_common/udp/protocol.h +++ b/src/input_common/udp/protocol.h @@ -7,7 +7,6 @@ #include #include #include -#include #include #include "common/bit_field.h" #include "common/swap.h" diff --git a/src/input_common/udp/udp.cpp b/src/input_common/udp/udp.cpp index 43691ae2c2..08aee5f024 100644 --- a/src/input_common/udp/udp.cpp +++ b/src/input_common/udp/udp.cpp @@ -2,7 +2,9 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include "common/logging/log.h" +#include +#include + #include "common/param_package.h" #include "core/frontend/input.h" #include "core/settings.h" diff --git a/src/input_common/udp/udp.h b/src/input_common/udp/udp.h index 0e56e431b3..4f83f0441f 100644 --- a/src/input_common/udp/udp.h +++ b/src/input_common/udp/udp.h @@ -5,14 +5,10 @@ #pragma once #include -#include -#include "input_common/main.h" -#include "input_common/udp/client.h" namespace InputCommon::CemuhookUDP { -class UDPTouchDevice; -class UDPMotionDevice; +class Client; class State { public: From 7d45fdc1df23b4417d5787a191292c2055d87f81 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 3 Feb 2020 09:15:30 -0500 Subject: [PATCH 3/8] input_common/udp: Silence -Wreorder warning for Socket Amends the constructor initializer list to specify the order of its elements in the same order that initialization would occur. --- src/input_common/udp/client.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index 8874365503..ba46a43708 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp @@ -31,10 +31,9 @@ public: explicit Socket(const std::string& host, u16 port, u8 pad_index, u32 client_id, SocketCallback callback) - : client_id(client_id), timer(io_service), - send_endpoint(udp::endpoint(address_v4::from_string(host), port)), - socket(io_service, udp::endpoint(udp::v4(), 0)), pad_index(pad_index), - callback(std::move(callback)) {} + : callback(std::move(callback)), timer(io_service), + socket(io_service, udp::endpoint(udp::v4(), 0)), client_id(client_id), + pad_index(pad_index), send_endpoint(udp::endpoint(address_v4::from_string(host), port)) {} void Stop() { io_service.stop(); From 8a0f8c3a4f74b0e552c0d312360ef1b9b57e85ee Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 3 Feb 2020 09:19:03 -0500 Subject: [PATCH 4/8] udp/client: Replace deprecated from_string() call with make_address_v4() Future-proofs code if boost is ever updated. --- src/input_common/udp/client.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index ba46a43708..5f5d271243 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp @@ -14,7 +14,6 @@ #include "input_common/udp/client.h" #include "input_common/udp/protocol.h" -using boost::asio::ip::address_v4; using boost::asio::ip::udp; namespace InputCommon::CemuhookUDP { @@ -33,7 +32,8 @@ public: SocketCallback callback) : callback(std::move(callback)), timer(io_service), socket(io_service, udp::endpoint(udp::v4(), 0)), client_id(client_id), - pad_index(pad_index), send_endpoint(udp::endpoint(address_v4::from_string(host), port)) {} + pad_index(pad_index), + send_endpoint(udp::endpoint(boost::asio::ip::make_address_v4(host), port)) {} void Stop() { io_service.stop(); From fcdc1911076f3f6e478f6c579600ebea57e6c481 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 3 Feb 2020 09:21:44 -0500 Subject: [PATCH 5/8] input_common/udp: std::move shared_ptr within Client constructor Gets rid of a trivially avoidable atomic reference count increment and decrement. --- src/input_common/udp/client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index 5f5d271243..b6946d9dcf 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp @@ -125,7 +125,7 @@ static void SocketLoop(Socket* socket) { Client::Client(std::shared_ptr status, const std::string& host, u16 port, u8 pad_index, u32 client_id) - : status(status) { + : status(std::move(status)) { StartCommunication(host, port, pad_index, client_id); } From 575ab92a760f453111b91646049872feef9862e8 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 3 Feb 2020 09:24:03 -0500 Subject: [PATCH 6/8] input_common/udp: std::move SocketCallback instances where applicable std::function is allowed to heap allocate if the size of the captures associated with each lambda exceed a certain threshold. This prevents potentially unnecessary reallocations from occurring. --- src/input_common/udp/client.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index b6946d9dcf..c9ffe899c6 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp @@ -207,7 +207,7 @@ void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 clie Common::Event success_event; SocketCallback callback{[](Response::Version version) {}, [](Response::PortInfo info) {}, [&](Response::PadData data) { success_event.Set(); }}; - Socket socket{host, port, pad_index, client_id, callback}; + Socket socket{host, port, pad_index, client_id, std::move(callback)}; std::thread worker_thread{SocketLoop, &socket}; bool result = success_event.WaitFor(std::chrono::seconds(8)); socket.Stop(); @@ -263,7 +263,7 @@ CalibrationConfigurationJob::CalibrationConfigurationJob( complete_event.Set(); } }}; - Socket socket{host, port, pad_index, client_id, callback}; + Socket socket{host, port, pad_index, client_id, std::move(callback)}; std::thread worker_thread{SocketLoop, &socket}; complete_event.Wait(); socket.Stop(); From 7362fe48acca810786251fe77eca4283fd3e81cb Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 3 Feb 2020 09:26:50 -0500 Subject: [PATCH 7/8] input_common/udp: Add missing override specifiers Prevents trivial warnings and ensures interfaces are properly maintained between the base class. --- src/input_common/udp/udp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/input_common/udp/udp.cpp b/src/input_common/udp/udp.cpp index 08aee5f024..1b83de373c 100644 --- a/src/input_common/udp/udp.cpp +++ b/src/input_common/udp/udp.cpp @@ -16,7 +16,7 @@ namespace InputCommon::CemuhookUDP { class UDPTouchDevice final : public Input::TouchDevice { public: explicit UDPTouchDevice(std::shared_ptr status_) : status(std::move(status_)) {} - std::tuple GetStatus() const { + std::tuple GetStatus() const override { std::lock_guard guard(status->update_mutex); return status->touch_status; } @@ -28,7 +28,7 @@ private: class UDPMotionDevice final : public Input::MotionDevice { public: explicit UDPMotionDevice(std::shared_ptr status_) : status(std::move(status_)) {} - std::tuple, Common::Vec3> GetStatus() const { + std::tuple, Common::Vec3> GetStatus() const override { std::lock_guard guard(status->update_mutex); return status->motion_status; } From 4c2c27046dae9c98a8a45a4130cc4a7a941c8310 Mon Sep 17 00:00:00 2001 From: FearlessTobi Date: Sun, 9 Feb 2020 23:09:19 +0100 Subject: [PATCH 8/8] Fix compilation --- src/input_common/udp/udp.cpp | 1 - src/input_common/udp/udp.h | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/input_common/udp/udp.cpp b/src/input_common/udp/udp.cpp index 1b83de373c..c4d5121b9b 100644 --- a/src/input_common/udp/udp.cpp +++ b/src/input_common/udp/udp.cpp @@ -4,7 +4,6 @@ #include #include - #include "common/param_package.h" #include "core/frontend/input.h" #include "core/settings.h" diff --git a/src/input_common/udp/udp.h b/src/input_common/udp/udp.h index 4f83f0441f..3eac8c7ea7 100644 --- a/src/input_common/udp/udp.h +++ b/src/input_common/udp/udp.h @@ -5,11 +5,10 @@ #pragma once #include +#include "input_common/udp/client.h" namespace InputCommon::CemuhookUDP { -class Client; - class State { public: State();