Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 5 additions & 36 deletions Source/WindowsDualsense_ds5w/Private/Core/DeviceRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "Core/DeviceRegistry.h"
#include "Async/Async.h"
#include "Async/TaskGraphInterfaces.h"
#include "Core/HIDPollingRunnable.h"
#include "Core/HIDDeviceInfo.h"
#include "Windows/WindowsApplication.h"
#include "Core/DualSense/DualSenseLibrary.h"
Expand All @@ -21,7 +20,6 @@ TSharedPtr<FDeviceRegistry> FDeviceRegistry::Instance;
TMap<FString, FInputDeviceId> FDeviceRegistry::KnownDevicePaths;
TMap<FString, FInputDeviceId> FDeviceRegistry::HistoryDevices;
TMap<FInputDeviceId, ISonyGamepadInterface*> FDeviceRegistry::LibraryInstances;
TMap<int32, TUniquePtr<FHIDPollingRunnable>> FDeviceRegistry::ActiveConnectionWatchers;

bool PrimaryTick = true;
float AccumulateSecurity = 0;
Expand Down Expand Up @@ -80,7 +78,7 @@ void FDeviceRegistry::DetectedChangeConnections(float DeltaTime)
{
IPlatformInputDeviceMapper::Get().Internal_SetInputDeviceConnectionState(DeviceId, EInputDeviceConnectionState::Disconnected);

Manager->RemoveLibraryInstance(DeviceId.GetId());
Manager->RemoveLibraryInstance(DeviceId);
DisconnectedPaths.Add(Path);
}
}
Expand Down Expand Up @@ -127,10 +125,10 @@ TSharedPtr<FDeviceRegistry> FDeviceRegistry::Get()

FDeviceRegistry::~FDeviceRegistry()
{
TArray<int32> WatcherKeys;
ActiveConnectionWatchers.GetKeys(WatcherKeys);
TArray<FInputDeviceId> WatcherKeys;
LibraryInstances.GetKeys(WatcherKeys);

for (const int32 ControllerId : WatcherKeys)
for (const FInputDeviceId& ControllerId : WatcherKeys)
{
RemoveLibraryInstance(ControllerId);
}
Expand All @@ -150,9 +148,8 @@ ISonyGamepadInterface* FDeviceRegistry::GetLibraryInstance(const FInputDeviceId&
return LibraryInstances[DeviceId];
}

void FDeviceRegistry::RemoveLibraryInstance(int32 ControllerId)
void FDeviceRegistry::RemoveLibraryInstance(const FInputDeviceId& GamepadId)
{
FInputDeviceId GamepadId = FInputDeviceId::CreateFromInternalId(ControllerId);
if (
IPlatformInputDeviceMapper::Get().GetInputDeviceConnectionState(GamepadId) !=
EInputDeviceConnectionState::Disconnected)
Expand All @@ -168,8 +165,6 @@ void FDeviceRegistry::RemoveLibraryInstance(int32 ControllerId)

LibraryInstances[GamepadId]->ShutdownLibrary();
LibraryInstances.Remove(GamepadId);

const int32 NumRemoved = ActiveConnectionWatchers.Remove(ControllerId);
}

void FDeviceRegistry::CreateLibraryInstance(FDeviceContext& Context)
Expand Down Expand Up @@ -243,34 +238,8 @@ void FDeviceRegistry::CreateLibraryInstance(FDeviceContext& Context)
UserId,
EInputDeviceConnectionState::Connected);
}


if (ActiveConnectionWatchers.Contains(Context.UniqueInputDeviceId.GetId()))
{
ActiveConnectionWatchers.Remove(Context.UniqueInputDeviceId.GetId());
}

auto WatcherRunnable = MakeUnique<FHIDPollingRunnable>(
MoveTemp(Context.Handle),
std::chrono::milliseconds(150)
);
if (WatcherRunnable)
{
WatcherRunnable->StartThread();
ActiveConnectionWatchers.Add(Context.UniqueInputDeviceId.GetId(), MoveTemp(WatcherRunnable));
}
}

void FDeviceRegistry::RemoveAllLibraryInstance()
{
for (const auto& LibraryInstance : LibraryInstances)
{
RemoveLibraryInstance(LibraryInstance.Key.GetId());
}
LibraryInstances.Reset();
}


int32 FDeviceRegistry::GetAllocatedDevices()
{
return LibraryInstances.Num();
Expand Down
76 changes: 0 additions & 76 deletions Source/WindowsDualsense_ds5w/Private/Core/HIDPollingRunnable.cpp

This file was deleted.

14 changes: 3 additions & 11 deletions Source/WindowsDualsense_ds5w/Public/Core/DeviceRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "CoreMinimal.h"
#include "Windows/WindowsApplication.h"
#include "Async/TaskGraphInterfaces.h"
#include "Core/HIDPollingRunnable.h"
#include "HAL/PlatformProcess.h"
#include "HAL/RunnableThread.h"
#include "Interfaces/SonyGamepadInterface.h"
Expand All @@ -31,8 +30,7 @@ class WINDOWSDUALSENSE_DS5W_API FDeviceRegistry : public TSharedFromThis<FDevice
static TSharedPtr<FDeviceRegistry> Get();
/**
* Destructor for the FDeviceRegistry class. Responsible for cleaning up resources associated with the device
* library instances. Ensures that all active connection watchers are properly removed and their corresponding
* controller instances are cleaned up to prevent resource leakage.
* library instances. Ensures that all controller instances are cleaned up to prevent resource leakage.
*/
virtual ~FDeviceRegistry();
/**
Expand Down Expand Up @@ -73,9 +71,9 @@ class WINDOWSDUALSENSE_DS5W_API FDeviceRegistry : public TSharedFromThis<FDevice
* corresponding input device if it is currently connected. Ensures proper removal and cleanup
* of the library instance from the internal container.
*
* @param ControllerId The unique identifier of the controller whose library instance is to be removed.
* @param GamepadId The unique identifier of the controller whose library instance is to be removed.
*/
void RemoveLibraryInstance(int32 ControllerId);
void RemoveLibraryInstance(const FInputDeviceId& GamepadId);
/**
* Creates an instance of a device library based on the provided device context. It initializes and
* manages the lifecycle of the Sony gamepad library for controllers like DualSense, DualSense Edge,
Expand Down Expand Up @@ -133,10 +131,4 @@ class WINDOWSDUALSENSE_DS5W_API FDeviceRegistry : public TSharedFromThis<FDevice
* within the system, enabling efficient querying and management of device-user relationships.
*/
static TMap<FString, FInputDeviceId> HistoryDevices;
/**
* A static map that maintains active connections by associating unique integer identifiers with their
* corresponding HID polling runnable instances. This map is used to manage and monitor ongoing input
* device connection activities and ensures proper lifecycle control of the associated polling threads.
*/
static TMap<int32, TUniquePtr<FHIDPollingRunnable>> ActiveConnectionWatchers;
};
170 changes: 0 additions & 170 deletions Source/WindowsDualsense_ds5w/Public/Core/HIDPollingRunnable.h

This file was deleted.