gloox  1.0
bytestream.h
1 /*
2  Copyright (c) 2006-2009 by Jakob Schroeter <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 
142  void registerBytestreamDataHandler( BytestreamDataHandler* bdh )
143  { m_handler = bdh; }
144 
148  void removeBytestreamDataHandler()
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__