From 046c0c91a3ed665531f20955e7cfb86fe5b73213 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 14 Oct 2020 02:51:14 -0400 Subject: input_common/CMakeLists: Make some warnings errors Makes the input_common code warnings consistent with the rest of the codebase. --- src/input_common/udp/udp.cpp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'src/input_common/udp/udp.cpp') diff --git a/src/input_common/udp/udp.cpp b/src/input_common/udp/udp.cpp index eba077a36..71a76a7aa 100644 --- a/src/input_common/udp/udp.cpp +++ b/src/input_common/udp/udp.cpp @@ -2,8 +2,6 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include -#include #include #include #include "common/assert.h" @@ -15,8 +13,8 @@ namespace InputCommon { class UDPMotion final : public Input::MotionDevice { public: - UDPMotion(std::string ip_, int port_, int pad_, CemuhookUDP::Client* client_) - : ip(ip_), port(port_), pad(pad_), client(client_) {} + explicit UDPMotion(std::string ip_, int port_, u32 pad_, CemuhookUDP::Client* client_) + : ip(std::move(ip_)), port(port_), pad(pad_), client(client_) {} Input::MotionStatus GetStatus() const override { return client->GetPadState(pad).motion_status; @@ -25,7 +23,7 @@ public: private: const std::string ip; const int port; - const int pad; + const u32 pad; CemuhookUDP::Client* client; mutable std::mutex mutex; }; @@ -40,11 +38,11 @@ UDPMotionFactory::UDPMotionFactory(std::shared_ptr client_) * - "port": the nth jcpad on the adapter */ std::unique_ptr UDPMotionFactory::Create(const Common::ParamPackage& params) { - const std::string ip = params.Get("ip", "127.0.0.1"); - const int port = params.Get("port", 26760); - const int pad = params.Get("pad_index", 0); + auto ip = params.Get("ip", "127.0.0.1"); + const auto port = params.Get("port", 26760); + const auto pad = static_cast(params.Get("pad_index", 0)); - return std::make_unique(ip, port, pad, client.get()); + return std::make_unique(std::move(ip), port, pad, client.get()); } void UDPMotionFactory::BeginConfiguration() { @@ -79,7 +77,7 @@ Common::ParamPackage UDPMotionFactory::GetNextInput() { class UDPTouch final : public Input::TouchDevice { public: - UDPTouch(std::string ip_, int port_, int pad_, CemuhookUDP::Client* client_) + explicit UDPTouch(std::string ip_, int port_, u32 pad_, CemuhookUDP::Client* client_) : ip(std::move(ip_)), port(port_), pad(pad_), client(client_) {} std::tuple GetStatus() const override { @@ -89,7 +87,7 @@ public: private: const std::string ip; const int port; - const int pad; + const u32 pad; CemuhookUDP::Client* client; mutable std::mutex mutex; }; @@ -104,11 +102,11 @@ UDPTouchFactory::UDPTouchFactory(std::shared_ptr client_) * - "port": the nth jcpad on the adapter */ std::unique_ptr UDPTouchFactory::Create(const Common::ParamPackage& params) { - const std::string ip = params.Get("ip", "127.0.0.1"); - const int port = params.Get("port", 26760); - const int pad = params.Get("pad_index", 0); + auto ip = params.Get("ip", "127.0.0.1"); + const auto port = params.Get("port", 26760); + const auto pad = static_cast(params.Get("pad_index", 0)); - return std::make_unique(ip, port, pad, client.get()); + return std::make_unique(std::move(ip), port, pad, client.get()); } void UDPTouchFactory::BeginConfiguration() { -- cgit v1.2.3 From 2c2b586d86d71bd6c134c32d27b155615230222e Mon Sep 17 00:00:00 2001 From: german Date: Tue, 17 Nov 2020 22:16:29 -0600 Subject: Add multiple udp server support --- src/input_common/udp/udp.cpp | 64 +++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 34 deletions(-) (limited to 'src/input_common/udp/udp.cpp') diff --git a/src/input_common/udp/udp.cpp b/src/input_common/udp/udp.cpp index 71a76a7aa..8686a059c 100644 --- a/src/input_common/udp/udp.cpp +++ b/src/input_common/udp/udp.cpp @@ -13,17 +13,17 @@ namespace InputCommon { class UDPMotion final : public Input::MotionDevice { public: - explicit UDPMotion(std::string ip_, int port_, u32 pad_, CemuhookUDP::Client* client_) + explicit UDPMotion(std::string ip_, u16 port_, u16 pad_, CemuhookUDP::Client* client_) : ip(std::move(ip_)), port(port_), pad(pad_), client(client_) {} Input::MotionStatus GetStatus() const override { - return client->GetPadState(pad).motion_status; + return client->GetPadState(ip, port, pad).motion_status; } private: const std::string ip; - const int port; - const u32 pad; + const u16 port; + const u16 pad; CemuhookUDP::Client* client; mutable std::mutex mutex; }; @@ -39,8 +39,8 @@ UDPMotionFactory::UDPMotionFactory(std::shared_ptr client_) */ std::unique_ptr UDPMotionFactory::Create(const Common::ParamPackage& params) { auto ip = params.Get("ip", "127.0.0.1"); - const auto port = params.Get("port", 26760); - const auto pad = static_cast(params.Get("pad_index", 0)); + const auto port = static_cast(params.Get("port", 26760)); + const auto pad = static_cast(params.Get("pad_index", 0)); return std::make_unique(std::move(ip), port, pad, client.get()); } @@ -59,35 +59,33 @@ Common::ParamPackage UDPMotionFactory::GetNextInput() { Common::ParamPackage params; CemuhookUDP::UDPPadStatus pad; auto& queue = client->GetPadQueue(); - for (std::size_t pad_number = 0; pad_number < queue.size(); ++pad_number) { - while (queue[pad_number].Pop(pad)) { - if (pad.motion == CemuhookUDP::PadMotion::Undefined || std::abs(pad.motion_value) < 1) { - continue; - } - params.Set("engine", "cemuhookudp"); - params.Set("ip", "127.0.0.1"); - params.Set("port", 26760); - params.Set("pad_index", static_cast(pad_number)); - params.Set("motion", static_cast(pad.motion)); - return params; + while (queue.Pop(pad)) { + if (pad.motion == CemuhookUDP::PadMotion::Undefined || std::abs(pad.motion_value) < 1) { + continue; } + params.Set("engine", "cemuhookudp"); + params.Set("ip", pad.host); + params.Set("port", static_cast(pad.port)); + params.Set("pad_index", static_cast(pad.pad_index)); + params.Set("motion", static_cast(pad.motion)); + return params; } return params; } class UDPTouch final : public Input::TouchDevice { public: - explicit UDPTouch(std::string ip_, int port_, u32 pad_, CemuhookUDP::Client* client_) + explicit UDPTouch(std::string ip_, u16 port_, u16 pad_, CemuhookUDP::Client* client_) : ip(std::move(ip_)), port(port_), pad(pad_), client(client_) {} std::tuple GetStatus() const override { - return client->GetPadState(pad).touch_status; + return client->GetPadState(ip, port, pad).touch_status; } private: const std::string ip; - const int port; - const u32 pad; + const u16 port; + const u16 pad; CemuhookUDP::Client* client; mutable std::mutex mutex; }; @@ -103,8 +101,8 @@ UDPTouchFactory::UDPTouchFactory(std::shared_ptr client_) */ std::unique_ptr UDPTouchFactory::Create(const Common::ParamPackage& params) { auto ip = params.Get("ip", "127.0.0.1"); - const auto port = params.Get("port", 26760); - const auto pad = static_cast(params.Get("pad_index", 0)); + const auto port = static_cast(params.Get("port", 26760)); + const auto pad = static_cast(params.Get("pad_index", 0)); return std::make_unique(std::move(ip), port, pad, client.get()); } @@ -123,18 +121,16 @@ Common::ParamPackage UDPTouchFactory::GetNextInput() { Common::ParamPackage params; CemuhookUDP::UDPPadStatus pad; auto& queue = client->GetPadQueue(); - for (std::size_t pad_number = 0; pad_number < queue.size(); ++pad_number) { - while (queue[pad_number].Pop(pad)) { - if (pad.touch == CemuhookUDP::PadTouch::Undefined) { - continue; - } - params.Set("engine", "cemuhookudp"); - params.Set("ip", "127.0.0.1"); - params.Set("port", 26760); - params.Set("pad_index", static_cast(pad_number)); - params.Set("touch", static_cast(pad.touch)); - return params; + while (queue.Pop(pad)) { + if (pad.touch == CemuhookUDP::PadTouch::Undefined) { + continue; } + params.Set("engine", "cemuhookudp"); + params.Set("ip", pad.host); + params.Set("port", static_cast(pad.port)); + params.Set("pad_index", static_cast(pad.pad_index)); + params.Set("touch", static_cast(pad.touch)); + return params; } return params; } -- cgit v1.2.3 From a745d87971b2c9795e1b2c587bfe30b849b522fa Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Sat, 2 Jan 2021 09:00:05 -0500 Subject: general: Fix various spelling errors --- src/input_common/udp/udp.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/input_common/udp/udp.cpp') diff --git a/src/input_common/udp/udp.cpp b/src/input_common/udp/udp.cpp index 8686a059c..c5da27a38 100644 --- a/src/input_common/udp/udp.cpp +++ b/src/input_common/udp/udp.cpp @@ -28,14 +28,14 @@ private: mutable std::mutex mutex; }; -/// A motion device factory that creates motion devices from JC Adapter +/// A motion device factory that creates motion devices from a UDP client UDPMotionFactory::UDPMotionFactory(std::shared_ptr client_) : client(std::move(client_)) {} /** * Creates motion device * @param params contains parameters for creating the device: - * - "port": the nth jcpad on the adapter + * - "port": the UDP port number */ std::unique_ptr UDPMotionFactory::Create(const Common::ParamPackage& params) { auto ip = params.Get("ip", "127.0.0.1"); @@ -90,14 +90,14 @@ private: mutable std::mutex mutex; }; -/// A motion device factory that creates motion devices from JC Adapter +/// A motion device factory that creates motion devices from a UDP client UDPTouchFactory::UDPTouchFactory(std::shared_ptr client_) : client(std::move(client_)) {} /** * Creates motion device * @param params contains parameters for creating the device: - * - "port": the nth jcpad on the adapter + * - "port": the UDP port number */ std::unique_ptr UDPTouchFactory::Create(const Common::ParamPackage& params) { auto ip = params.Get("ip", "127.0.0.1"); -- cgit v1.2.3