summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface
diff options
context:
space:
mode:
authorrlnilsen <47765059+rlnilsen@users.noreply.github.com>2019-10-23 01:49:48 +0200
committerrlnilsen <47765059+rlnilsen@users.noreply.github.com>2019-10-26 02:20:18 +0200
commit5ff79499a593f651978188f1711728cf67d44a59 (patch)
tree8ce181cee26a227add0aae9a1f93da63a2f4707e /Source/Core/InputCommon/ControllerInterface
parent8aec424191b295e51d3f305c20086c08dd41b480 (diff)
UDPServer: Add configuration UI.
Accessed through button "Alternate Input Sources" in the "Controller Settings" dialog.
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface')
-rw-r--r--Source/Core/InputCommon/ControllerInterface/CemuHookUDPServer/CemuHookUDPServer.cpp48
-rw-r--r--Source/Core/InputCommon/ControllerInterface/CemuHookUDPServer/CemuHookUDPServer.h10
2 files changed, 39 insertions, 19 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/CemuHookUDPServer/CemuHookUDPServer.cpp b/Source/Core/InputCommon/ControllerInterface/CemuHookUDPServer/CemuHookUDPServer.cpp
index a480320b33..36cd148041 100644
--- a/Source/Core/InputCommon/ControllerInterface/CemuHookUDPServer/CemuHookUDPServer.cpp
+++ b/Source/Core/InputCommon/ControllerInterface/CemuHookUDPServer/CemuHookUDPServer.cpp
@@ -135,6 +135,7 @@ static std::thread s_hotplug_thread;
static Common::Flag s_hotplug_thread_running;
static std::mutex s_port_info_mutex;
static Proto::MessageType::PortInfo s_port_info[Proto::PORT_COUNT];
+static sf::UdpSocket s_socket;
static bool IsSameController(const Proto::MessageType::PortInfo& a,
const Proto::MessageType::PortInfo& b)
@@ -162,8 +163,6 @@ static void HotplugThreadFunc()
Common::SetCurrentThreadName("CemuHookUDPServer Hotplug Thread");
NOTICE_LOG(SERIALINTERFACE, "CemuHookUDPServer hotplug thread started");
- sf::UdpSocket socket;
-
while (s_hotplug_thread_running.IsSet())
{
const auto now = std::chrono::steady_clock::now();
@@ -180,7 +179,7 @@ static void HotplugThreadFunc()
list_ports.pad_id[2] = 2;
list_ports.pad_id[3] = 3;
msg.Finish();
- if (socket.send(&list_ports, sizeof list_ports, s_server_address, s_server_port) !=
+ if (s_socket.send(&list_ports, sizeof list_ports, s_server_address, s_server_port) !=
sf::Socket::Status::Done)
ERROR_LOG(SERIALINTERFACE, "CemuHookUDPServer HotplugThreadFunc send failed");
}
@@ -194,7 +193,7 @@ static void HotplugThreadFunc()
std::size_t received_bytes;
sf::IpAddress sender;
u16 port;
- if (ReceiveWithTimeout(socket, &msg, sizeof(msg), received_bytes, sender, port,
+ if (ReceiveWithTimeout(s_socket, &msg, sizeof(msg), received_bytes, sender, port,
sf::milliseconds(timeout_ms)) == sf::Socket::Status::Done)
{
if (auto port_info = msg.CheckAndCastTo<Proto::MessageType::PortInfo>())
@@ -233,14 +232,15 @@ static void StopHotplugThread()
return;
}
+ s_socket.unbind(); // interrupt blocking socket
s_hotplug_thread.join();
}
-void Init()
+static void Restart()
{
- s_server_enabled = Config::Get(Settings::SERVER_ENABLED);
- s_server_address = Config::Get(Settings::SERVER_ADDRESS);
- s_server_port = Config::Get(Settings::SERVER_PORT);
+ NOTICE_LOG(SERIALINTERFACE, "CemuHookUDPServer Restart");
+
+ StopHotplugThread();
s_client_uid = Common::Random::GenerateValue<u32>();
s_next_listports = std::chrono::steady_clock::time_point::min();
@@ -250,10 +250,32 @@ void Init()
s_port_info[port_index].pad_id = port_index;
}
+ PopulateDevices(); // remove devices
+
if (s_server_enabled)
StartHotplugThread();
}
+static void ConfigChanged()
+{
+ bool server_enabled = Config::Get(Settings::SERVER_ENABLED);
+ std::string server_address = Config::Get(Settings::SERVER_ADDRESS);
+ u16 server_port = Config::Get(Settings::SERVER_PORT);
+ if (server_enabled != s_server_enabled || server_address != s_server_address ||
+ server_port != s_server_port)
+ {
+ s_server_enabled = server_enabled;
+ s_server_address = server_address;
+ s_server_port = server_port;
+ Restart();
+ }
+}
+
+void Init()
+{
+ Config::AddConfigChangedCallback(ConfigChanged);
+}
+
void PopulateDevices()
{
NOTICE_LOG(SERIALINTERFACE, "CemuHookUDPServer PopulateDevices");
@@ -273,16 +295,6 @@ void PopulateDevices()
void DeInit()
{
StopHotplugThread();
- SaveSettings();
-}
-
-void SaveSettings()
-{
- Config::ConfigChangeCallbackGuard config_guard;
-
- Config::SetBaseOrCurrent(Settings::SERVER_ENABLED, s_server_enabled);
- Config::SetBaseOrCurrent(Settings::SERVER_ADDRESS, s_server_address);
- Config::SetBaseOrCurrent(Settings::SERVER_PORT, s_server_port);
}
Device::Device(Proto::DsModel model, int index)
diff --git a/Source/Core/InputCommon/ControllerInterface/CemuHookUDPServer/CemuHookUDPServer.h b/Source/Core/InputCommon/ControllerInterface/CemuHookUDPServer/CemuHookUDPServer.h
index 98b2506d2e..f7eaa34407 100644
--- a/Source/Core/InputCommon/ControllerInterface/CemuHookUDPServer/CemuHookUDPServer.h
+++ b/Source/Core/InputCommon/ControllerInterface/CemuHookUDPServer/CemuHookUDPServer.h
@@ -2,10 +2,18 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
+#include "Common/Config/Config.h"
+
namespace ciface::CemuHookUDPServer
{
+namespace Settings
+{
+extern const Config::ConfigInfo<bool> SERVER_ENABLED;
+extern const Config::ConfigInfo<std::string> SERVER_ADDRESS;
+extern const Config::ConfigInfo<int> SERVER_PORT;
+} // namespace Settings
+
void Init();
void PopulateDevices();
void DeInit();
-void SaveSettings();
} // namespace ciface::CemuHookUDPServer