From 459669ac404c0acac33f74a8ee4ca958158f255d Mon Sep 17 00:00:00 2001 From: cdfrey Date: Fri, 30 Nov 2007 03:34:46 +0000 Subject: [PATCH] - changed Probe class behaviour so that it will not throw an exception on Device Busy (-EBUSY) but instead log the error in an internal array and keep going. This makes it possible to use btool and barrybackup with two devices plugged in at the same time. BACKWARD COMPATIBILITY NOTE: this changes initializaion behaviour, but in practice, it should only make applications look more capable, not less. - updated btool to show errors logged by Probe --- ChangeLog | 9 +++++++++ src/probe.cc | 42 ++++++++++++++++++++++++++++-------------- src/probe.h | 7 +++++++ tools/btool.cc | 14 ++++++++++++++ 4 files changed, 58 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index a278abb8..6a03b6ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,15 @@ Release: version 0.10 - 2007/10/12 possible to run bcharge, moving from 0006 to 0004 to 0001 and back to 0004, all *while* usb_storage is loaded! + - changed Probe class behaviour so that it will not throw an + exception on Device Busy (-EBUSY) but instead + log the error in an internal array and keep going. + This makes it possible to use btool and barrybackup + with two devices plugged in at the same time. + BACKWARD COMPATIBILITY NOTE: this changes initializaion + behaviour, but in practice, it should only + make applications look more capable, not less. + - updated btool to show errors logged by Probe 2007/11/27 - added ClearHalt() calls to probe and controller classes, just before any communication happens... the 8830 seems diff --git a/src/probe.cc b/src/probe.cc index 635e1f75..188d1a41 100644 --- a/src/probe.cc +++ b/src/probe.cc @@ -32,6 +32,7 @@ #include "record-internal.h" #include "strnlen.h" #include +#include using namespace Usb; @@ -115,25 +116,38 @@ bool Probe::ParseDesc(const Data &data, ProbeResult &result) } Probe::Probe() + : m_fail_count(0) { - Usb::DeviceIDType devid; // Search for standard product ID first - { - Match match(VENDOR_RIM, PRODUCT_RIM_BLACKBERRY); - while( match.next_device(&devid) ) - ProbeDevice(devid); - } + ProbeMatching(VENDOR_RIM, PRODUCT_RIM_BLACKBERRY); // Search for Pearl devices second - { - // productID 6 devices (PRODUCT_RIM_PEARL) do not expose - // the USB class 255 interface we need, but only the - // Mass Storage one. Here we search for PRODUCT_RIM_PEARL_DUAL, - // (ID 4) which has both enabled. - Match match(VENDOR_RIM, PRODUCT_RIM_PEARL_DUAL); - while( match.next_device(&devid) ) - ProbeDevice(devid); + // + // productID 6 devices (PRODUCT_RIM_PEARL) do not expose + // the USB class 255 interface we need, but only the + // Mass Storage one. Here we search for PRODUCT_RIM_PEARL_DUAL, + // (ID 4) which has both enabled. + ProbeMatching(VENDOR_RIM, PRODUCT_RIM_PEARL_DUAL); +} + +void Probe::ProbeMatching(int vendor, int product) +{ + Usb::DeviceIDType devid; + + Match match(vendor, product); + while( match.next_device(&devid) ) try { + ProbeDevice(devid); + } + catch( Usb::Error &e ) { + dout("Usb::Error exception caught: " << e.what()); + if( e.libusb_errcode() == -EBUSY ) { + m_fail_count++; + m_fail_msgs.push_back(e.what()); + } + else { + throw; + } } } diff --git a/src/probe.h b/src/probe.h index 922438d5..1b6dce5e 100644 --- a/src/probe.h +++ b/src/probe.h @@ -46,17 +46,24 @@ class Probe { std::vector m_results; + std::vector m_fail_msgs; + int m_fail_count; + bool CheckSize(const Data &data, unsigned int required); bool ParsePIN(const Data &data, ProbeResult &result); bool ParseDesc(const Data &data, ProbeResult &result); protected: + void ProbeMatching(int vendor, int product); void ProbeDevice(Usb::DeviceIDType devid); public: Probe(); int GetCount() const { return m_results.size(); } + int GetFailCount() const { return m_fail_count; } + + const std::string& GetFailMsg(int index) const { return m_fail_msgs[index]; } const ProbeResult& Get(int index) const { return m_results[index]; } int FindActive(uint32_t pin = 0) const; // returns -1 if pin not found diff --git a/tools/btool.cc b/tools/btool.cc index bbd8f3ef..2ff3a683 100644 --- a/tools/btool.cc +++ b/tools/btool.cc @@ -542,6 +542,20 @@ int main(int argc, char *argv[]) // available device list here as well Barry::Probe probe; int activeDevice = -1; + + // show any errors during probe first + if( probe.GetFailCount() ) { + if( ldif_contacts ) + cout << "# "; + cout << "Blackberry device errors with errors during probe:" << endl; + for( int i = 0; i < probe.GetFailCount(); i++ ) { + if( ldif_contacts ) + cout << "# "; + cout << probe.GetFailMsg(i) << endl; + } + } + + // show all successfully found devices if( ldif_contacts ) cout << "# "; cout << "Blackberry devices found:" << endl; -- 2.11.4.GIT