summaryrefslogtreecommitdiffstats
blob: 07b5b1cf133310ddf704821422470a63f8ad7d1d (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
#ifndef SWIFTEN_XMPPLAYER_H
#define SWIFTEN_XMPPLAYER_H

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

#include "Swiften/Base/ByteArray.h"
#include "Swiften/Elements/Element.h"
#include "Swiften/Parser/XMPPParserClient.h"

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

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

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

			void parseData(ByteArray data);
			void resetParser();

		public:
			boost::signal<void ()> 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();
			void handleElement(boost::shared_ptr<Element>);
			void handleStreamEnd();

			void doResetParser();

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

#endif