libftdi-git Archives

Subject: A library to talk to FTDI chips branch, master, updated. v0.16rc1-3-g2f6b4bb

From: libftdi-git@xxxxxxxxxxxxxxxxxxxxxxx
To: libftdi-git@xxxxxxxxxxxxxxxxxxxxxxx
Date: Mon, 4 May 2009 17:55:25 +0200 (CEST)
The branch, master has been updated
       via  2f6b4bb6a67d7b3a0d4b0ba216637c8bdaac728f (commit)
       via  a14193ac17be8cf781feeea182a5e56582d4e0a6 (commit)
       via  6b22a0549318d1e7fba0c1d9e28c1acf7b94f8b0 (commit)
      from  e81598e4752debbc926108e4526b124f06e063b6 (commit)


- Log -----------------------------------------------------------------
commit 2f6b4bb6a67d7b3a0d4b0ba216637c8bdaac728f
Author: Marek Vavrusa <marek@xxxxxxxxxxx>
Date:   Mon May 4 11:54:52 2009 +0200

    Fixed Context::open as get_strings() closes the device before. Thanks to 
Chris M. Leahy for pointing this out. Tested on our good old example (added 
open test).
    
    Intra2net: Reverted return code behavior of Context::open() calls

commit a14193ac17be8cf781feeea182a5e56582d4e0a6
Author: Thomas Jarosch <thomas.jarosch@xxxxxxxxxxxxx>
Date:   Mon May 4 17:11:28 2009 +0200

    Added some more functions to list API. Fixed return type of size() call and 
made sure clear() really frees the internal memory of the list. Added doxygen 
documentation

commit 6b22a0549318d1e7fba0c1d9e28c1acf7b94f8b0
Author: Marek Vavrusa <marek@xxxxxxxxxxx>
Date:   Mon May 4 11:41:52 2009 +0200

    List having non-virtual destructor fixed (thanks to Thomas Jarosch) 
Proposed subset of list API. Tested on examples.

-----------------------------------------------------------------------

Summary of changes:
 examples/find_all_pp.cpp |   13 +++-
 ftdipp/ftdi.cpp          |  193 +++++++++++++++++++++++++++++++++++++++++-----
 ftdipp/ftdi.hpp          |   35 ++++++++-
 3 files changed, 215 insertions(+), 26 deletions(-)

diff --git a/examples/find_all_pp.cpp b/examples/find_all_pp.cpp
index 4e8e824..98e5133 100644
--- a/examples/find_all_pp.cpp
+++ b/examples/find_all_pp.cpp
@@ -51,8 +51,17 @@ int main(int argc, char **argv)
         std::cout << "FTDI (" << &*it << "): "
         << it->vendor() << ", "
         << it->description() << ", "
-        << it->serial()
-        << std::endl;
+        << it->serial();
+
+        // Open test
+        if(it->open())
+           std::cout << " (Open OK)";
+        else
+           std::cout << " (Open FAILED)";
+
+        it->close();
+
+        std::cout << std::endl;
 
     }
 
diff --git a/ftdipp/ftdi.cpp b/ftdipp/ftdi.cpp
index 23d3a57..e5a8966 100644
--- a/ftdipp/ftdi.cpp
+++ b/ftdipp/ftdi.cpp
@@ -81,37 +81,39 @@ int Context::open(int vendor, int product, const 
std::string& description, const
 {
     int ret = 0;
 
+    // Open device
     if (description.empty() && serial.empty())
         ret = ftdi_usb_open(d->ftdi, vendor, product);
     else
         ret = ftdi_usb_open_desc(d->ftdi, vendor, product, 
description.c_str(), serial.c_str());
 
-    d->dev = usb_device(d->ftdi->usb_dev);
+    if (ret < 0)
+       return ret;
 
-    if ((ret = ftdi_usb_open_dev(d->ftdi, d->dev)) >= 0)
-    {
-        d->open = true;
-        get_strings();
-    }
+    // Get device strings (closes device)
+    get_strings();
+
+    // Reattach device
+    ret = ftdi_usb_open_dev(d->ftdi, d->dev);
+    d->open = (ret >= 0);
 
     return ret;
 }
 
 int Context::open(struct usb_device *dev)
 {
-    int ret = 0;
-
     if (dev != 0)
         d->dev = dev;
 
     if (d->dev == 0)
         return -1;
 
-    if ((ret = ftdi_usb_open_dev(d->ftdi, d->dev)) >= 0)
-    {
-        d->open = true;
-        get_strings();
-    }
+    // Get device strings (closes device)
+    get_strings();
+
+    // Reattach device
+    int ret = ftdi_usb_open_dev(d->ftdi, d->dev);
+    d->open = (ret >= 0);
 
     return ret;
 }
@@ -401,30 +403,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<Context> 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);
         }
     }
 }
@@ -433,6 +437,153 @@ List::~List()
 {
 }
 
+/**
+* Return begin iterator for accessing the contained list elements
+* @return Iterator
+*/
+List::iterator List::begin()
+{
+    return d->list.begin();
+}
+
+/**
+* Return end iterator for accessing the contained list elements
+* @return Iterator
+*/
+List::iterator List::end()
+{
+    return d->list.end();
+}
+
+/**
+* Return begin iterator for accessing the contained list elements
+* @return Const iterator
+*/
+List::const_iterator List::begin() const
+{
+    return d->list.begin();
+}
+
+/**
+* Return end iterator for accessing the contained list elements
+* @return Const iterator
+*/
+List::const_iterator List::end() const
+{
+    return d->list.end();
+}
+
+/**
+* Return begin reverse iterator for accessing the contained list elements
+* @return Reverse iterator
+*/
+List::reverse_iterator List::rbegin()
+{
+    return d->list.rbegin();
+}
+
+/**
+* Return end reverse iterator for accessing the contained list elements
+* @return Reverse iterator
+*/
+List::reverse_iterator List::rend()
+{
+    return d->list.rend();
+}
+
+/**
+* Return begin reverse iterator for accessing the contained list elements
+* @return Const reverse iterator
+*/
+List::const_reverse_iterator List::rbegin() const
+{
+    return d->list.rbegin();
+}
+
+/**
+* Return end reverse iterator for accessing the contained list elements
+* @return Const reverse iterator
+*/
+List::const_reverse_iterator List::rend() const
+{
+    return d->list.rend();
+
+}
+
+/**
+* Get number of elements stored in the list
+* @return Number of elements
+*/
+List::ListType::size_type List::size() const
+{
+    return d->list.size();
+}
+
+/**
+* Check if list is empty
+* @return True if empty, false otherwise
+*/
+bool List::empty() const
+{
+    return d->list.empty();
+}
+
+/**
+ * Removes all elements. Invalidates all iterators.
+ * Do it in a non-throwing way and also make
+ * sure we really free the allocated memory.
+ */
+void List::clear()
+{
+    ListType().swap(d->list);
+
+    // Free device list
+    if (d->devlist)
+    {
+        ftdi_list_free(&d->devlist);
+        d->devlist = 0;
+    }
+}
+
+/**
+ * Appends a copy of the element as the new last element.
+ * @param element Value to copy and append
+*/
+void List::push_back(const Context& element)
+{
+    d->list.push_back(element);
+}
+
+/**
+ * Adds a copy of the element as the new first element.
+ * @param element Value to copy and add
+*/
+void List::push_front(const Context& element)
+{
+    d->list.push_front(element);
+}
+
+/**
+ * Erase one element pointed by iterator
+ * @param pos Element to erase
+ * @return Position of the following element (or end())
+*/
+List::iterator List::erase(iterator pos)
+{
+    return d->list.erase(pos);
+}
+
+/**
+ * Erase a range of elements
+ * @param beg Begin of range
+ * @param end End of range
+ * @return Position of the element after the erased range (or end())
+*/
+List::iterator List::erase(iterator beg, iterator end)
+{
+    return d->list.erase(beg, end);
+}
+
 List* List::find_all(int vendor, int product)
 {
     struct ftdi_device_list* dlist = 0;
diff --git a/ftdipp/ftdi.hpp b/ftdipp/ftdi.hpp
index 4c3b7c5..d752bd6 100644
--- a/ftdipp/ftdi.hpp
+++ b/ftdipp/ftdi.hpp
@@ -162,11 +162,9 @@ private:
     boost::shared_ptr<Private> d;
 };
 
-typedef std::list<Context> ListBase;
-
 /*! \brief Device list.
  */
-class List : public ListBase
+class List
 {
 public:
     List(struct ftdi_device_list* devlist = 0);
@@ -174,6 +172,37 @@ public:
 
     static List* find_all(int vendor, int product);
 
+    /// List type storing "Context" objects
+    typedef std::list<Context> ListType;
+    /// Iterator type for the container
+    typedef ListType::iterator iterator;
+    /// Const iterator type for the container
+    typedef ListType::const_iterator const_iterator;
+    /// Reverse iterator type for the container
+    typedef ListType::reverse_iterator reverse_iterator;
+    /// Const reverse iterator type for the container
+    typedef ListType::const_reverse_iterator const_reverse_iterator;
+
+    iterator begin();
+    iterator end();
+    const_iterator begin() const;
+    const_iterator end() const;
+
+    reverse_iterator rbegin();
+    reverse_iterator rend();
+    const_reverse_iterator rbegin() const;
+    const_reverse_iterator rend() const;
+
+    ListType::size_type size() const;
+    bool empty() const;
+    void clear();
+
+    void push_back(const Context& element);
+    void push_front(const Context& element);
+
+    iterator erase(iterator pos);
+    iterator erase(iterator beg, iterator end);
+
 private:
     class Private;
     boost::shared_ptr<Private> d;


hooks/post-receive
-- 
A library to talk to FTDI chips

--
libftdi-git - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi-git+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx   

Current Thread
  • A library to talk to FTDI chips branch, master, updated. v0.16rc1-3-g2f6b4bb, libftdi-git <=