We can no longer call ftdi_deinit() inside find_all().
This will call libusb_exit() which invalidates all further
operations on device lists / usb devices pointers.
Instead we pass in the Ftdi::Context from the calling side.
<< std::endl << std::dec;
// Print whole list
- List* list = List::find_all(vid, pid);
+ Context context;
+ List* list = List::find_all(context, vid, pid);
for (List::iterator it = list->begin(); it != list->end(); it++)
{
std::cout << "FTDI (" << &*it << "): "
return d->list.erase(beg, end);
}
-List* List::find_all(int vendor, int product)
+List* List::find_all(Context &context, int vendor, int product)
{
struct ftdi_device_list* dlist = 0;
- struct ftdi_context ftdi;
- ftdi_init(&ftdi);
- ftdi_usb_find_all(&ftdi, &dlist, vendor, product);
- ftdi_deinit(&ftdi);
+ ftdi_usb_find_all(context.context(), &dlist, vendor, product);
return new List(dlist);
}
List(struct ftdi_device_list* devlist = 0);
~List();
- static List* find_all(int vendor, int product);
+ static List* find_all(Context &context, int vendor, int product);
/// List type storing "Context" objects
typedef std::list<Context> ListType;