X-Git-Url: http://developer.intra2net.com/git/?p=libftdi;a=blobdiff_plain;f=ftdipp%2Fftdi.cpp;h=0a22bd51d60f4ec1b003fc42fd4052e316145d79;hp=7c1ba60d47cb32236cd4f5f96183360bbd3664ec;hb=6b22a0549318d1e7fba0c1d9e28c1acf7b94f8b0;hpb=cdf448f6d42cbda7d5ced7661f6de22ffb96cc54 diff --git a/ftdipp/ftdi.cpp b/ftdipp/ftdi.cpp index 7c1ba60..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,8 +36,17 @@ class Context::Private { public: Private() - : ftdi(0), dev(0), open(false) + : ftdi(0), dev(0), open(false) { + ftdi = ftdi_new(); + } + + ~Private() + { + if (open) + ftdi_usb_close(ftdi); + + ftdi_free(ftdi); } bool open; @@ -43,18 +64,12 @@ public: Context::Context() : d( new Private() ) { - d->ftdi = ftdi_new(); } /*! \brief Destructor. */ Context::~Context() { - if (d->open) - close(); - - ftdi_free(d->ftdi); - delete d; } bool Context::is_open() @@ -341,7 +356,6 @@ Eeprom::Eeprom(Context* parent) Eeprom::~Eeprom() { - delete d; } void Eeprom::init_defaults() @@ -387,46 +401,76 @@ int Eeprom::erase() class List::Private { public: - Private() - : list(0) + Private(struct ftdi_device_list* _devlist) + : devlist(_devlist) {} - struct ftdi_device_list* list; + ~Private() + { + if(devlist) + ftdi_list_free(&devlist); + } + + std::list list; + struct ftdi_device_list* devlist; }; List::List(struct ftdi_device_list* devlist) - : ListBase(), d( new Private() ) + : d( new Private(devlist) ) { if (devlist != 0) { // Iterate list - Context* c = 0; - for (d->list = devlist; d->list != 0; d->list = d->list->next) + for (; devlist != 0; devlist = devlist->next) { - c = new Context(); - c->set_usb_device(d->list->dev); - push_back(c); + Context c; + c.set_usb_device(devlist->dev); + c.get_strings(); + d->list.push_back(c); } - - // Store pointer - d->list = devlist; } } List::~List() { - // Deallocate instances - for (iterator it = begin(); it != end(); it++) - delete *it; +} - // Clear list - clear(); - ftdi_list_free(&d->list); +int List::size() +{ + return d->list.size(); +} - // Delete d-ptr - delete d; +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;