summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar bunnei2020-02-03 11:41:04 -0500
committerGravatar GitHub2020-02-03 11:41:04 -0500
commit2cd51fc9fd11cce6aeea44dc0158f6bfde5456ec (patch)
treedfd9cc0b10283da66259842b584e920697d6196b
parentMerge pull request #3370 from ReinUsesLisp/node-shared-ptr (diff)
parentinput_common/udp: Ensure that UDP is shut down within Shutdown() (diff)
downloadyuzu-2cd51fc9fd11cce6aeea44dc0158f6bfde5456ec.tar.gz
yuzu-2cd51fc9fd11cce6aeea44dc0158f6bfde5456ec.tar.xz
yuzu-2cd51fc9fd11cce6aeea44dc0158f6bfde5456ec.zip
Merge pull request #3374 from lioncash/udp
input_common/udp: Minor changes
-rw-r--r--src/input_common/main.cpp1
-rw-r--r--src/input_common/udp/client.cpp15
-rw-r--r--src/input_common/udp/client.h1
-rw-r--r--src/input_common/udp/protocol.h1
-rw-r--r--src/input_common/udp/udp.cpp8
-rw-r--r--src/input_common/udp/udp.h8
6 files changed, 16 insertions, 18 deletions
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() {
41 Input::UnregisterFactory<Input::MotionDevice>("motion_emu"); 41 Input::UnregisterFactory<Input::MotionDevice>("motion_emu");
42 motion_emu.reset(); 42 motion_emu.reset();
43 sdl.reset(); 43 sdl.reset();
44 udp.reset();
44} 45}
45 46
46Keyboard* GetKeyboard() { 47Keyboard* GetKeyboard() {
diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp
index 5f5a9989c..2228571a6 100644
--- a/src/input_common/udp/client.cpp
+++ b/src/input_common/udp/client.cpp
@@ -14,7 +14,6 @@
14#include "input_common/udp/client.h" 14#include "input_common/udp/client.h"
15#include "input_common/udp/protocol.h" 15#include "input_common/udp/protocol.h"
16 16
17using boost::asio::ip::address_v4;
18using boost::asio::ip::udp; 17using boost::asio::ip::udp;
19 18
20namespace InputCommon::CemuhookUDP { 19namespace InputCommon::CemuhookUDP {
@@ -31,10 +30,10 @@ public:
31 30
32 explicit Socket(const std::string& host, u16 port, u8 pad_index, u32 client_id, 31 explicit Socket(const std::string& host, u16 port, u8 pad_index, u32 client_id,
33 SocketCallback callback) 32 SocketCallback callback)
34 : client_id(client_id), timer(io_service), 33 : callback(std::move(callback)), timer(io_service),
35 send_endpoint(udp::endpoint(address_v4::from_string(host), port)), 34 socket(io_service, udp::endpoint(udp::v4(), 0)), client_id(client_id),
36 socket(io_service, udp::endpoint(udp::v4(), 0)), pad_index(pad_index), 35 pad_index(pad_index),
37 callback(std::move(callback)) {} 36 send_endpoint(udp::endpoint(boost::asio::ip::make_address_v4(host), port)) {}
38 37
39 void Stop() { 38 void Stop() {
40 io_service.stop(); 39 io_service.stop();
@@ -126,7 +125,7 @@ static void SocketLoop(Socket* socket) {
126 125
127Client::Client(std::shared_ptr<DeviceStatus> status, const std::string& host, u16 port, 126Client::Client(std::shared_ptr<DeviceStatus> status, const std::string& host, u16 port,
128 u8 pad_index, u32 client_id) 127 u8 pad_index, u32 client_id)
129 : status(status) { 128 : status(std::move(status)) {
130 StartCommunication(host, port, pad_index, client_id); 129 StartCommunication(host, port, pad_index, client_id);
131} 130}
132 131
@@ -207,7 +206,7 @@ void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 clie
207 Common::Event success_event; 206 Common::Event success_event;
208 SocketCallback callback{[](Response::Version version) {}, [](Response::PortInfo info) {}, 207 SocketCallback callback{[](Response::Version version) {}, [](Response::PortInfo info) {},
209 [&](Response::PadData data) { success_event.Set(); }}; 208 [&](Response::PadData data) { success_event.Set(); }};
210 Socket socket{host, port, pad_index, client_id, callback}; 209 Socket socket{host, port, pad_index, client_id, std::move(callback)};
211 std::thread worker_thread{SocketLoop, &socket}; 210 std::thread worker_thread{SocketLoop, &socket};
212 bool result = success_event.WaitFor(std::chrono::seconds(8)); 211 bool result = success_event.WaitFor(std::chrono::seconds(8));
213 socket.Stop(); 212 socket.Stop();
@@ -267,7 +266,7 @@ CalibrationConfigurationJob::CalibrationConfigurationJob(
267 complete_event.Set(); 266 complete_event.Set();
268 } 267 }
269 }}; 268 }};
270 Socket socket{host, port, pad_index, client_id, callback}; 269 Socket socket{host, port, pad_index, client_id, std::move(callback)};
271 std::thread worker_thread{SocketLoop, &socket}; 270 std::thread worker_thread{SocketLoop, &socket};
272 complete_event.Wait(); 271 complete_event.Wait();
273 socket.Stop(); 272 socket.Stop();
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 @@
11#include <string> 11#include <string>
12#include <thread> 12#include <thread>
13#include <tuple> 13#include <tuple>
14#include <vector>
15#include "common/common_types.h" 14#include "common/common_types.h"
16#include "common/thread.h" 15#include "common/thread.h"
17#include "common/vector_math.h" 16#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 @@
7#include <array> 7#include <array>
8#include <optional> 8#include <optional>
9#include <type_traits> 9#include <type_traits>
10#include <vector>
11#include <boost/crc.hpp> 10#include <boost/crc.hpp>
12#include "common/bit_field.h" 11#include "common/bit_field.h"
13#include "common/swap.h" 12#include "common/swap.h"
diff --git a/src/input_common/udp/udp.cpp b/src/input_common/udp/udp.cpp
index a80f38614..ca99cc22f 100644
--- a/src/input_common/udp/udp.cpp
+++ b/src/input_common/udp/udp.cpp
@@ -2,7 +2,9 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include "common/logging/log.h" 5#include <mutex>
6#include <tuple>
7
6#include "common/param_package.h" 8#include "common/param_package.h"
7#include "core/frontend/input.h" 9#include "core/frontend/input.h"
8#include "core/settings.h" 10#include "core/settings.h"
@@ -14,7 +16,7 @@ namespace InputCommon::CemuhookUDP {
14class UDPTouchDevice final : public Input::TouchDevice { 16class UDPTouchDevice final : public Input::TouchDevice {
15public: 17public:
16 explicit UDPTouchDevice(std::shared_ptr<DeviceStatus> status_) : status(std::move(status_)) {} 18 explicit UDPTouchDevice(std::shared_ptr<DeviceStatus> status_) : status(std::move(status_)) {}
17 std::tuple<float, float, bool> GetStatus() const { 19 std::tuple<float, float, bool> GetStatus() const override {
18 std::lock_guard guard(status->update_mutex); 20 std::lock_guard guard(status->update_mutex);
19 return status->touch_status; 21 return status->touch_status;
20 } 22 }
@@ -26,7 +28,7 @@ private:
26class UDPMotionDevice final : public Input::MotionDevice { 28class UDPMotionDevice final : public Input::MotionDevice {
27public: 29public:
28 explicit UDPMotionDevice(std::shared_ptr<DeviceStatus> status_) : status(std::move(status_)) {} 30 explicit UDPMotionDevice(std::shared_ptr<DeviceStatus> status_) : status(std::move(status_)) {}
29 std::tuple<Common::Vec3<float>, Common::Vec3<float>> GetStatus() const { 31 std::tuple<Common::Vec3<float>, Common::Vec3<float>> GetStatus() const override {
30 std::lock_guard guard(status->update_mutex); 32 std::lock_guard guard(status->update_mutex);
31 return status->motion_status; 33 return status->motion_status;
32 } 34 }
diff --git a/src/input_common/udp/udp.h b/src/input_common/udp/udp.h
index ea3de60bb..4f83f0441 100644
--- a/src/input_common/udp/udp.h
+++ b/src/input_common/udp/udp.h
@@ -2,15 +2,13 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#pragma once
6
5#include <memory> 7#include <memory>
6#include <unordered_map>
7#include "input_common/main.h"
8#include "input_common/udp/client.h"
9 8
10namespace InputCommon::CemuhookUDP { 9namespace InputCommon::CemuhookUDP {
11 10
12class UDPTouchDevice; 11class Client;
13class UDPMotionDevice;
14 12
15class State { 13class State {
16public: 14public: