Update ControllerListener_mac.cpp to our style guidelines

This commit is contained in:
Micke Prag 2012-09-26 16:31:27 +02:00
parent bc22754f8c
commit c522173296

View file

@ -1,10 +1,17 @@
#include "ControllerListener.h" //
// Copyright (C) 2012 Telldus Technologies AB. All rights reserved.
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "service/ControllerListener.h"
#include <CoreFoundation/CoreFoundation.h> #include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h> #include <IOKit/IOKitLib.h>
#include <IOKit/IOMessage.h> #include <IOKit/IOMessage.h>
#include <IOKit/IOCFPlugIn.h> #include <IOKit/IOCFPlugIn.h>
#include <IOKit/usb/IOUSBLib.h> #include <IOKit/usb/IOUSBLib.h>
#include <string>
class TellStickData { class TellStickData {
public: public:
@ -29,8 +36,7 @@ public:
}; };
ControllerListener::ControllerListener(TelldusCore::EventRef event) ControllerListener::ControllerListener(TelldusCore::EventRef event)
:Thread() :Thread() {
{
d = new PrivateData; d = new PrivateData;
d->event = event; d->event = event;
d->running = true; d->running = true;
@ -61,8 +67,9 @@ void ControllerListener::run() {
// Race check, if destructor was called really close to thread init, // Race check, if destructor was called really close to thread init,
// running might have gone false. Make sure we don't get stuck // running might have gone false. Make sure we don't get stuck
if(d->running) if (d->running) {
CFRunLoopRun(); CFRunLoopRun();
}
} }
void ControllerListener::PrivateData::addUsbFilter(int vid, int pid) { void ControllerListener::PrivateData::addUsbFilter(int vid, int pid) {
@ -96,7 +103,6 @@ void ControllerListener::PrivateData::addUsbFilter(int vid, int pid) {
); );
// Iterate once to get already-present devices and arm the notification // Iterate once to get already-present devices and arm the notification
PrivateData::DeviceAdded(this, gAddedIter); PrivateData::DeviceAdded(this, gAddedIter);
} }
void ControllerListener::PrivateData::DeviceNotification(void *refCon, io_service_t service, natural_t messageType, void *messageArgument) { void ControllerListener::PrivateData::DeviceNotification(void *refCon, io_service_t service, natural_t messageType, void *messageArgument) {
@ -114,7 +120,7 @@ void ControllerListener::PrivateData::DeviceNotification(void *refCon, io_servic
CFIndex size = CFStringGetLength(tsd->serialNumber); CFIndex size = CFStringGetLength(tsd->serialNumber);
char *s = new char[size+1]; char *s = new char[size+1];
CFStringGetCString(tsd->serialNumber, s, size+1, kCFStringEncodingASCII); CFStringGetCString(tsd->serialNumber, s, size+1, kCFStringEncodingASCII);
std::string serial(s); //Copy the string to the stack std::string serial(s); // Copy the string to the stack
delete[] s; delete[] s;
ControllerChangeEventData *data = new ControllerChangeEventData; ControllerChangeEventData *data = new ControllerChangeEventData;
@ -144,11 +150,10 @@ void ControllerListener::PrivateData::DeviceAdded(void *refCon, io_iterator_t it
// Get the serial number // Get the serial number
CFStringRef serialRef = reinterpret_cast<CFStringRef>(IORegistryEntryCreateCFProperty( usbDevice, CFSTR("USB Serial Number" ), kCFAllocatorDefault, 0 )); CFStringRef serialRef = reinterpret_cast<CFStringRef>(IORegistryEntryCreateCFProperty( usbDevice, CFSTR("USB Serial Number" ), kCFAllocatorDefault, 0 ));
if (serialRef == NULL) { if (serialRef == NULL) {
//No serial number, we cannot continue. Sorry // No serial number, we cannot continue. Sorry
continue; continue;
} }
CFNumberRef vidRef = reinterpret_cast<CFNumberRef> (IORegistryEntryCreateCFProperty(usbDevice, CFSTR("idVendor"), kCFAllocatorDefault, 0)); CFNumberRef vidRef = reinterpret_cast<CFNumberRef> (IORegistryEntryCreateCFProperty(usbDevice, CFSTR("idVendor"), kCFAllocatorDefault, 0));
if (vidRef) { if (vidRef) {
CFNumberGetValue(vidRef, kCFNumberIntType, &(tsd->vid)); CFNumberGetValue(vidRef, kCFNumberIntType, &(tsd->vid));
@ -172,7 +177,7 @@ void ControllerListener::PrivateData::DeviceAdded(void *refCon, io_iterator_t it
CFIndex size = CFStringGetLength(serialNumberAsCFString); CFIndex size = CFStringGetLength(serialNumberAsCFString);
char *s = new char[size+1]; char *s = new char[size+1];
CFStringGetCString(serialNumberAsCFString, s, size+1, kCFStringEncodingASCII); CFStringGetCString(serialNumberAsCFString, s, size+1, kCFStringEncodingASCII);
std::string serial(s); //Copy the string to the stack std::string serial(s); // Copy the string to the stack
delete[] s; delete[] s;
kr = IOObjectRelease(usbDevice); kr = IOObjectRelease(usbDevice);