gloox  1.0.20
bytestream.h
1 /*
2  Copyright (c) 2006-2017 by Jakob Schröter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 #ifndef BYTESTREAM_H__
15 #define BYTESTREAM_H__
16 
17 #include "jid.h"
18 #include "logsink.h"
19 
20 #include <string>
21 
22 namespace gloox
23 {
24 
25  class BytestreamDataHandler;
26 
36  class GLOOX_API Bytestream
37  {
38  public:
43  {
44  S5B,
45  IBB
46  };
47 
56  Bytestream( StreamType type, LogSink& logInstance, const JID& initiator, const JID& target,
57  const std::string& sid )
58  : m_handler( 0 ), m_logInstance( logInstance ), m_initiator( initiator ), m_target( target ),
59  m_type( type ), m_sid( sid ), m_open( false )
60  {}
61 
65  virtual ~Bytestream() {}
66 
72  bool isOpen() const { return m_open; }
73 
83  virtual bool connect() = 0;
84 
88  virtual void close() = 0;
89 
99  virtual bool send( const std::string& data ) = 0;
100 
108  virtual ConnectionError recv( int timeout = -1 ) = 0;
109 
114  const std::string& sid() const { return m_sid; }
115 
120  StreamType type() const { return m_type; }
121 
127  const JID& target() const { return m_target; }
128 
134  const JID& initiator() const { return m_initiator; }
135 
143  { m_handler = bdh; }
144 
149  { m_handler = 0; }
150 
151  protected:
154 
157 
160 
162  const JID m_target;
163 
166 
168  std::string m_sid;
169 
171  bool m_open;
172 
173  private:
174  Bytestream& operator=( const Bytestream& );
175 
176  };
177 
178 }
179 
180 #endif // BYTESTREAM_H__
std::string m_sid
Definition: bytestream.h:168
Bytestream(StreamType type, LogSink &logInstance, const JID &initiator, const JID &target, const std::string &sid)
Definition: bytestream.h:56
void registerBytestreamDataHandler(BytestreamDataHandler *bdh)
Definition: bytestream.h:142
BytestreamDataHandler * m_handler
Definition: bytestream.h:153
const std::string & sid() const
Definition: bytestream.h:114
const LogSink & m_logInstance
Definition: bytestream.h:156
ConnectionError
Definition: gloox.h:683
void removeBytestreamDataHandler()
Definition: bytestream.h:148
bool isOpen() const
Definition: bytestream.h:72
The namespace for the gloox library.
Definition: adhoc.cpp:27
A virtual interface that allows implementors to receive data sent over a SOCKS5 Bytestream as defined...
const JID & initiator() const
Definition: bytestream.h:134
StreamType m_type
Definition: bytestream.h:165
const JID & target() const
Definition: bytestream.h:127
An abstraction of a JID.
Definition: jid.h:30
StreamType type() const
Definition: bytestream.h:120
virtual ~Bytestream()
Definition: bytestream.h:65
const JID m_initiator
Definition: bytestream.h:159
An abstraction of a single bytestream.
Definition: bytestream.h:36
const JID m_target
Definition: bytestream.h:162
An implementation of log sink and source.
Definition: logsink.h:38