From 8e9bf6d0d88c7a563578aaae102c7358adcc8044 Mon Sep 17 00:00:00 2001 From: Fawzi Mohamed Date: Thu, 28 Nov 2013 16:02:22 +0100 Subject: ios: create devices in the disconnected state The device status is updated only when it is connected or disconnected. Thus a restored device would mantain the unknown state in which the user cannot remove the device. Using always the disconnected state so the use can remove the devices. Change-Id: Icdeb1e314eef0e5b1553decfc728e4b9eab939ab Reviewed-by: Christian Kandeler --- src/plugins/ios/iosdevice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/plugins/ios/iosdevice.cpp') diff --git a/src/plugins/ios/iosdevice.cpp b/src/plugins/ios/iosdevice.cpp index b0d552345c..801b865575 100644 --- a/src/plugins/ios/iosdevice.cpp +++ b/src/plugins/ios/iosdevice.cpp @@ -85,7 +85,7 @@ IosDevice::IosDevice() Constants::IOS_DEVICE_ID) { setDisplayName(IosDevice::name()); - setDeviceState(DeviceStateUnknown); + setDeviceState(DeviceDisconnected); } IosDevice::IosDevice(const IosDevice &other) @@ -99,7 +99,7 @@ IosDevice::IosDevice(const QString &uid) Core::Id(Constants::IOS_DEVICE_ID).withSuffix(uid)) { setDisplayName(IosDevice::name()); - setDeviceState(DeviceStateUnknown); + setDeviceState(DeviceDisconnected); } -- cgit v1.2.1 From 5a095237268f2885b2ff86ad27e7ba4c75811007 Mon Sep 17 00:00:00 2001 From: Fawzi Mohamed Date: Thu, 28 Nov 2013 14:45:56 +0100 Subject: iosdevice: guard detection handlers against foreign exceptions Change-Id: I1f74aff3aa68cf8334ede232af61c85f3152adb9 Reviewed-by: Fawzi Mohamed --- src/plugins/ios/iosdevice.cpp | 114 +++++++++++++++++++++++++----------------- 1 file changed, 67 insertions(+), 47 deletions(-) (limited to 'src/plugins/ios/iosdevice.cpp') diff --git a/src/plugins/ios/iosdevice.cpp b/src/plugins/ios/iosdevice.cpp index 801b865575..58cf894b96 100644 --- a/src/plugins/ios/iosdevice.cpp +++ b/src/plugins/ios/iosdevice.cpp @@ -46,6 +46,8 @@ #include #endif +#include + using namespace ProjectExplorer; static bool debugDeviceDetection = false; @@ -364,62 +366,80 @@ io_iterator_t gRemovedIter; extern "C" { void deviceConnectedCallback(void *refCon, io_iterator_t iterator) { - kern_return_t kr; - io_service_t usbDevice; - (void) refCon; - - while ((usbDevice = IOIteratorNext(iterator))) { - io_name_t deviceName; - - // Get the USB device's name. - kr = IORegistryEntryGetName(usbDevice, deviceName); - QString name; - if (KERN_SUCCESS == kr) - name = QString::fromLocal8Bit(deviceName); - if (debugDeviceDetection) - qDebug() << "ios device " << name << " in deviceAddedCallback"; - - CFStringRef cfUid = static_cast(IORegistryEntryCreateCFProperty( - usbDevice, - CFSTR(kUSBSerialNumberString), - kCFAllocatorDefault, 0)); - QString uid = CFStringRef2QString(cfUid); - CFRelease(cfUid); - IosDeviceManager::instance()->deviceConnected(uid, name); - - // Done with this USB device; release the reference added by IOIteratorNext - kr = IOObjectRelease(usbDevice); - } -} - -void deviceDisconnectedCallback(void *refCon, io_iterator_t iterator) -{ - kern_return_t kr; - io_service_t usbDevice; - (void) refCon; - - while ((usbDevice = IOIteratorNext(iterator))) { - io_name_t deviceName; - - // Get the USB device's name. - kr = IORegistryEntryGetName(usbDevice, deviceName); - if (KERN_SUCCESS != kr) - deviceName[0] = '\0'; - if (debugDeviceDetection) - qDebug() << "ios device " << deviceName << " in deviceDisconnectedCallback"; + try { + kern_return_t kr; + io_service_t usbDevice; + (void) refCon; + + while ((usbDevice = IOIteratorNext(iterator))) { + io_name_t deviceName; + + // Get the USB device's name. + kr = IORegistryEntryGetName(usbDevice, deviceName); + QString name; + if (KERN_SUCCESS == kr) + name = QString::fromLocal8Bit(deviceName); + if (debugDeviceDetection) + qDebug() << "ios device " << name << " in deviceAddedCallback"; - { CFStringRef cfUid = static_cast(IORegistryEntryCreateCFProperty( usbDevice, CFSTR(kUSBSerialNumberString), kCFAllocatorDefault, 0)); QString uid = CFStringRef2QString(cfUid); CFRelease(cfUid); - IosDeviceManager::instance()->deviceDisconnected(uid); + IosDeviceManager::instance()->deviceConnected(uid, name); + + // Done with this USB device; release the reference added by IOIteratorNext + kr = IOObjectRelease(usbDevice); } + } + catch (std::exception &e) { + qDebug() << "Exception " << e.what() << " in iosdevice.cpp deviceConnectedCallback"; + } + catch (...) { + qDebug() << "Exception in iosdevice.cpp deviceConnectedCallback"; + throw; + } +} + +void deviceDisconnectedCallback(void *refCon, io_iterator_t iterator) +{ + try { + kern_return_t kr; + io_service_t usbDevice; + (void) refCon; + + while ((usbDevice = IOIteratorNext(iterator))) { + io_name_t deviceName; + + // Get the USB device's name. + kr = IORegistryEntryGetName(usbDevice, deviceName); + if (KERN_SUCCESS != kr) + deviceName[0] = '\0'; + if (debugDeviceDetection) + qDebug() << "ios device " << deviceName << " in deviceDisconnectedCallback"; + + { + CFStringRef cfUid = static_cast(IORegistryEntryCreateCFProperty( + usbDevice, + CFSTR(kUSBSerialNumberString), + kCFAllocatorDefault, 0)); + QString uid = CFStringRef2QString(cfUid); + CFRelease(cfUid); + IosDeviceManager::instance()->deviceDisconnected(uid); + } - // Done with this USB device; release the reference added by IOIteratorNext - kr = IOObjectRelease(usbDevice); + // Done with this USB device; release the reference added by IOIteratorNext + kr = IOObjectRelease(usbDevice); + } + } + catch (std::exception &e) { + qDebug() << "Exception " << e.what() << " in iosdevice.cpp deviceDisconnectedCallback"; + } + catch (...) { + qDebug() << "Exception in iosdevice.cpp deviceDisconnectedCallback"; + throw; } } -- cgit v1.2.1