summaryrefslogtreecommitdiff
path: root/sappeer.h
blob: 5e565dba12f591a4bd8de295b9505acdfafb66b9 (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
#ifndef SAPPEER_H
#define SAPPEER_H

#include <QtCore/QObject>
#include <QtCore/QQueue>

#include "saprotocol.h"
#include "sapserviceinfo.h"

class WMSPeer;
class CapabilityPeer;
class SAPConnection;
class SAPConnectionRequest;
class SAPSocket;
class SAPAgent;

class SAPPeer : public QObject
{
	Q_OBJECT
public:
	explicit SAPPeer(SAProtocol::Role role, const QString &localName, const QString &peerName, QObject *parent = 0);

	SAPConnection* createServiceConnection(const QString &profile, const QString &requesterProfile, SAPServiceInfo::Role requesterRole);

	SAProtocol::Role role() const;
	QString localName() const;
	QString peerName() const;

signals:
	void connected();
	void disconnected();

protected:
	/** Transmits a frame to the underlying transport. */
	virtual void sendFrame(const QByteArray &data) = 0;

	CapabilityPeer *capabilityPeer();

	/** Writes data to the remote. */
	bool writeToSession(int session, const QByteArray &data);

	void acceptServiceConnection(SAPConnectionRequest *connReq, int statusCode);

	/** Distributes data to the appropiate socket. */
	void handleSessionData(int session, const QByteArray &data);

	/** Perform service discovery once connected. */
	void handleConnected();
	void handleDisconnected();

private:
	int findUnusedSessionId() const;
	void handleDefaultSessionMessage(const QByteArray &message);

protected:
	WMSPeer *_wms;

private:
	const SAProtocol::Role _role;
	const QString _localName;
	const QString _peerName;

	QMap<int, SAPSocket*> _sessions;

	friend class SAPSocket;
	friend class SAPConnectionRequest;
};

#endif // SAPPEER_H