/* -*- Mode: C; indent-tabs-mode:nil -*- */
/*
* darwin backend for libusb 1.0
- * Copyright © 2008-2013 Nathan Hjelm <hjelmn@users.sourceforge.net>
+ * Copyright © 2008-2014 Nathan Hjelm <hjelmn@users.sourceforge.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
if (interface_out)
*interface_out = cInterface;
- usbi_dbg ("pipe %d on interface %d matches", *pipep, *ifcp);
+ usbi_dbg ("pipe %d on interface %d matches", *pipep, iface);
return 0;
}
}
UInt64 session;
int ret;
+ usbi_mutex_lock(&active_contexts_lock);
+
while ((device = IOIteratorNext (rem_devices)) != 0) {
/* get the location from the i/o registry */
ret = get_ioregistry_value_number (device, CFSTR("sessionID"), kCFNumberSInt64Type, &session);
if (!ret)
continue;
- usbi_mutex_lock(&active_contexts_lock);
-
list_for_each_entry(ctx, &active_contexts_list, list, struct libusb_context) {
usbi_dbg ("notifying context %p of device disconnect", ctx);
libusb_unref_device(dev);
}
}
-
- usbi_mutex_unlock(&active_contexts_lock);
}
+
+ usbi_mutex_unlock(&active_contexts_lock);
+}
+
+static void darwin_hotplug_poll (void)
+{
+ /* not sure if 5 seconds will be too long/short but it should work ok */
+ mach_timespec_t timeout = {.tv_sec = 5, .tv_nsec = 0};
+
+ /* since a kernel thread may nodify the IOInterators used for
+ * hotplug notidication we can't just clear the iterators.
+ * instead just wait until all IOService providers are quiet */
+ (void) IOKitWaitQuiet (kIOMasterPortDefault, &timeout);
}
static void darwin_clear_iterator (io_iterator_t iter) {
usbi_dbg ("interface: %i pipe %i: dir: %i number: %i", iface, i, direction, number);
- cInterface->endpoint_addrs[i - 1] = ((direction << 7 & LIBUSB_ENDPOINT_DIR_MASK) | (number & LIBUSB_ENDPOINT_ADDRESS_MASK));
+ cInterface->endpoint_addrs[i - 1] = (((kUSBIn == direction) << kUSBRqDirnShift) | (number & LIBUSB_ENDPOINT_ADDRESS_MASK));
}
cInterface->num_endpoints = numep;
.get_device_descriptor = darwin_get_device_descriptor,
.get_active_config_descriptor = darwin_get_active_config_descriptor,
.get_config_descriptor = darwin_get_config_descriptor,
+ .hotplug_poll = darwin_hotplug_poll,
.open = darwin_open,
.close = darwin_close,