Fixing readings over stdin not working. Connection still isn't 100% reliable yet...
[barry.git] / src / m_raw_socket.h
blob266bbe0f70459a0260b79ea3b153e1e052d81795
1 ///
2 /// \file m_raw_socket.h
3 /// Mode class for a raw socket
4 ///
6 /*
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_SOCKET_H__
24 #define __BARRY_M_RAW_SOCKET_H__
26 #include "dll.h"
27 #include "m_mode_base.h"
28 #include "socket.h"
30 namespace Barry {
32 namespace Mode {
34 // Callback from the raw socket.
36 class BXEXPORT RawSocketDataCallback
38 public:
39 virtual void DataReceived(Data& data) = 0;
40 virtual ~RawSocketDataCallback() {};
43 #define RAW_SOCKET_HEADER_SIZE 4
44 #define RAW_SOCKET_MAXIMUM_PACKET_SIZE 16384
45 #define RAW_SOCKET_MAXIMUM_PACKET_CONTENTS_SIZE (RAW_SOCKET_MAXIMUM_PACKET_SIZE - RAW_SOCKET_HEADER_SIZE)
48 // Raw socket class
50 /// The main class for creating a raw socket session.
51 ///
52 /// To use this class, use the following steps:
53 ///
54 /// - Implement RawSocketDataCallback
55 /// - Create a Controller object (see Controller class for more details)
56 /// - Create this Mode::RawSocket object, passing in the Controller
57 /// object during construction
58 /// - Call Open() to open database socket and finish constructing.
59 /// - Call GetData() to fetch data
60 /// - Call SendData() to send data
61 ///
62 class BXEXPORT RawSocket : public Mode
64 public:
65 RawSocket(Controller &con, RawSocketDataCallback& callback);
66 ~RawSocket();
68 //////////////////////////////////
69 // Raw Socket mode specific methods
71 // Send some data on the raw socket
72 // Will throw an error if data is longer than
73 // RAW_SOCKET_MAXIMUM_PACKET_CONTENTS_SIZE
74 void Send(Data& data);
76 void HandleReceivedData(Data& data);
78 void OnOpen();
80 private:
81 RawSocketDataCallback& Callback;
82 unsigned char m_sendBuffer[RAW_SOCKET_MAXIMUM_PACKET_SIZE];
86 }} // namespace Barry::Mode
88 #endif