desktop: po: added copyright for Nicolas CARRIER to fr.po
[barry.git] / tools / brawchannel.h
bloba3a9910fd421c3fd4c4fb3ddeac235043518ba92
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>
29 #include <string>
31 // How long, in seconds, to wait between reads before checking if should shutdown
32 #define READ_TIMEOUT_SECONDS 1
34 /* Defined generic stream reading and writing classes.
36 * It'd be great to use iostream, but they don't provide non-blocking reads.
38 class Stream {
39 public:
40 virtual ~Stream() {};
43 class InputStream {
44 public:
45 virtual ~InputStream() {};
46 virtual ssize_t read(unsigned char* ptr, size_t size, int timeout) = 0;
49 class OutputStream {
50 public:
51 virtual ~OutputStream() {};
52 virtual ssize_t write(const unsigned char* ptr, size_t size) = 0;
55 class StdOutStream : public OutputStream {
56 public:
57 virtual ssize_t write(const unsigned char* ptr, size_t size);
60 class StdInStream : public InputStream {
61 public:
62 virtual ssize_t read(unsigned char* ptr, size_t size, int timeout);
65 // Forward declaration of platform implementation details
66 struct TcpStreamImpl;
68 class TcpStream : public Stream {
69 public:
70 std::auto_ptr<TcpStreamImpl> mImpl;
71 public:
72 TcpStream(const std::string& addr, long port);
73 ~TcpStream();
74 bool accept();
77 class TcpInStream : public InputStream {
78 private:
79 TcpStream& mStream;
80 public:
81 TcpInStream(TcpStream& stream)
82 : mStream(stream) {}
83 virtual ssize_t read(unsigned char* ptr, size_t size, int timeout);
86 class TcpOutStream : public OutputStream {
87 private:
88 TcpStream& mStream;
89 public:
90 TcpOutStream(TcpStream& stream)
91 : mStream(stream) {}
92 public:
93 virtual ssize_t write(const unsigned char* ptr, size_t size);
96 #endif // __BARRY_TOOLS_BRAWCHANNEL_H__