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
; }
30 namespace Barry
{ class Packet
; }
37 /// Encapsulates a "logical socket" in the Blackberry USB protocol.
38 /// By default, provides raw send/receive access, as well as packet
39 /// writing on socket 0, which is always open.
41 /// There are Open and Close members to open data sockets which are used
42 /// to transfer data to and from the device.
44 /// The destructor will close any non-0 open sockets automatically.
46 /// Requires an active Usb::Device object to work on.
51 int m_writeEp
, m_readEp
;
52 uint16_t m_socket
; // defaults to 0, which is valid,
53 // since socket 0 is always open
54 // If this is not 0, then class will
55 // deal with closing automatically.
57 uint32_t m_sequenceId
;
62 // sends 'send' data to device, and waits for response, using
63 // "read first, write second" order observed in capture
64 void AppendFragment(Data
&whole
, const Data
&fragment
);
65 unsigned int MakeNextFragment(const Data
&whole
, Data
&fragment
, unsigned int offset
= 0);
66 void CheckSequence(const Data
&seq
);
69 Socket(Usb::Device
&dev
, int writeEndpoint
, int readEndpoint
);
72 int GetLastStatus() const { return m_lastStatus
; }
73 uint16_t GetSocket() const { return m_socket
; }
75 void Open(uint16_t socket
, uint8_t flag
);
78 // Send and Receive are available before Open...
79 // an unopened socket defaults to socket 0, which you need
80 // in order to set the blackberry mode
81 bool Send(const Data
&send
, Data
&receive
);
82 bool Receive(Data
&receive
);
84 // sends the send packet down to the device, fragmenting if
85 // necessary, and returns the response in receive, defragmenting
87 // Blocks until response received or timed out in Usb::Device
88 bool Packet(const Data
&send
, Data
&receive
);
89 bool Packet(Barry::Packet
&packet
);
91 // some handy wrappers for the Packet() interface
92 bool NextRecord(Data
&receive
);