Updated .gitignore for the barry18 -> barry19 symlink
[barry.git] / tools / brawchannel.h
blob3293ef88da311fecb05d526aadabe11ee5c64f48
1 ///
2 /// \file brawchannel.h
3 /// Directs a named raw channel over STDIN/STDOUT or TCP
4 ///
6 /*
7 Copyright (C) 2010-2012, RealVNC Ltd.
9 Some parts are inspired from bjavaloader.cc
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 See the GNU General Public License in the COPYING file at the
21 root directory of this project for more details.
24 #ifndef __BARRY_TOOLS_BRAWCHANNEL_H__
25 #define __BARRY_TOOLS_BRAWCHANNEL_H__
27 #include <sys/types.h>
28 #include <memory>
30 // How long, in seconds, to wait between reads before checking if should shutdown
31 #define READ_TIMEOUT_SECONDS 1
33 /* Defined generic stream reading and writing classes.
35 * It'd be great to use iostream, but they don't provide non-blocking reads.
37 class Stream {
38 public:
39 virtual ~Stream() {};
42 class InputStream {
43 public:
44 virtual ~InputStream() {};
45 virtual ssize_t read(unsigned char* ptr, size_t size, int timeout) = 0;
48 class OutputStream {
49 public:
50 virtual ~OutputStream() {};
51 virtual ssize_t write(const unsigned char* ptr, size_t size) = 0;
54 class StdOutStream : public OutputStream {
55 public:
56 virtual ssize_t write(const unsigned char* ptr, size_t size);
59 class StdInStream : public InputStream {
60 public:
61 virtual ssize_t read(unsigned char* ptr, size_t size, int timeout);
64 // Forward declaration of platform implementation details
65 struct TcpStreamImpl;
67 class TcpStream : public Stream {
68 public:
69 std::auto_ptr<TcpStreamImpl> mImpl;
70 public:
71 TcpStream(const char * addr, long port);
72 ~TcpStream();
73 bool accept();
76 class TcpInStream : public InputStream {
77 private:
78 TcpStream& mStream;
79 public:
80 TcpInStream(TcpStream& stream)
81 : mStream(stream) {}
82 virtual ssize_t read(unsigned char* ptr, size_t size, int timeout);
85 class TcpOutStream : public OutputStream {
86 private:
87 TcpStream& mStream;
88 public:
89 TcpOutStream(TcpStream& stream)
90 : mStream(stream) {}
91 public:
92 virtual ssize_t write(const unsigned char* ptr, size_t size);
95 #endif // __BARRY_TOOLS_BRAWCHANNEL_H__