ControllerInterface: Switch to std::shared_ptr

Small cleanup by using std::shared_ptr and getting rid of
ciface.Devices() which just returned the m_devices (which defeats the
point of making m_devices protected).

Incidentally, this should make the code safer when we have
different threads accessing devices in the future (for hotplug?).

A lot of code use Device references directly so there is
no easy way to remove FindDevice() and make those unique_ptrs.
This commit is contained in:
Léo Lam
2016-06-25 21:46:39 +02:00
parent afa202738e
commit 8678133e87
18 changed files with 80 additions and 60 deletions

View File

@ -144,7 +144,7 @@ static void DeviceMatching_callback(void* inContext, IOReturn inResult, void* in
// Add a device if it's of a type we want
if (IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard))
g_controller_interface.AddDevice(
new Keyboard(inIOHIDDeviceRef, name, kbd_name_counts[name]++, g_window));
std::make_shared<Keyboard>(inIOHIDDeviceRef, name, kbd_name_counts[name]++, g_window));
#if 0
else if (IOHIDDeviceConformsTo(inIOHIDDeviceRef,
kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse))
@ -152,7 +152,8 @@ static void DeviceMatching_callback(void* inContext, IOReturn inResult, void* in
name, mouse_name_counts[name]++));
#endif
else
g_controller_interface.AddDevice(new Joystick(inIOHIDDeviceRef, name, joy_name_counts[name]++));
g_controller_interface.AddDevice(
std::make_shared<Joystick>(inIOHIDDeviceRef, name, joy_name_counts[name]++));
}
void Init(void* window)