From 1eccfa732124a03d6987e44ab907264ff3a6f864 Mon Sep 17 00:00:00 2001 From: Chris Frey Date: Thu, 26 Nov 2009 22:05:40 -0500 Subject: [PATCH] lib: moved GUI's Pin class into the library Also changed some of the pin number types to use the Pin class, in places where the API is exposed (Probe, etc) --- examples/addcontact.cc | 4 ++-- gui/src/ConfigFile.cc | 4 ++-- gui/src/ConfigFile.h | 8 ++++---- gui/src/DeviceIface.h | 3 +-- gui/src/Makefile.am | 2 -- gui/src/Thread.h | 2 +- src/Makefile.am | 2 ++ src/controller.h | 3 ++- src/m_javaloader.cc | 2 +- src/m_javaloader.h | 3 ++- gui/src/Pin.cc => src/pin.cc | 11 ++++++++--- gui/src/Pin.h => src/pin.h | 23 +++++++++++++++++------ src/probe.cc | 4 ++-- src/probe.h | 5 +++-- tools/bfuse.cc | 11 +++++------ tools/bidentify.cc | 2 +- tools/btool.cc | 4 ++-- 17 files changed, 55 insertions(+), 38 deletions(-) rename gui/src/Pin.cc => src/pin.cc (90%) rename gui/src/Pin.h => src/pin.h (67%) diff --git a/examples/addcontact.cc b/examples/addcontact.cc index 27423bee..67aa020a 100644 --- a/examples/addcontact.cc +++ b/examples/addcontact.cc @@ -136,8 +136,8 @@ int main(int argc, char *argv[]) return 1; } else { - cout << "Using PIN: " << std::hex - << probe.Get(0).m_pin << endl; + cout << "Using PIN: " + << probe.Get(0).m_pin.str() << endl; } diff --git a/gui/src/ConfigFile.cc b/gui/src/ConfigFile.cc index 3979f54a..f97fa231 100644 --- a/gui/src/ConfigFile.cc +++ b/gui/src/ConfigFile.cc @@ -53,7 +53,7 @@ ConfigFile::ConfigFileError::ConfigFileError(const char *msg, int err) /// but it is not an error if the config does not exist. /// Never use this if you have a DatabaseDatabase object! /// This ctor is only for temporary loading of config data. -ConfigFile::ConfigFile(Pin pin) +ConfigFile::ConfigFile(Barry::Pin pin) : m_pin(pin) , m_loaded(false) , m_promptBackupLabel(false) @@ -69,7 +69,7 @@ ConfigFile::ConfigFile(Pin pin) /// Opens and loads config file for given pin, and calls Enlighten /// Throws ConfigFileError on error. Should never fail unless /// passed a bad pin. -ConfigFile::ConfigFile(Pin pin, +ConfigFile::ConfigFile(Barry::Pin pin, const Barry::DatabaseDatabase &db) : m_pin(pin) , m_loaded(false) diff --git a/gui/src/ConfigFile.h b/gui/src/ConfigFile.h index 91d57ae8..a14febd1 100644 --- a/gui/src/ConfigFile.h +++ b/gui/src/ConfigFile.h @@ -24,8 +24,8 @@ #include #include +#include #include -#include "Pin.h" class ConfigFile { @@ -45,7 +45,7 @@ public: private: // meta data - Pin m_pin; + Barry::Pin m_pin; std::string m_path; // /path/to/config/dir without trailing slash std::string m_filename; // /path/to/config/dir/filename bool m_loaded; @@ -71,12 +71,12 @@ public: /// but it is not an error if the config does not exist. /// Never use this if you have a DatabaseDatabase object! /// This ctor is only for temporary loading of config data. - explicit ConfigFile(Pin pin); + explicit ConfigFile(Barry::Pin pin); /// Opens and loads config file for given pin, and calls Enlighten /// Throws ConfigFileError on error. Should never fail unless /// passed a bad pin, or if unable to get current user info. - ConfigFile(Pin pin, const Barry::DatabaseDatabase &db); + ConfigFile(Barry::Pin pin, const Barry::DatabaseDatabase &db); ~ConfigFile(); diff --git a/gui/src/DeviceIface.h b/gui/src/DeviceIface.h index 3b463498..723e9bca 100644 --- a/gui/src/DeviceIface.h +++ b/gui/src/DeviceIface.h @@ -27,7 +27,6 @@ #include #include #include "ConfigFile.h" -#include "Pin.h" #include "tarfile.h" #define DI_THREAD_DONE 100 @@ -46,7 +45,7 @@ public: Device(); Device(Barry::ProbeResult); - Pin GetPIN() const { return Pin(result.m_pin); }; + Barry::Pin GetPIN() const { return Barry::Pin(result.m_pin); }; friend class DeviceInterface; }; diff --git a/gui/src/Makefile.am b/gui/src/Makefile.am index a46e58b4..7de44207 100644 --- a/gui/src/Makefile.am +++ b/gui/src/Makefile.am @@ -31,7 +31,6 @@ barrybackup_SOURCES = \ DeviceBus.cc \ DeviceIface.cc \ Thread.cc \ - Pin.cc \ tarfile.cc \ tarfile-ops-nt.cc \ util.cc @@ -46,7 +45,6 @@ noinst_HEADERS= \ PasswordDlg.h \ PromptDlg.h \ Thread.h \ - Pin.h \ tarfile.h \ util.h diff --git a/gui/src/Thread.h b/gui/src/Thread.h index 7271bcb9..5c51af32 100644 --- a/gui/src/Thread.h +++ b/gui/src/Thread.h @@ -90,7 +90,7 @@ public: void LoadConfig(); - Pin GetPIN() { return m_dev.GetPIN(); } + Barry::Pin GetPIN() { return m_dev.GetPIN(); } std::string GetFullname(); std::string Status() const { return m_status; } diff --git a/src/Makefile.am b/src/Makefile.am index ecc42f94..2e09c676 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -87,6 +87,7 @@ include_barry_HEADERS = barry.h \ ldif.h \ log.h \ parser.h \ + pin.h \ probe.h \ protocol.h \ record.h \ @@ -147,6 +148,7 @@ libbarry_la_SOURCES = time.cc \ cod.cc \ data.cc \ usbwrap.cc \ + pin.cc \ probe.cc \ common.cc \ error.cc \ diff --git a/src/controller.h b/src/controller.h index 4cb9fe6e..3275db7d 100644 --- a/src/controller.h +++ b/src/controller.h @@ -25,6 +25,7 @@ #include "dll.h" #include "usbwrap.h" #include "socket.h" +#include "pin.h" #include "probe.h" /// Project namespace, containing all related functions and classes. @@ -91,7 +92,7 @@ private: ProbeResult m_result; Usb::Device m_dev; Usb::Interface *m_iface; - uint32_t m_pin; + Pin m_pin; SocketZero m_zero; SocketRoutingQueue *m_queue; //< ptr to external object; no delete diff --git a/src/m_javaloader.cc b/src/m_javaloader.cc index 4de2557c..1531a42a 100644 --- a/src/m_javaloader.cc +++ b/src/m_javaloader.cc @@ -304,7 +304,7 @@ void JLDeviceInfo::Dump(std::ostream &os) const os << "0x" << hex << HardwareId << endl; os << left << setfill(' ') << setw(17) << "PIN:"; - os << "0x" << hex << Pin << endl; + os << "0x" << Pin.str() << endl; os << left << setfill(' ') << setw(17) << "OS Version:"; os << dec << OsVersion.Major << '.' << OsVersion.Minor << '.' << OsVersion.SubMinor << '.' << OsVersion.Build << endl; diff --git a/src/m_javaloader.h b/src/m_javaloader.h index 68cf4b36..e8570b09 100644 --- a/src/m_javaloader.h +++ b/src/m_javaloader.h @@ -30,6 +30,7 @@ #include "socket.h" #include "record.h" #include "data.h" +#include "pin.h" namespace Barry { @@ -183,7 +184,7 @@ public: public: uint32_t HardwareId; - uint32_t Pin; + struct Pin Pin; VersionQuad OsVersion; VersionQuad VmVersion; uint32_t RadioId; diff --git a/gui/src/Pin.cc b/src/pin.cc similarity index 90% rename from gui/src/Pin.cc rename to src/pin.cc index a6f07e21..06cccc7e 100644 --- a/gui/src/Pin.cc +++ b/src/pin.cc @@ -1,5 +1,5 @@ /// -/// \file Pin.cc +/// \file pin.cc /// class for device PIN notation /// @@ -20,11 +20,16 @@ */ #include -#include "Pin.h" +#include "pin.h" -std::string Pin::str() +namespace Barry { + +std::string Pin::str() const { std::ostringstream oss; oss << std::hex << pin; return oss.str(); } + +} + diff --git a/gui/src/Pin.h b/src/pin.h similarity index 67% rename from gui/src/Pin.h rename to src/pin.h index 09827e22..0341935a 100644 --- a/gui/src/Pin.h +++ b/src/pin.h @@ -1,5 +1,5 @@ /// -/// \file Pin.h +/// \file pin.h /// class for device PIN notation /// @@ -19,21 +19,32 @@ root directory of this project for more details. */ -#ifndef __BARRYBACKUP_PIN_H__ -#define __BARRYBACKUP_PIN_H__ +#ifndef __BARRY_PIN_H__ +#define __BARRY_PIN_H__ +#include "dll.h" #include #include -class Pin +namespace Barry { + +class BXEXPORT Pin { uint32_t pin; public: Pin(uint32_t pin__ = 0) : pin(pin__) {} - std::string str(); - bool operator==(uint32_t rhs) { return pin == rhs; } + std::string str() const; + uint32_t value() const { return pin; } + + Pin& operator=(uint32_t p) { pin = p; return *this; } + + bool operator==(uint32_t rhs) const { return pin == rhs; } + bool operator==(const Pin &rhs) const { return pin == rhs.pin; } }; +} // namespace Barry + #endif + diff --git a/src/probe.cc b/src/probe.cc index a132fff2..edf6a333 100644 --- a/src/probe.cc +++ b/src/probe.cc @@ -395,7 +395,7 @@ bool Probe::ProbeModem(Usb::Device &dev, const Usb::EndpointPair &ep) // return false; } -int Probe::FindActive(uint32_t pin) const +int Probe::FindActive(Barry::Pin pin) const { for( int i = 0; i < GetCount(); i++ ) { if( Get(i).m_pin == pin ) @@ -424,7 +424,7 @@ void ProbeResult::DumpAll(std::ostream &os) const std::ostream& operator<< (std::ostream &os, const ProbeResult &pr) { os << "Device ID: " << pr.m_dev - << std::hex << ". PIN: " << pr.m_pin + << ". PIN: " << pr.m_pin.str() << ", Description: " << pr.m_description; return os; } diff --git a/src/probe.h b/src/probe.h index f59ebdaa..2e49a069 100644 --- a/src/probe.h +++ b/src/probe.h @@ -24,6 +24,7 @@ #include "dll.h" #include "usbwrap.h" +#include "pin.h" #include #include #include @@ -34,7 +35,7 @@ struct BXEXPORT ProbeResult { Usb::DeviceIDType m_dev; unsigned char m_interface; - uint32_t m_pin; + Barry::Pin m_pin; Usb::EndpointPair m_ep; Usb::EndpointPair m_epModem; uint8_t m_zeroSocketSequence; @@ -82,7 +83,7 @@ public: 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 + int FindActive(Barry::Pin pin = 0) const; // returns -1 if pin not found // or if no devices }; diff --git a/tools/bfuse.cc b/tools/bfuse.cc index 24a44300..bfeb5bde 100644 --- a/tools/bfuse.cc +++ b/tools/bfuse.cc @@ -630,23 +630,22 @@ public: // connect to all PINs found, and add them to our map for( int i = 0; i < m_probe->GetCount(); i++ ) { - ostringstream oss; - oss << hex << m_probe->Get(i).m_pin; + string curpin = m_probe->Get(i).m_pin.str(); // don't add a blank or pre-existing pin - if( !oss.str().size() || m_pinmap.find(oss.str()) != m_pinmap.end() ) { + if( !curpin.size() || m_pinmap.find(curpin) != m_pinmap.end() ) { continue; } // don't add non-PIN device if pin specified - if( m_limit_pin.size() && oss.str() != m_limit_pin ) { + if( m_limit_pin.size() && curpin != m_limit_pin ) { continue; } DesktopConPtr dev = DesktopConPtr ( - new DesktopCon(m_probe->Get(i), oss.str()) ); + new DesktopCon(m_probe->Get(i), curpin) ); dev->Open(m_password.c_str()); - m_pinmap[ oss.str() ] = dev; + m_pinmap[ curpin ] = dev; } } diff --git a/tools/bidentify.cc b/tools/bidentify.cc index 13653064..890124e1 100644 --- a/tools/bidentify.cc +++ b/tools/bidentify.cc @@ -100,7 +100,7 @@ int main(int argc, char *argv[]) // show all successfully found devices for( int i = 0; i < probe.GetCount(); i++ ) { const ProbeResult &pr = probe.Get(i); - cout << hex << pr.m_pin << ", " + cout << pr.m_pin.str() << ", " << pr.m_description << endl; } diff --git a/tools/btool.cc b/tools/btool.cc index d8bd1baa..d983c91b 100644 --- a/tools/btool.cc +++ b/tools/btool.cc @@ -691,8 +691,8 @@ int main(int argc, char *argv[]) if( ldif_contacts ) cout << "# "; - cout << "Using device (PIN): " << setbase(16) - << probe.Get(activeDevice).m_pin << endl; + cout << "Using device (PIN): " + << probe.Get(activeDevice).m_pin.str() << endl; if( reset_device ) { Usb::Device dev(probe.Get(activeDevice).m_dev); -- 2.11.4.GIT