summaryrefslogtreecommitdiffstats
blob: 234c491df07774e619c1e57e09bc1578e378ae96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * Copyright (c) 2015 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#pragma once

#include <Swiften/Base/API.h>
#include <Swiften/Base/boost_bsignals.h>
#include <Swiften/FileTransfer/TransportSession.h>
#include <Swiften/FileTransfer/ReadBytestream.h>
#include <Swiften/FileTransfer/WriteBytestream.h>

namespace Swift {

template <typename T>
class SWIFTEN_API S5BTransportSession : public TransportSession {
	public:
		S5BTransportSession(
				boost::shared_ptr<T> session,
				boost::shared_ptr<ReadBytestream> readStream) :
					session(session),
					readStream(readStream) {
			initialize();
		}

		S5BTransportSession(
				boost::shared_ptr<T> session,
				boost::shared_ptr<WriteBytestream> writeStream) :
					session(session),
					writeStream(writeStream) {
			initialize();
		}

		virtual ~S5BTransportSession() {
		}

		virtual void start() SWIFTEN_OVERRIDE {
			if (readStream) {
				session->startSending(readStream);
			}
			else {
				session->startReceiving(writeStream);
			}
		}

		virtual void stop() SWIFTEN_OVERRIDE {
			session->stop();
		}

	private:
		void initialize() {
			finishedConnection = session->onFinished.connect(boost::bind(boost::ref(onFinished), _1));
			bytesSentConnection = session->onBytesSent.connect(boost::bind(boost::ref(onBytesSent), _1));
		}

	private:
		boost::shared_ptr<T> session;
		boost::shared_ptr<ReadBytestream> readStream;
		boost::shared_ptr<WriteBytestream> writeStream;

		boost::bsignals::scoped_connection finishedConnection;
		boost::bsignals::scoped_connection bytesSentConnection;
};

}