3 /// Class wrapper to encapsulate the Blackberry USB logical socket
7 Copyright (C) 2005-2006, 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_SOCKET_H__
23 #define __BARRY_SOCKET_H__
27 // forward declarations
29 namespace Usb
{ class Device
; }
36 /// Encapsulates a "logical socket" in the Blackberry USB protocol.
37 /// By default, provides raw send/receive access, as well as packet
38 /// writing on socket 0, which is always open.
40 /// There are Open and Close members to open data sockets which are used
41 /// to transfer data to and from the device.
43 /// The destructor will close any non-0 open sockets automatically.
45 /// Requires an active Usb::Device object to work on.
50 int m_writeEp
, m_readEp
;
51 uint16_t m_socket
; // defaults to 0, which is valid,
52 // since socket 0 is always open
53 // If this is not 0, then class will
54 // deal with closing automatically.
56 uint32_t m_sequenceId
;
61 // sends 'send' data to device, and waits for response, using
62 // "read first, write second" order observed in capture
63 void AppendFragment(Data
&whole
, const Data
&fragment
);
64 unsigned int MakeNextFragment(const Data
&whole
, Data
&fragment
, unsigned int offset
= 0);
65 void CheckSequence(const Data
&seq
);
68 Socket(Usb::Device
&dev
, int writeEndpoint
, int readEndpoint
);
71 int GetLastStatus() const { return m_lastStatus
; }
72 uint16_t GetSocket() const { return m_socket
; }
74 void Open(uint16_t socket
, uint8_t flag
);
77 // Send and Receive are available before Open...
78 // an unopened socket defaults to socket 0, which you need
79 // in order to set the blackberry mode
80 bool Send(const Data
&send
, Data
&receive
);
81 bool Receive(Data
&receive
);
83 // sends the send packet down to the device, fragmenting if
84 // necessary, and returns the response in receive, defragmenting
86 // Blocks until response received or timed out in Usb::Device
87 bool Packet(const Data
&send
, Data
&receive
);
89 // some handy wrappers for the Packet() interface
90 bool NextRecord(Data
&receive
);