Return owning pointer type

This commit is contained in:
Chris Thrasher 2024-09-16 17:53:43 -04:00
parent 119ea42e0a
commit e432237b5d
No known key found for this signature in database
GPG Key ID: 56FB686C9DFC8E2C
3 changed files with 9 additions and 13 deletions

View File

@ -94,7 +94,7 @@ public:
/// \return a retained CFDictionaryRef
///
////////////////////////////////////////////////////////////
static CFDictionaryRef copyDevicesMask(std::uint32_t page, std::uint32_t usage);
static CFPtr<CFDictionaryRef> copyDevicesMask(std::uint32_t page, std::uint32_t usage);
////////////////////////////////////////////////////////////
/// \brief Try to convert a character into a SFML key code

View File

@ -69,21 +69,19 @@ long HIDInputManager::getLocationID(IOHIDDeviceRef device)
////////////////////////////////////////////////////////////
CFDictionaryRef HIDInputManager::copyDevicesMask(std::uint32_t page, std::uint32_t usage)
CFPtr<CFDictionaryRef> HIDInputManager::copyDevicesMask(std::uint32_t page, std::uint32_t usage)
{
// Create the dictionary.
CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorDefault,
2,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
auto dict = CFPtr<CFMutableDictionaryRef>(
CFDictionaryCreateMutable(kCFAllocatorDefault, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
// Add the page value.
auto value = CFPtr<CFNumberRef>(CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &page));
CFDictionarySetValue(dict, CFSTR(kIOHIDDeviceUsagePageKey), value.get());
CFDictionarySetValue(dict.get(), CFSTR(kIOHIDDeviceUsagePageKey), value.get());
// Add the usage value (which is only valid if page value exists).
value = CFPtr<CFNumberRef>(CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage));
CFDictionarySetValue(dict, CFSTR(kIOHIDDeviceUsageKey), value.get());
CFDictionarySetValue(dict.get(), CFSTR(kIOHIDDeviceUsageKey), value.get());
return dict;
}
@ -929,7 +927,7 @@ void HIDInputManager::freeUp()
CFPtr<CFSetRef> HIDInputManager::copyDevices(std::uint32_t page, std::uint32_t usage)
{
// Filter and keep only the requested devices
const auto mask = CFPtr<CFDictionaryRef>(copyDevicesMask(page, usage));
const auto mask = copyDevicesMask(page, usage);
IOHIDManagerSetDeviceMatching(m_manager.get(), mask.get());

View File

@ -72,11 +72,9 @@ HIDJoystickManager::HIDJoystickManager()
{
m_manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
const auto mask0 = CFPtr<CFDictionaryRef>(
HIDInputManager::copyDevicesMask(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick));
const auto mask0 = HIDInputManager::copyDevicesMask(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick);
const auto mask1 = CFPtr<CFDictionaryRef>(
HIDInputManager::copyDevicesMask(kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad));
const auto mask1 = HIDInputManager::copyDevicesMask(kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad);
std::array maskArray = {mask0.get(), mask1.get()};
const auto mask = CFPtr<CFArrayRef>(