lib: add prefixes to enums to avoid name clashes on Windows (like ERROR)
[barry.git] / src / probe.h
blob8f4eeedd91314146527ce011792dff953eac8ee4
1 ///
2 /// \file probe.h
3 /// USB Blackberry detection routines
4 ///
6 /*
7 Copyright (C) 2005-2010, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRY_PROBE_H__
23 #define __BARRY_PROBE_H__
25 #include "dll.h"
26 #include "usbwrap.h"
27 #include "pin.h"
28 #include <vector>
29 #include <iosfwd>
30 #include <stdint.h>
32 namespace Barry {
34 struct BXEXPORT ProbeResult
36 Usb::DeviceIDType m_dev;
37 unsigned char m_interface;
38 Barry::Pin m_pin;
39 Usb::EndpointPair m_ep;
40 Usb::EndpointPair m_epModem;
41 // Specifies if it's necessary to clear halt on the
42 // endpoints before using them. On some devices such
43 // as the 8830 it's essential to clear halt. On other
44 // devices such as the Curve 8520 calling clear halt
45 // can cause them to get into a state where they drop
46 // packets.
47 bool m_needClearHalt;
48 // Specifies if it's necessary to call usb_set_altinterface()
49 // before attempting to use the end points for this device.
51 // This can help to re-synchronize the state between the USB
52 // host and the device. However it can also cause usb-storage
53 // URBs to be lost on some device, so it's only used as a
54 // last resort.
55 bool m_needSetAltInterface;
56 uint8_t m_zeroSocketSequence;
57 std::string m_description;
59 // data from a possible ConfigFile (filled in automatically by
60 // the probe code if available)
61 std::string m_cfgDeviceName;
63 ProbeResult()
64 : m_dev(0), m_interface(0), m_pin(0)
65 , m_needClearHalt(false), m_needSetAltInterface(false)
66 , m_zeroSocketSequence(0)
68 void DumpAll(std::ostream &os) const;
69 bool HasIpModem() const { return m_epModem.IsComplete(); }
71 bool operator==(const Barry::Pin &pin) const
73 return m_pin == pin;
77 BXEXPORT std::ostream& operator<< (std::ostream &os, const ProbeResult &pr);
80 class BXEXPORT Probe
82 public:
83 typedef std::vector<ProbeResult> Results;
85 private:
86 Results m_results;
88 std::vector<std::string> m_fail_msgs;
89 int m_fail_count;
91 bool m_epp_override;
92 Usb::EndpointPair m_epp;
94 BXLOCAL bool CheckSize(const Data &data, unsigned int required);
95 BXLOCAL bool ParsePIN(const Data &data, uint32_t &pin);
96 BXLOCAL bool ParseDesc(const Data &data, std::string &desc);
98 protected:
99 void ProbeMatching(int vendor, int product,
100 const char *busname, const char *devname);
101 void ProbeDevice(Usb::DeviceIDType devid);
102 void ProbeDeviceEndpoints(Usb::Device &dev, Usb::EndpointDiscovery &ed, ProbeResult &result);
103 bool ProbePair(Usb::Device &dev, const Usb::EndpointPair &ep,
104 uint32_t &pin, std::string &desc, uint8_t &zeroSocketSequence,
105 bool &needClearHalt);
106 bool ProbeModem(Usb::Device &dev, const Usb::EndpointPair &ep);
108 public:
109 Probe(const char *busname = 0, const char *devname = 0,
110 const Usb::EndpointPair *epp = 0);
112 const Results& GetResults() const { return m_results; }
114 int GetCount() const { return m_results.size(); }
115 int GetFailCount() const { return m_fail_count; }
117 const std::string& GetFailMsg(int index) const { return m_fail_msgs[index]; }
118 const ProbeResult& Get(int index) const { return m_results[index]; }
120 int FindActive(Barry::Pin pin = 0) const; // returns -1 if pin not found
121 // or if no devices
122 static int FindActive(const Results &results, Barry::Pin pin = 0);
123 static int Find(const Results &results, Barry::Pin pin = 0);
127 } // namespace Barry
129 #endif