Commit 5a095237 authored by Fawzi Mohamed's avatar Fawzi Mohamed
Browse files

iosdevice: guard detection handlers against foreign exceptions



Change-Id: I1f74aff3aa68cf8334ede232af61c85f3152adb9
Reviewed-by: default avatarFawzi Mohamed <fawzi.mohamed@digia.com>
parent 21c4056c
......@@ -46,6 +46,8 @@
#include <CoreFoundation/CoreFoundation.h>
#endif
#include <exception>
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<CFStringRef>(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<CFStringRef>(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<CFStringRef>(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;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment