summaryrefslogtreecommitdiffstats
blob: 54bb22d97d4a15cf776e205e49f314156a9e2cb1 (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) 2010 Remko Tronçon
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */

#pragma once

#include <boost/shared_ptr.hpp>
#include "Swiften/Base/boost_bsignals.h"
#include <boost/noncopyable.hpp>

#include <Swiften/StreamStack/HighLayer.h>
#include "Swiften/Base/ByteArray.h"
#include "Swiften/Elements/Element.h"
#include "Swiften/Elements/StreamType.h"
#include "Swiften/Parser/XMPPParserClient.h"

namespace Swift {
	class ProtocolHeader;
	class XMPPParser;
	class PayloadParserFactoryCollection;
	class XMPPSerializer;
	class PayloadSerializerCollection;

	class XMPPLayer : public XMPPParserClient, public HighLayer, boost::noncopyable {
		public:
			XMPPLayer(
					PayloadParserFactoryCollection* payloadParserFactories,
					PayloadSerializerCollection* payloadSerializers,
					StreamType streamType);
			~XMPPLayer();

			void writeHeader(const ProtocolHeader& header);
			void writeFooter();
			void writeElement(boost::shared_ptr<Element>);
			void writeData(const String& data);

			void resetParser();

		private:
			void handleDataRead(const ByteArray& data);
			void writeDataInternal(const ByteArray& data);

		public:
			boost::signal<void (const ProtocolHeader&)> onStreamStart;
			boost::signal<void (boost::shared_ptr<Element>)> onElement;
			boost::signal<void (const ByteArray&)> onWriteData;
			boost::signal<void (const ByteArray&)> onDataRead;
			boost::signal<void ()> onError;

		private:
			void handleStreamStart(const ProtocolHeader&);
			void handleElement(boost::shared_ptr<Element>);
			void handleStreamEnd();

			void doResetParser();

		private:
			PayloadParserFactoryCollection* payloadParserFactories_;
			XMPPParser* xmppParser_;
			PayloadSerializerCollection* payloadSerializers_;
			XMPPSerializer* xmppSerializer_;
			bool resetParserAfterParse_;
			bool inParser_;
	};
}