summaryrefslogtreecommitdiffstats
blob: 9a7ac1332de988c1e19e78d9aa992135955a3f81 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#pragma once

#include <boost/shared_ptr.hpp>
#include <boost/signal.hpp>
#include <boost/enable_shared_from_this.hpp>

#include "Swiften/JID/JID.h"
#include "Swiften/Elements/Element.h"
#include "Swiften/Network/Connection.h"
#include "Swiften/StreamStack/ConnectionLayer.h"

namespace Swift {
	class ProtocolHeader;
	class StreamStack;
	class JID;
	class Stanza;
	class ByteArray;
	class PayloadParserFactoryCollection;
	class PayloadSerializerCollection;
	class XMPPLayer;

	class LinkLocalSession : 
			public boost::enable_shared_from_this<LinkLocalSession> {
		public:
			LinkLocalSession(
					const JID& localJID,
					boost::shared_ptr<Connection> connection,
					PayloadParserFactoryCollection* payloadParserFactories, 
					PayloadSerializerCollection* payloadSerializers);
			virtual ~LinkLocalSession();

			void finishSession();

			// TODO: Make non-virtual when OutgoingSession is fixed
			virtual void sendStanza(boost::shared_ptr<Stanza>);

			virtual const JID& getRemoteJID() const = 0;

			virtual void start() = 0;

			boost::signal<void (boost::shared_ptr<Stanza>)> onStanzaReceived;
			boost::signal<void ()> onSessionFinished;
			boost::signal<void ()> onSessionStarted;
			boost::signal<void (const ByteArray&)> onDataWritten;
			boost::signal<void (const ByteArray&)> onDataRead;

		protected:
			void initializeStreamStack();

			const JID& getLocalJID() const {
				return localJID;
			}

			boost::shared_ptr<XMPPLayer> getXMPPLayer() const {
				return xmppLayer;
			}

			// TODO: Remove later
			void setConnection(boost::shared_ptr<Connection> c) {
				connection = c;
			}

			virtual void handleElement(boost::shared_ptr<Element>) = 0;
			virtual void handleStreamStart(const ProtocolHeader&) = 0;

			void setInitialized();
			bool isInitialized() const { return initialized; }

		private:
			void handleDisconnected(const boost::optional<Connection::Error>& error);

		private:
			JID localJID;
			PayloadParserFactoryCollection* payloadParserFactories;
			PayloadSerializerCollection* payloadSerializers;
			boost::shared_ptr<Connection> connection;
			boost::shared_ptr<XMPPLayer> xmppLayer;
			boost::shared_ptr<ConnectionLayer> connectionLayer;
			StreamStack* streamStack;
			bool initialized;
	};
}