Skip to content

Commit

Permalink
Merge pull request #69 from gazay/master
Browse files Browse the repository at this point in the history
fixed compilation/linking
  • Loading branch information
whoozle committed Sep 11, 2015
2 parents 273d3f7 + cccb1a4 commit 2ff76f7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ if (USB_BACKEND_LIBUSB)
)
list(APPEND MTP_LIBRARIES ${LIBUSB_LIBRARIES})
elseif (USB_BACKEND_DARWIN)
find_library(CORE_LIBRARY CoreFoundation)
find_library(IOKIT_LIBRARY IOKit)
list(APPEND MTP_LIBRARIES ${IOKIT_LIBRARY} ${CORE_LIBRARY})
include_directories(mtp/backend/darwin)
list(APPEND SOURCES
mtp/backend/darwin/usb/Context.cpp
Expand Down
27 changes: 14 additions & 13 deletions mtp/backend/darwin/usb/DeviceDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

namespace mtp { namespace usb
{
Configuration::Configuration(IOUSBDeviceInterface * dev, *IOUSBConfigurationDescriptorPtr conf):
_device(dev) _conf(conf)
Configuration::Configuration(IOUSBDeviceInterface ** dev, IOUSBConfigurationDescriptorPtr conf):
_dev(dev), _conf(conf)
{
IOUSBFindInterfaceRequest request = { };

Expand All @@ -34,14 +34,14 @@ namespace mtp { namespace usb
request.bAlternateSetting = kIOUSBFindInterfaceDontCare;

io_iterator_t iterator;
USB_CALL((*dev)->CreateInterfaceIterator(dev, &request, &interface_iterator));
USB_CALL((*dev)->CreateInterfaceIterator(dev, &request, &iterator));

io_service_t interface;
while (interface = IOIteratorNext(iterator))
while ((interface = IOIteratorNext(iterator)))
{
IOCFPlugInInterface **plugInInterface = NULL;

USB_CALL(IOCreatePlugInInterfaceForService(usbInterface,
SInt32 score;
USB_CALL(IOCreatePlugInInterfaceForService(interface,
kIOUSBInterfaceUserClientTypeID,
kIOCFPlugInInterfaceID,
&plugInInterface, &score));
Expand All @@ -60,34 +60,35 @@ namespace mtp { namespace usb
}
}

DeviceDescriptor::DeviceDescriptor(io_service_t desc): _device()
DeviceDescriptor::DeviceDescriptor(io_service_t desc): _dev()
{
IOCFPlugInInterface **plugInInterface = NULL;
IOCFPlugInInterface **plugInInterface = NULL;
SInt32 score;
USB_CALL( IOCreatePlugInInterfaceForService(desc,
kIOUSBDeviceUserClientTypeID, kIOCFPlugInInterfaceID,
&plugInInterface, &score) ); //wrap desc, so it cannot leak here

USB_CALL(IOObjectRelease(desc));
(*plugInInterface)->QueryInterface(plugInInterface,
CFUUIDGetUUIDBytes(kIOUSBDeviceInterfaceID),
(LPVOID *)&_device);
(LPVOID *)&_dev);

(*plugInInterface)->Release(plugInInterface);
if (!_device)
if (!_dev)
throw std::runtime_error("cannot create device");
}

u16 DeviceDescriptor::GetVendorId() const
{
UInt16 vendor;
USB_CALL((*dev)->GetDeviceVendor(dev, &vendor));
USB_CALL((*_dev)->GetDeviceVendor(_dev, &vendor));
return vendor;
}

u16 DeviceDescriptor::GetProductId() const
{
Uint16 product;
USB_CALL((*dev)->GetDeviceProduct(dev, &product));
UInt16 product;
USB_CALL((*_dev)->GetDeviceProduct(_dev, &product));
return product;
}

Expand Down
4 changes: 2 additions & 2 deletions mtp/backend/darwin/usb/DeviceDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ namespace mtp { namespace usb
std::vector<IOUSBInterfaceInterface **> _interfaces;

public:
Configuration(IOUSBDeviceInterface * dev, IOUSBConfigurationDescriptorPtr conf): _dev(dev) _conf(conf) { }
Configuration(IOUSBDeviceInterface ** dev, IOUSBConfigurationDescriptorPtr conf);
~Configuration() { }

int GetIndex() const
{ return _conf->configValue; }
{ return _conf->bConfigurationValue; }

int GetInterfaceCount() const
{ return _interfaces.size(); }
Expand Down

0 comments on commit 2ff76f7

Please sign in to comment.