X-Git-Url: http://developer.intra2net.com/git/?p=libftdi;a=blobdiff_plain;f=ftdipp%2Fftdi.cpp;h=0a22bd51d60f4ec1b003fc42fd4052e316145d79;hp=5333d30cf80b93058976ea8db065d5a385876fef;hb=6b22a0549318d1e7fba0c1d9e28c1acf7b94f8b0;hpb=cfceadbca71ddaf170ea3d869adb8ea4d91ea819 diff --git a/ftdipp/ftdi.cpp b/ftdipp/ftdi.cpp index 5333d30..0a22bd5 100644 --- a/ftdipp/ftdi.cpp +++ b/ftdipp/ftdi.cpp @@ -5,15 +5,27 @@ copyright : (C) 2008 by Marek Vavruša email : opensource@intra2net.com and marek@vavrusa.com ***************************************************************************/ +/* +Copyright (C) 2008 by Marek Vavruša -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Lesser General Public License * - * version 2.1 as published by the Free Software Foundation; * - * * - ***************************************************************************/ +The software in this package is distributed under the GNU General +Public License version 2 (with a special exception described below). + +A copy of GNU General Public License (GPL) is included in this distribution, +in the file COPYING.GPL. + +As a special exception, if other files instantiate templates or use macros +or inline functions from this file, or you compile this file and link it +with other works to produce a work based on this file, this file +does not by itself cause the resulting work to be covered +by the GNU General Public License. +However the source code for this file must still be made available +in accordance with section (3) of the GNU General Public License. + +This exception does not invalidate any other reasons why a work based +on this file might be covered by the GNU General Public License. +*/ #include "ftdi.hpp" #include "ftdi.h" @@ -24,14 +36,14 @@ class Context::Private { public: Private() - : ftdi(0), dev(0), open(false) + : ftdi(0), dev(0), open(false) { ftdi = ftdi_new(); } ~Private() { - if(open) + if (open) ftdi_usb_close(ftdi); ftdi_free(ftdi); @@ -389,30 +401,32 @@ int Eeprom::erase() class List::Private { public: - Private(struct ftdi_device_list* devlist) - : list(devlist) + Private(struct ftdi_device_list* _devlist) + : devlist(_devlist) {} ~Private() { - ftdi_list_free(&list); + if(devlist) + ftdi_list_free(&devlist); } - struct ftdi_device_list* list; + std::list list; + struct ftdi_device_list* devlist; }; List::List(struct ftdi_device_list* devlist) - : ListBase(), d( new Private(devlist) ) + : d( new Private(devlist) ) { if (devlist != 0) { // Iterate list - for (d->list = devlist; d->list != 0; d->list = d->list->next) + for (; devlist != 0; devlist = devlist->next) { Context c; - c.set_usb_device(d->list->dev); + c.set_usb_device(devlist->dev); c.get_strings(); - push_back(c); + d->list.push_back(c); } } } @@ -421,6 +435,42 @@ List::~List() { } +int List::size() +{ + return d->list.size(); +} + +void List::push_front(const Context& element) +{ + d->list.push_front(element); +} + + +void List::push_back(const Context& element) +{ + d->list.push_back(element); +} + +void List::clear() +{ + d->list.clear(); + + // Free device list + ftdi_list_free(&d->devlist); + d->devlist = 0; +} + +std::list::iterator List::begin() +{ + return d->list.begin(); +} + +std::list::iterator List::end() +{ + return d->list.end(); +} + + List* List::find_all(int vendor, int product) { struct ftdi_device_list* dlist = 0;