From bbd85a495a3576a5ec99cd69b54e983653b38ea4 Mon Sep 17 00:00:00 2001 From: FearlessTobi Date: Sun, 3 Nov 2019 08:07:04 +0100 Subject: [PATCH] Address second part of review comments --- src/common/thread.h | 2 +- src/input_common/udp/client.cpp | 14 +++++++++----- src/input_common/udp/client.h | 4 ++-- src/input_common/udp/protocol.cpp | 12 ++++++------ 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/common/thread.h b/src/common/thread.h index 5584c3bf3..2fc071685 100644 --- a/src/common/thread.h +++ b/src/common/thread.h @@ -30,7 +30,7 @@ public: template bool WaitFor(const std::chrono::duration& time) { - std::unique_lock lk(mutex); + std::unique_lock lk{mutex}; if (!condvar.wait_for(lk, time, [this] { return is_set; })) return false; is_set = false; diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index 3c51f72a0..5f5a9989c 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp @@ -212,10 +212,11 @@ void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 clie bool result = success_event.WaitFor(std::chrono::seconds(8)); socket.Stop(); worker_thread.join(); - if (result) + if (result) { success_callback(); - else + } else { failure_callback(); + } }) .detach(); } @@ -228,8 +229,10 @@ CalibrationConfigurationJob::CalibrationConfigurationJob( std::thread([=] { constexpr u16 CALIBRATION_THRESHOLD = 100; - u16 min_x{UINT16_MAX}, min_y{UINT16_MAX}; - u16 max_x{}, max_y{}; + u16 min_x{UINT16_MAX}; + u16 min_y{UINT16_MAX}; + u16 max_x{}; + u16 max_y{}; Status current_status{Status::Initialized}; SocketCallback callback{[](Response::Version version) {}, [](Response::PortInfo info) {}, @@ -239,8 +242,9 @@ CalibrationConfigurationJob::CalibrationConfigurationJob( current_status = Status::Ready; status_callback(current_status); } - if (!data.touch_1.is_active) + if (!data.touch_1.is_active) { return; + } LOG_DEBUG(Input, "Current touch: {} {}", data.touch_1.x, data.touch_1.y); min_x = std::min(min_x, static_cast(data.touch_1.x)); diff --git a/src/input_common/udp/client.h b/src/input_common/udp/client.h index b06a3f85a..0b21f4da6 100644 --- a/src/input_common/udp/client.h +++ b/src/input_common/udp/client.h @@ -18,8 +18,8 @@ namespace InputCommon::CemuhookUDP { -static constexpr u16 DEFAULT_PORT = 26760; -static constexpr const char* DEFAULT_ADDR = "127.0.0.1"; +constexpr u16 DEFAULT_PORT = 26760; +constexpr char DEFAULT_ADDR[] = "127.0.0.1"; class Socket; diff --git a/src/input_common/udp/protocol.cpp b/src/input_common/udp/protocol.cpp index 16da706d5..a982ac49d 100644 --- a/src/input_common/udp/protocol.cpp +++ b/src/input_common/udp/protocol.cpp @@ -32,21 +32,21 @@ namespace Response { std::optional Validate(u8* data, std::size_t size) { if (size < sizeof(Header)) { LOG_DEBUG(Input, "Invalid UDP packet received"); - return {}; + return std::nullopt; } Header header{}; std::memcpy(&header, data, sizeof(Header)); if (header.magic != SERVER_MAGIC) { LOG_ERROR(Input, "UDP Packet has an unexpected magic value"); - return {}; + return std::nullopt; } if (header.protocol_version != PROTOCOL_VERSION) { LOG_ERROR(Input, "UDP Packet protocol mismatch"); - return {}; + return std::nullopt; } if (header.type < Type::Version || header.type > Type::PadData) { LOG_ERROR(Input, "UDP Packet is an unknown type"); - return {}; + return std::nullopt; } // Packet size must equal sizeof(Header) + sizeof(Data) @@ -59,7 +59,7 @@ std::optional Validate(u8* data, std::size_t size) { Input, "UDP Packet payload length doesn't match. Received: {} PayloadLength: {} Expected: {}", size, header.payload_length, data_len + sizeof(Type)); - return {}; + return std::nullopt; } const u32 crc32 = header.crc; @@ -70,7 +70,7 @@ std::optional Validate(u8* data, std::size_t size) { result.process_bytes(data, data_len + sizeof(Header)); if (crc32 != result.checksum()) { LOG_ERROR(Input, "UDP Packet CRC check failed. Offset: {}", offsetof(Header, crc)); - return {}; + return std::nullopt; } return header.type; }