From 4aa9c9632df1f896c5ada61e546482a6fee6dd13 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 3 Feb 2020 09:09:06 -0500 Subject: input_common/udp: Add missing header guard --- src/input_common/udp/udp.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/input_common/udp/udp.h b/src/input_common/udp/udp.h index ea3de60bb..0e56e431b 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" -- cgit v1.2.3 From 36524465a6fb9940ab5297cef21cd2aa6de8e239 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 3 Feb 2020 09:10:59 -0500 Subject: 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(-) (limited to 'src') diff --git a/src/input_common/udp/client.h b/src/input_common/udp/client.h index 0b21f4da6..b8c654755 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 1b521860a..3ba4d1fc8 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 a80f38614..49a747327 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 0e56e431b..4f83f0441 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: -- cgit v1.2.3 From 881408445a3e4a22734f6ccfdf7f96575fa249d3 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 3 Feb 2020 09:15:30 -0500 Subject: 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(-) (limited to 'src') diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index 5f5a9989c..7d6b0478e 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(); -- cgit v1.2.3 From 9bb6ab77f4439ea8c9d78c896aedf8dcdf0c1c6e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 3 Feb 2020 09:19:03 -0500 Subject: 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(-) (limited to 'src') diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index 7d6b0478e..f020628eb 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(); -- cgit v1.2.3 From fb9c9ddcc908e181793fb2564c7e05c1af5d4913 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 3 Feb 2020 09:21:44 -0500 Subject: 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(-) (limited to 'src') diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index f020628eb..1fa246e79 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); } -- cgit v1.2.3 From 5c61e0ba3938c9b939416ec996ee339bf1417ebf Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 3 Feb 2020 09:24:03 -0500 Subject: 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(-) (limited to 'src') diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index 1fa246e79..2228571a6 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp @@ -206,7 +206,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(); @@ -266,7 +266,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(); -- cgit v1.2.3 From 83f8090273fbc8d499b08c6a53700c9a2c262d81 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 3 Feb 2020 09:26:50 -0500 Subject: 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(-) (limited to 'src') diff --git a/src/input_common/udp/udp.cpp b/src/input_common/udp/udp.cpp index 49a747327..ca99cc22f 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; } -- cgit v1.2.3 From c7678c3044165d9e15ae6a8e0d996f8b793f3c0f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 3 Feb 2020 09:29:13 -0500 Subject: input_common/udp: Ensure that UDP is shut down within Shutdown() Previously the UDP backend would never actually get shut down. --- src/input_common/main.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index 9e028da89..c98c848cf 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp @@ -41,6 +41,7 @@ void Shutdown() { Input::UnregisterFactory("motion_emu"); motion_emu.reset(); sdl.reset(); + udp.reset(); } Keyboard* GetKeyboard() { -- cgit v1.2.3