Uglify. Ignore 80 column rule without going too far past.

Use inline functions instead of the two macros. No other nonspacing changes.
This commit is contained in:
Steve Checkoway
2005-10-16 23:09:00 +00:00
parent df7405f4ec
commit 849980cf74
2 changed files with 190 additions and 247 deletions
@@ -32,10 +32,15 @@ static inline void PrintIOErr(IOReturn err, const char *s)
LOG->Warn( "%s - %s(%x,%d)", s, mach_error_string(err), err, err & 0xFFFFFF );
}
// These gets absurdly long
#define DictValue(d, k) CFDictionaryGetValue(d, CFSTR(k))
#define IntValue(o, n) \
CFNumberGetValue(CFNumberRef(o), kCFNumberIntType, n)
static inline CFTypeRef DictValue( CFDictionaryRef d, const char *k )
{
return CFDictionaryGetValue( d, k );
}
static inline int IntValue( const void *o, int *n )
{
return CFNumberGetValue( CFNumberRef(o), kCFNumberIntType, n );
}
/* This is just awful, these aren't objects, treating them as such leads
* to: (*object)->function(object [, argument]...)
@@ -87,21 +92,17 @@ public:
inline const CString& GetDescription() const { return mDescription; }
};
JoystickDevice::JoystickDevice() : mInterface(NULL), mQueue(NULL),
mRunning(false)
JoystickDevice::JoystickDevice() : mInterface(NULL), mQueue(NULL), mRunning(false)
{
}
bool JoystickDevice::Open(io_object_t device, int num,
InputHandler_Carbon *handler)
bool JoystickDevice::Open( io_object_t device, int num, InputHandler_Carbon *handler )
{
IOReturn ret;
CFMutableDictionaryRef properties;
kern_return_t result;
result = IORegistryEntryCreateCFProperties(device, &properties,
kCFAllocatorDefault,
kNilOptions);
result = IORegistryEntryCreateCFProperties( device, &properties, kCFAllocatorDefault, kNilOptions );
if ( result != KERN_SUCCESS || !properties )
{
LOG->Warn( "Couldn't get properties." );
@@ -128,14 +129,11 @@ bool JoystickDevice::Open(io_object_t device, int num,
// Create the interface
IOCFPlugInInterface **plugInInterface;
// Ugh. HRESULT an awful return type
HRESULT hresult;
SInt32 score;
ret = IOCreatePlugInInterfaceForService(device,
kIOHIDDeviceUserClientTypeID,
kIOCFPlugInInterfaceID,
&plugInInterface, &score);
ret = IOCreatePlugInInterfaceForService( device, kIOHIDDeviceUserClientTypeID,
kIOCFPlugInInterfaceID, &plugInInterface, &score );
if( ret != kIOReturnSuccess )
{
PrintIOErr( ret, "Failed to create plugin interface." );
@@ -145,8 +143,7 @@ bool JoystickDevice::Open(io_object_t device, int num,
// Call a method of the plugin to create the device interface
CFUUIDBytes bytes = CFUUIDGetUUIDBytes( kIOHIDDeviceInterfaceID );
hresult = CALL(plugInInterface, QueryInterface, bytes,
(void **)&mInterface);
hresult = CALL( plugInInterface, QueryInterface, bytes, (void **)&mInterface );
CALL( plugInInterface, Release );
@@ -183,8 +180,7 @@ bool JoystickDevice::Open(io_object_t device, int num,
}
// Add elements to the queue for each Joystick
for (vector<Joystick>::const_iterator i = mSticks.begin();
i != mSticks.end(); ++i)
for( vector<Joystick>::const_iterator i = mSticks.begin(); i != mSticks.end(); ++i )
{
const Joystick& js = *i;
@@ -195,12 +191,9 @@ bool JoystickDevice::Open(io_object_t device, int num,
if( js.z_axis )
CALL( mQueue, addElement, IOHIDElementCookie(js.z_axis), 0 );
for (hash_map<int, int>::const_iterator j = js.mapping.begin();
j != js.mapping.end(); ++j)
{
for( hash_map<int, int>::const_iterator j = js.mapping.begin(); j != js.mapping.end(); ++j)
CALL( mQueue, addElement, IOHIDElementCookie(j->first), 0 );
}
}
// add the callback
CFRunLoopSourceRef runLoopSource;
@@ -216,15 +209,10 @@ bool JoystickDevice::Open(io_object_t device, int num,
runLoop = CFRunLoopRef( GetCFRunLoopFromEventLoop(GetMainEventLoop()) );
if (!CFRunLoopContainsSource(runLoop, runLoopSource,
kCFRunLoopDefaultMode))
{
CFRunLoopAddSource(runLoop, runLoopSource,
kCFRunLoopDefaultMode);
}
if( !CFRunLoopContainsSource(runLoop, runLoopSource, kCFRunLoopDefaultMode) )
CFRunLoopAddSource( runLoop, runLoopSource, kCFRunLoopDefaultMode );
CALL(mQueue, setEventCallout, InputHandler_Carbon::QueueCallBack,
handler, (void *)num);
CALL( mQueue, setEventCallout, InputHandler_Carbon::QueueCallBack, handler, (void *)num );
if( ret != kIOReturnSuccess )
{
@@ -258,12 +246,8 @@ JoystickDevice::~JoystickDevice()
ref = CFRunLoopRef( GetCFRunLoopFromEventLoop(GetMainEventLoop()) );
if (CFRunLoopContainsSource(ref, runLoopSource,
kCFRunLoopDefaultMode))
{
CFRunLoopRemoveSource(ref, runLoopSource,
kCFRunLoopDefaultMode);
}
if( CFRunLoopContainsSource(ref, runLoopSource, kCFRunLoopDefaultMode) )
CFRunLoopRemoveSource( ref, runLoopSource, kCFRunLoopDefaultMode );
CFRelease( runLoopSource );
}
@@ -291,25 +275,16 @@ void JoystickDevice::AddJoystick(const void *value, void *context)
// Get usage page
object = DictValue( dict, kIOHIDElementUsagePageKey );
if (!object || CFGetTypeID(object) != numID ||
!IntValue(object, &usagePage))
{
if( !object || CFGetTypeID(object) != numID || !IntValue(object, &usagePage) )
return;
}
// Get usage
object = DictValue( dict, kIOHIDElementUsageKey );
if (!object || CFGetTypeID(object) != numID ||
!IntValue(object, &usage))
{
if( !object || CFGetTypeID(object) != numID || !IntValue(object, &usage) )
return;
}
if (usagePage != kHIDPage_GenericDesktop ||
usage != kHIDUsage_GD_Joystick)
{
if( usagePage != kHIDPage_GenericDesktop || usage != kHIDUsage_GD_Joystick )
return;
}
if( !(elements = (CFArrayRef)DictValue(dict, kIOHIDElementKey)) )
return;
@@ -324,11 +299,8 @@ void JoystickDevice::AddJoystick(const void *value, void *context)
int JoystickDevice::AssignJoystickIDs( int startID )
{
for (vector<Joystick>::iterator i = mSticks.begin();
i != mSticks.end(); ++i)
{
for( vector<Joystick>::iterator i = mSticks.begin(); i != mSticks.end(); ++i )
i->id = InputDevice( startID++ );
}
return mSticks.size();
}
@@ -355,28 +327,19 @@ static void AddElement(const void *value, void *context)
// Get usage page
object = DictValue( dict, kIOHIDElementUsagePageKey );
if (!object || CFGetTypeID(object) != numID ||
!IntValue(object, &usagePage))
{
if( !object || CFGetTypeID(object) != numID || !IntValue(object, &usagePage) )
return;
}
// Get usage
object = DictValue( dict, kIOHIDElementUsageKey );
if (!object || CFGetTypeID(object) != numID ||
!IntValue(object, &usage))
{
if( !object || CFGetTypeID(object) != numID || !IntValue(object, &usage) )
return;
}
// Get cookie
object = DictValue( dict, kIOHIDElementCookieKey );
if (!object || CFGetTypeID(object) != numID ||
!IntValue(object, &cookie))
{
if( !object || CFGetTypeID(object) != numID || !IntValue(object, &cookie) )
return;
}
switch( usagePage )
{
@@ -442,8 +405,7 @@ static void AddElement(const void *value, void *context)
} // end switch (usagePage)
}
void InputHandler_Carbon::QueueCallBack(void *target, int result,
void *refcon, void *sender)
void InputHandler_Carbon::QueueCallBack( void *target, int result, void *refcon, void *sender )
{
// The result seems useless as you can't actually return anything...
// refcon is the JoystickDevice number
@@ -455,8 +417,7 @@ void InputHandler_Carbon::QueueCallBack(void *target, int result,
AbsoluteTime zeroTime = { 0, 0 };
JoystickDevice *jd = This->mDevices[int( refcon )];
while ((result = CALL(queue, getNextEvent, &event, zeroTime, 0))
== kIOReturnSuccess)
while( (result = CALL(queue, getNextEvent, &event, zeroTime, 0)) == kIOReturnSuccess )
{
int cookie = int( event.elementCookie );
int value = event.value;
@@ -500,8 +461,7 @@ void InputHandler_Carbon::QueueCallBack(void *target, int result,
iter = js.mapping.find( cookie );
if( iter != js.mapping.end() )
{
LOG->Trace("(%d) Button %d: %s\n", int(js.id),
iter->second, (value ? "down" : "up"));
LOG->Trace( "(%d) Button %d: %s\n", int(js.id), iter->second, (value ? "down" : "up") );
This->ButtonPressed( DeviceInput(js.id, iter->second, value, now), value );
break;
}
@@ -510,18 +470,15 @@ void InputHandler_Carbon::QueueCallBack(void *target, int result,
}
}
OSStatus InputHandler_Carbon::EventHandler(EventHandlerCallRef callRef,
EventRef event, void *data)
OSStatus InputHandler_Carbon::EventHandler( EventHandlerCallRef callRef, EventRef event, void *data )
{
InputHandler_Carbon *This = (InputHandler_Carbon *)data;
UInt32 kind = GetEventKind(event);
UInt32 keyCode;
char charCode;
GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL,
sizeof(keyCode), NULL, &keyCode);
GetEventParameter(event, kEventParamKeyMacCharCodes, typeChar, NULL,
sizeof(charCode), NULL, &charCode);
GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(keyCode), NULL, &keyCode );
GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(charCode), NULL, &charCode );
const char *type;
@@ -545,11 +502,8 @@ OSStatus InputHandler_Carbon::EventHandler(EventHandlerCallRef callRef,
InputHandler_Carbon::~InputHandler_Carbon()
{
for (vector<JoystickDevice *>::iterator i = mDevices.begin();
i != mDevices.end(); ++i)
{
for( vector<JoystickDevice *>::iterator i = mDevices.begin(); i != mDevices.end(); ++i)
delete *i;
}
if( mMasterPort )
mach_port_deallocate( mach_task_self(), mMasterPort );
RemoveEventHandler( mEventHandlerRef );
@@ -566,11 +520,8 @@ InputHandler_Carbon::InputHandler_Carbon()
{ kEventClassKeyboard, kEventRawKeyUp } };
if (InstallEventHandler(GetApplicationEventTarget(), mEventHandlerUPP,
3, typeList, this, &mEventHandlerRef))
{
if( InstallEventHandler(GetApplicationEventTarget(), mEventHandlerUPP, 3, typeList, this, &mEventHandlerRef) )
LOG->Warn("Failed to install the Event Handler.");
}
// Get a Mach port to initiate communication with I/O Kit.
mach_port_t masterPort;
@@ -597,10 +548,9 @@ InputHandler_Carbon::InputHandler_Carbon()
CFNumberRef usagePage = CFInt( kHIDPage_GenericDesktop );
CFNumberRef usage = CFInt( kHIDUsage_GD_Joystick );
CFDictionarySetValue(dict, CFSTR(kIOHIDPrimaryUsagePageKey),
usagePage);
CFDictionarySetValue(dict, CFSTR(kIOHIDPrimaryUsageKey),
usage);
CFDictionarySetValue( dict, CFSTR(kIOHIDPrimaryUsagePageKey), usagePage );
CFDictionarySetValue( dict, CFSTR(kIOHIDPrimaryUsageKey), usage);
// Cleanup after ourselves
CFRelease(usagePage);
CFRelease(usage);
@@ -608,7 +558,6 @@ InputHandler_Carbon::InputHandler_Carbon()
// Find the HID devices.
io_iterator_t iter;
/* Get an iterator to the matching devies
* This consumes a reference to the dictionary so we don't
* have to Release() later.
@@ -636,7 +585,9 @@ InputHandler_Carbon::InputHandler_Carbon()
puts( "Added device." );
}
else
{
delete jd;
}
IOObjectRelease( device );
@@ -644,11 +595,9 @@ InputHandler_Carbon::InputHandler_Carbon()
IOObjectRelease( iter );
}
void InputHandler_Carbon::GetDevicesAndDescriptions(vector<InputDevice>& dev,
vector<CString>& desc)
void InputHandler_Carbon::GetDevicesAndDescriptions( vector<InputDevice>& dev, vector<CString>& desc )
{
for (vector<JoystickDevice *>::const_iterator i = mDevices.begin();
i != mDevices.end(); ++i)
for( vector<JoystickDevice *>::const_iterator i = mDevices.begin(); i != mDevices.end(); ++i )
{
const JoystickDevice *jd = *i;
@@ -10,11 +10,7 @@ typedef struct OpaqueEventRef *EventRef;
typedef struct OpaqueEventHandlerRef *EventHandlerRef;
typedef struct OpaqueEventTargetRef *EventTargetRef;
typedef long int OSStatus;
typedef OSStatus (*EventHandlerProcPtr) (
EventHandlerCallRef inHandlerCallRef,
EventRef inEvent,
void *inUserData
);
typedef OSStatus (*EventHandlerProcPtr) ( EventHandlerCallRef, EventRef, void * );
typedef EventHandlerProcPtr EventHandlerUPP;
class JoystickDevice;
@@ -34,10 +30,8 @@ public:
void GetDevicesAndDescriptions( vector<InputDevice>& vDevicesOut,
vector<CString>& vDescriptionsOut );
static void QueueCallBack(void *target, int result,
void *refcon, void *sender);
static OSStatus EventHandler(EventHandlerCallRef callRef, EventRef event,
void *data);
static void QueueCallBack( void *target, int result, void *refcon, void *sender );
static OSStatus EventHandler( EventHandlerCallRef callRef, EventRef event, void *data );
};
#define USE_INPUT_HANDLER_CARBON