From 5e7ea06c5feb517e42dca251880abd3715993a33 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Sun, 5 Oct 2008 08:25:31 +0000 Subject: [PATCH] Use IOHIDElementCookie which is really a void* rather than int. --- .../InputHandler/InputHandler_MacOSX_HID.cpp | 4 +-- stepmania/src/archutils/Darwin/HIDDevice.cpp | 7 +++-- stepmania/src/archutils/Darwin/HIDDevice.h | 30 +++++++++++++++---- .../src/archutils/Darwin/JoystickDevice.cpp | 8 ++--- .../src/archutils/Darwin/JoystickDevice.h | 22 +++++++------- .../src/archutils/Darwin/KeyboardDevice.cpp | 8 ++--- .../src/archutils/Darwin/KeyboardDevice.h | 7 ++--- stepmania/src/archutils/Darwin/PumpDevice.cpp | 16 +++++----- stepmania/src/archutils/Darwin/PumpDevice.h | 4 +-- 9 files changed, 63 insertions(+), 43 deletions(-) diff --git a/stepmania/src/arch/InputHandler/InputHandler_MacOSX_HID.cpp b/stepmania/src/arch/InputHandler/InputHandler_MacOSX_HID.cpp index 096646d423..55087e40cb 100644 --- a/stepmania/src/arch/InputHandler/InputHandler_MacOSX_HID.cpp +++ b/stepmania/src/arch/InputHandler/InputHandler_MacOSX_HID.cpp @@ -27,9 +27,9 @@ void InputHandler_MacOSX_HID::QueueCallBack( void *target, int result, void *ref HIDDevice *dev = This->m_vDevices[int( refcon )]; vector vPresses; - LOG->Trace( "Got event with cookie %d, value %d", int(event.elementCookie), int(event.value) ); + LOG->Trace( "Got event with cookie %p, value %d", event.elementCookie, int(event.value) ); while( (result = CALL(queue, getNextEvent, &event, zeroTime, 0)) == kIOReturnSuccess ) - dev->GetButtonPresses( vPresses, int(event.elementCookie), int(event.value), now ); + dev->GetButtonPresses( vPresses, event.elementCookie, event.value, now ); FOREACH_CONST( DeviceInput, vPresses, i ) INPUTFILTER->ButtonPressed( *i ); } diff --git a/stepmania/src/archutils/Darwin/HIDDevice.cpp b/stepmania/src/archutils/Darwin/HIDDevice.cpp index e272da1996..2fa92e56a2 100644 --- a/stepmania/src/archutils/Darwin/HIDDevice.cpp +++ b/stepmania/src/archutils/Darwin/HIDDevice.cpp @@ -223,7 +223,8 @@ void HIDDevice::AddElement( const void *value, void *context ) CFDictionaryRef properties = CFDictionaryRef( value ); HIDDevice *This = (HIDDevice *)context; CFTypeRef object; - int cookie, usage, usagePage; + int usage, usagePage; + long cookie; // Recursively add elements object = CFDictionaryGetValue( properties, CFSTR(kIOHIDElementKey) ); @@ -248,9 +249,9 @@ void HIDDevice::AddElement( const void *value, void *context ) // Get cookie object = CFDictionaryGetValue( properties, CFSTR(kIOHIDElementCookieKey) ); - if( !IntValue(object, cookie) ) + if( !LongValue(object, cookie) ) return; - This->AddElement( usagePage, usage, cookie, properties ); + This->AddElement( usagePage, usage, IOHIDElementCookie(cookie), properties ); } /* diff --git a/stepmania/src/archutils/Darwin/HIDDevice.h b/stepmania/src/archutils/Darwin/HIDDevice.h index 33c267e782..72690a31ac 100644 --- a/stepmania/src/archutils/Darwin/HIDDevice.h +++ b/stepmania/src/archutils/Darwin/HIDDevice.h @@ -11,6 +11,7 @@ #include #include #include +#include #include "RageLog.h" #include "RageInputDevice.h" @@ -35,6 +36,25 @@ inline Boolean IntValue( CFTypeRef o, int &n ) return CFNumberGetValue( CFNumberRef(o), kCFNumberIntType, &n ); } +inline Boolean LongValue( CFTypeRef o, long &n ) +{ + if( !o || CFGetTypeID(o) != CFNumberGetTypeID() ) + return false; + return CFNumberGetValue( CFNumberRef(o), kCFNumberLongType, &n ); +} + +namespace __gnu_cxx +{ + template<> + struct hash : private hash + { + size_t operator()( const IOHIDElementCookie& cookie ) const + { + return hash::operator()( uintptr_t(cookie) ); + } + }; +} + /* * This is just awful, these aren't objects, treating them as such leads * to: (*object)->function(object [, argument]...) @@ -65,7 +85,7 @@ protected: * If the most recently added logical device cares about the state of an element of type * (usagePage, usage), store the cookie. */ - virtual void AddElement( int usagePage, int usage, int cookie, const CFDictionaryRef properties ) = 0; + virtual void AddElement( int usagePage, int usage, IOHIDElementCookie cookie, const CFDictionaryRef properties ) = 0; /* * Add any elements to the queue by calling AddElementToQueue() with the stored cookies. @@ -78,11 +98,11 @@ protected: virtual bool InitDevice( int vid, int pid ) { return true; } // This adds the element with the given cookie to the queue to be notified of state changes. - inline void AddElementToQueue( int cookie ) + inline void AddElementToQueue( IOHIDElementCookie cookie ) { - IOReturn ret = CALL( m_Queue, addElement, IOHIDElementCookie(cookie), 0 ); + IOReturn ret = CALL( m_Queue, addElement, cookie, 0 ); if( ret != KERN_SUCCESS ) - LOG->Warn( "Failed to add HID element with cookie %d to queue: %d", cookie, ret ); + LOG->Warn( "Failed to add HID element with cookie %p to queue: %u", cookie, ret ); } // Perform a synchronous set report on the HID interface. @@ -105,7 +125,7 @@ public: * The value of the element is passed to determine if this is a push or a release. The time * is provided as an optimization. */ - virtual void GetButtonPresses( vector& vPresses, int cookie, int value, const RageTimer& now ) const = 0; + virtual void GetButtonPresses( vector& vPresses, IOHIDElementCookie cookie, int value, const RageTimer& now ) const = 0; /* * Returns the number of IDs assigned starting from startID. This is not meaningful for devices like diff --git a/stepmania/src/archutils/Darwin/JoystickDevice.cpp b/stepmania/src/archutils/Darwin/JoystickDevice.cpp index 9ab8214377..95b9a9bb38 100644 --- a/stepmania/src/archutils/Darwin/JoystickDevice.cpp +++ b/stepmania/src/archutils/Darwin/JoystickDevice.cpp @@ -33,7 +33,7 @@ bool JoystickDevice::AddLogicalDevice( int usagePage, int usage ) return true; } -void JoystickDevice::AddElement( int usagePage, int usage, int cookie, const CFDictionaryRef properties ) +void JoystickDevice::AddElement( int usagePage, int usage, IOHIDElementCookie cookie, const CFDictionaryRef properties ) { if( usagePage >= kHIDPage_VendorDefinedStart ) return; @@ -137,7 +137,7 @@ void JoystickDevice::Open() ADD( x_rot ); ADD( y_rot ); ADD( z_rot ); ADD( hat ); #undef ADD - for( hash_map::const_iterator j = js.mapping.begin(); j != js.mapping.end(); ++j ) + for( hash_map::const_iterator j = js.mapping.begin(); j != js.mapping.end(); ++j ) AddElementToQueue( j->first ); } } @@ -155,7 +155,7 @@ bool JoystickDevice::InitDevice( int vid, int pid ) return ret == kIOReturnSuccess; } -void JoystickDevice::GetButtonPresses( vector& vPresses, int cookie, int value, const RageTimer& now ) const +void JoystickDevice::GetButtonPresses( vector& vPresses, IOHIDElementCookie cookie, int value, const RageTimer& now ) const { FOREACH_CONST( Joystick, m_vSticks, i ) { @@ -236,7 +236,7 @@ void JoystickDevice::GetButtonPresses( vector& vPresses, int cookie else { // hash_map::operator[] is not const - hash_map::const_iterator iter; + hash_map::const_iterator iter; iter = js.mapping.find( cookie ); if( iter != js.mapping.end() ) diff --git a/stepmania/src/archutils/Darwin/JoystickDevice.h b/stepmania/src/archutils/Darwin/JoystickDevice.h index e82852c38b..df5d6323c9 100644 --- a/stepmania/src/archutils/Darwin/JoystickDevice.h +++ b/stepmania/src/archutils/Darwin/JoystickDevice.h @@ -2,20 +2,20 @@ #define JOYSTICK_DEVICE_H #include "HIDDevice.h" -#include struct Joystick { InputDevice id; // map cookie to button - __gnu_cxx::hash_map mapping; - int x_axis, x_min, x_max; - int y_axis, y_min, y_max; - int z_axis, z_min, z_max; - int x_rot, rx_min, rx_max; - int y_rot, ry_min, ry_max; - int z_rot, rz_min, rz_max; - int hat, hat_min, hat_max; + __gnu_cxx::hash_map mapping; + IOHIDElementCookie x_axis, y_axis, z_axis, x_rot, y_rot, z_rot, hat; + int x_min, x_max; + int y_min, y_max; + int z_min, z_max; + int rx_min, rx_max; + int ry_min, ry_max; + int rz_min, rz_max; + int hat_min, hat_max; Joystick(); }; @@ -27,12 +27,12 @@ private: protected: bool AddLogicalDevice( int usagePage, int usage ); - void AddElement( int usagePage, int usage, int cookie, const CFDictionaryRef properties ); + void AddElement( int usagePage, int usage, IOHIDElementCookie cookie, const CFDictionaryRef properties ); void Open(); bool InitDevice( int vid, int pid ); public: - void GetButtonPresses( vector& vPresses, int cookie, int value, const RageTimer& now ) const; + void GetButtonPresses( vector& vPresses, IOHIDElementCookie cookie, int value, const RageTimer& now ) const; int AssignIDs( InputDevice startID ); void GetDevicesAndDescriptions( vector& vDevices ) const; }; diff --git a/stepmania/src/archutils/Darwin/KeyboardDevice.cpp b/stepmania/src/archutils/Darwin/KeyboardDevice.cpp index 903cc14368..dfccd35d2c 100644 --- a/stepmania/src/archutils/Darwin/KeyboardDevice.cpp +++ b/stepmania/src/archutils/Darwin/KeyboardDevice.cpp @@ -150,7 +150,7 @@ static bool UsbKeyToDeviceButton( UInt8 iUsbKey, DeviceButton &buttonOut ) return false; } -void KeyboardDevice::AddElement( int usagePage, int usage, int cookie, const CFDictionaryRef properties ) +void KeyboardDevice::AddElement( int usagePage, int usage, IOHIDElementCookie cookie, const CFDictionaryRef properties ) { if( usagePage != kHIDPage_KeyboardOrKeypad ) return; @@ -162,13 +162,13 @@ void KeyboardDevice::AddElement( int usagePage, int usage, int cookie, const CFD void KeyboardDevice::Open() { - for( hash_map::const_iterator i = m_Mapping.begin(); i != m_Mapping.end(); ++i ) + for( hash_map::const_iterator i = m_Mapping.begin(); i != m_Mapping.end(); ++i ) AddElementToQueue( i->first ); } -void KeyboardDevice::GetButtonPresses( vector& vPresses, int cookie, int value, const RageTimer& now ) const +void KeyboardDevice::GetButtonPresses( vector& vPresses, IOHIDElementCookie cookie, int value, const RageTimer& now ) const { - hash_map::const_iterator iter = m_Mapping.find( cookie ); + hash_map::const_iterator iter = m_Mapping.find( cookie ); if( iter != m_Mapping.end() ) { diff --git a/stepmania/src/archutils/Darwin/KeyboardDevice.h b/stepmania/src/archutils/Darwin/KeyboardDevice.h index fee61e0480..f70a184b24 100644 --- a/stepmania/src/archutils/Darwin/KeyboardDevice.h +++ b/stepmania/src/archutils/Darwin/KeyboardDevice.h @@ -2,20 +2,19 @@ #define KEYBOARD_DEVICE_H #include "HIDDevice.h" -#include class KeyboardDevice : public HIDDevice { private: - __gnu_cxx::hash_map m_Mapping; + __gnu_cxx::hash_map m_Mapping; protected: bool AddLogicalDevice( int usagePage, int usage ); - void AddElement( int usagePage, int usage, int cookie, const CFDictionaryRef properties ); + void AddElement( int usagePage, int usage, IOHIDElementCookie cookie, const CFDictionaryRef properties ); void Open(); public: - void GetButtonPresses( vector& vPresses, int cookie, int value, const RageTimer& now ) const; + void GetButtonPresses( vector& vPresses, IOHIDElementCookie cookie, int value, const RageTimer& now ) const; void GetDevicesAndDescriptions( vector& vDevices ) const; static bool DeviceButtonToMacVirtualKey( DeviceButton button, UInt8 &iMacVKOut ); diff --git a/stepmania/src/archutils/Darwin/PumpDevice.cpp b/stepmania/src/archutils/Darwin/PumpDevice.cpp index 16938573d3..f7044659c8 100644 --- a/stepmania/src/archutils/Darwin/PumpDevice.cpp +++ b/stepmania/src/archutils/Darwin/PumpDevice.cpp @@ -3,22 +3,22 @@ void PumpDevice::Open() { - AddElementToQueue( 2 ); - AddElementToQueue( 3 ); - AddElementToQueue( 4 ); - AddElementToQueue( 6 ); - AddElementToQueue( 7 ); - AddElementToQueue( 8 ); + AddElementToQueue( IOHIDElementCookie(2) ); + AddElementToQueue( IOHIDElementCookie(3) ); + AddElementToQueue( IOHIDElementCookie(4) ); + AddElementToQueue( IOHIDElementCookie(6) ); + AddElementToQueue( IOHIDElementCookie(7) ); + AddElementToQueue( IOHIDElementCookie(8) ); } -void PumpDevice::GetButtonPresses( vector& vPresses, int cookie, int value, const RageTimer& now ) const +void PumpDevice::GetButtonPresses( vector& vPresses, IOHIDElementCookie cookie, int value, const RageTimer& now ) const { DeviceButton db1 = DeviceButton_Invalid; DeviceButton db2 = DeviceButton_Invalid; bool pressed1 = !(value & 0x1); bool pressed2 = !(value & 0x2); - switch( cookie ) + switch( uintptr_t(cookie) ) { case 2: db2 = JOY_BUTTON_1; // bit 9 diff --git a/stepmania/src/archutils/Darwin/PumpDevice.h b/stepmania/src/archutils/Darwin/PumpDevice.h index 42f48f18f3..1f8ee03a34 100644 --- a/stepmania/src/archutils/Darwin/PumpDevice.h +++ b/stepmania/src/archutils/Darwin/PumpDevice.h @@ -10,13 +10,13 @@ private: protected: bool AddLogicalDevice( int usagePage, int usage ) { return true; } - void AddElement( int usagePage, int usage, int cookie, + void AddElement( int usagePage, int usage, IOHIDElementCookie cookie, const CFDictionaryRef properties ) { } void Open(); bool InitDevice( int vid, int pid ) { return vid == 0x0d2f && pid == 0x0001; } public: - void GetButtonPresses( vector& vPresses, int cookie, int value, const RageTimer& now ) const; + void GetButtonPresses( vector& vPresses, IOHIDElementCookie cookie, int value, const RageTimer& now ) const; int AssignIDs( InputDevice startID ); void GetDevicesAndDescriptions( vector& vDevices ) const; };