2 /// \file m_raw_channel.h
3 /// Mode class for a raw channel
7 Copyright (C) 2005-2010, Net Direct Inc. (http://www.netdirect.ca/)
8 Portions Copyright (C) 2010 RealVNC Ltd.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 See the GNU General Public License in the COPYING file at the
20 root directory of this project for more details.
23 #ifndef __BARRY_M_RAW_CHANNEL_H__
24 #define __BARRY_M_RAW_CHANNEL_H__
27 #include "m_mode_base.h"
39 // Callback from the raw channel.
41 class BXEXPORT RawChannelDataCallback
44 // Called when data has been received on the channel
45 virtual void DataReceived(Data
& data
) = 0;
46 // Called when the channel has an error
47 virtual void ChannelError(std::string msg
) = 0;
48 // Called when the channel has been asked to close by the other side
49 virtual void ChannelClose() = 0;
55 /// The main class for creating a raw channel session.
57 /// To use this class, use the following steps:
59 /// - Implement RawChannelDataCallback
60 /// - Create a Controller object (see Controller class for more details)
61 /// - Create this Mode::RawChannel object, passing in the Controller
62 /// object during construction
63 /// - Call Open() to open the channel and finish constructing.
64 /// - Call GetData() to fetch data
65 /// - Call SendData() to send data
67 class BXEXPORT RawChannel
: public Mode
69 // Mutex for signalling between read and write threads
70 pthread_mutex_t m_mutex
;
72 // Condvar for signalling between read and write threads
76 semaphore
* m_semaphore
;
77 RawChannelDataCallback
& m_callback
;
78 unsigned char *m_sendBuffer
;
79 bool m_zeroRegistered
;
82 void UnregisterZeroSocketInterest();
85 RawChannel(Controller
&con
, RawChannelDataCallback
& callback
);
86 virtual ~RawChannel();
88 //////////////////////////////////
89 // Raw channel mode specific methods
91 // Send some data on the raw channel.
92 // Will throw a Barry::Error if data is longer than
93 // MaximumPacketContentsSize or a Barry::Usb::Error if there
94 // is an underlying USB error.
95 void Send(Data
& data
, int timeout
= -1);
97 // Returns the maximum quantity of data which
99 size_t MaximumSendSize();
101 // Not intended for use by users of this class.
102 // Instead data received will come in via the
103 // RawChannelDataCallback::DataReceived callback.
104 void HandleReceivedData(Data
& data
);
106 // Not intended for use by users of this class.
107 // This method is called by the internals of
108 // Barry when setting up a connection.
112 }} // namespace Barry::Mode