summaryrefslogtreecommitdiff
path: root/hostmanageragent.cc
blob: 7ed890dfbfe9206a4178cf09da0eefbd4550cd00 (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
#include "sapsocket.h"
#include "sapconnectionrequest.h"
#include "sapserviceinfo.h"
#include "sapchannelinfo.h"
#include "hostmanagerconn.h"
#include "hostmanageragent.h"

static HostManagerAgent *agent = 0;
static const QLatin1String hostmanager_profile("/system/hostmanager");

HostManagerAgent::HostManagerAgent(QObject *parent)
    : QObject(parent), _peer(0), _socket(0)
{
}

HostManagerAgent* HostManagerAgent::instance()
{
	if (!agent) {
		agent = new HostManagerAgent;
	}
	return agent;
}

void HostManagerAgent::peerFound(SAPPeer *peer)
{
	qDebug() << "Host manager peer found" << peer->peerName();
}

void HostManagerAgent::requestConnection(SAPConnectionRequest *request)
{
	qDebug() << "Host manager request connection from" << request->peer()->peerName();
	SAPConnection *conn = request->connection();
	new HostManagerConn(conn, this);

	request->accept();
}

void HostManagerAgent::registerServices(SAPManager *manager)
{
	SAPServiceInfo service;
	SAPChannelInfo channel;

	service.setProfile(hostmanager_profile);
	service.setFriendlyName("HostManager");
	service.setRole(SAPServiceInfo::RoleProvider);
	service.setVersion(1, 0);
	service.setConnectionTimeout(0);

	channel.setChannelId(103);
	channel.setPayloadType(SAPChannelInfo::PayloadJson);
	channel.setQoSType(SAPChannelInfo::QoSRestricted);
	channel.setQoSDataRate(SAPChannelInfo::QoSDataRateHigh);
	channel.setQoSPriority(SAPChannelInfo::QoSPriorityHigh);
	service.addChannel(channel);

	manager->registerServiceAgent(service, instance());
}