probe.h

Go to the documentation of this file.
00001 ///
00002 /// \file       probe.h
00003 ///             USB Blackberry detection routines
00004 ///
00005 
00006 /*
00007     Copyright (C) 2005-2010, Net Direct Inc. (http://www.netdirect.ca/)
00008 
00009     This program is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     This program is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00017 
00018     See the GNU General Public License in the COPYING file at the
00019     root directory of this project for more details.
00020 */
00021 
00022 #ifndef __BARRY_PROBE_H__
00023 #define __BARRY_PROBE_H__
00024 
00025 #include "dll.h"
00026 #include "usbwrap.h"
00027 #include "pin.h"
00028 #include <vector>
00029 #include <iosfwd>
00030 #include <stdint.h>
00031 
00032 namespace Barry {
00033 
00034 struct BXEXPORT ProbeResult
00035 {
00036         Usb::DeviceIDType m_dev;
00037         unsigned char m_interface;
00038         Barry::Pin m_pin;
00039         Usb::EndpointPair m_ep;
00040         Usb::EndpointPair m_epModem;
00041         uint8_t m_zeroSocketSequence;
00042         std::string m_description;
00043 
00044         // data from a possible ConfigFile (filled in automatically by
00045         // the probe code if available)
00046         std::string m_cfgDeviceName;
00047 
00048         ProbeResult()
00049                 : m_dev(0), m_interface(0), m_pin(0), m_zeroSocketSequence(0)
00050                 {}
00051         void DumpAll(std::ostream &os) const;
00052         bool HasIpModem() const { return m_epModem.IsComplete(); }
00053 
00054         bool operator==(const Barry::Pin &pin) const
00055         {
00056                 return m_pin == pin;
00057         }
00058 };
00059 
00060 BXEXPORT std::ostream& operator<< (std::ostream &os, const ProbeResult &pr);
00061 
00062 
00063 class BXEXPORT Probe
00064 {
00065 public:
00066         typedef std::vector<ProbeResult>                Results;
00067 
00068 private:
00069         Results m_results;
00070 
00071         std::vector<std::string> m_fail_msgs;
00072         int m_fail_count;
00073 
00074         bool m_epp_override;
00075         Usb::EndpointPair m_epp;
00076 
00077         BXLOCAL bool CheckSize(const Data &data, unsigned int required);
00078         BXLOCAL bool ParsePIN(const Data &data, uint32_t &pin);
00079         BXLOCAL bool ParseDesc(const Data &data, std::string &desc);
00080 
00081 protected:
00082         void ProbeMatching(int vendor, int product,
00083                 const char *busname, const char *devname);
00084         void ProbeDevice(Usb::DeviceIDType devid);
00085         bool ProbePair(Usb::Device &dev, const Usb::EndpointPair &ep,
00086                 uint32_t &pin, std::string &desc, uint8_t &zeroSocketSequence);
00087         bool ProbeModem(Usb::Device &dev, const Usb::EndpointPair &ep);
00088 
00089 public:
00090         Probe(const char *busname = 0, const char *devname = 0,
00091                 const Usb::EndpointPair *epp = 0);
00092 
00093         const Results& GetResults() const { return m_results; }
00094 
00095         int GetCount() const { return m_results.size(); }
00096         int GetFailCount() const { return m_fail_count; }
00097 
00098         const std::string& GetFailMsg(int index) const { return m_fail_msgs[index]; }
00099         const ProbeResult& Get(int index) const { return m_results[index]; }
00100 
00101         int FindActive(Barry::Pin pin = 0) const; // returns -1 if pin not found
00102                                                 // or if no devices
00103         static int FindActive(const Results &results, Barry::Pin pin = 0);
00104         static int Find(const Results &results, Barry::Pin pin = 0);
00105 };
00106 
00107 
00108 } // namespace Barry
00109 
00110 #endif
00111 
Generated by  doxygen 1.6.2-20100208