summaryrefslogtreecommitdiff
path: root/notificationagent.cc
blob: 70358d0da3cc420e1aa6f59f9b9a397355f87ff5 (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 "notificationconn.h"
#include "notificationagent.h"

static NotificationAgent *agent = 0;
static const QLatin1String notification_profile("/system/NotificationService");

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

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

void NotificationAgent::peerFound(SAPPeer *peer)
{
	qDebug() << "Notification peer found" << peer->peerName();
}

void NotificationAgent::requestConnection(SAPConnectionRequest *request)
{
	qDebug() << "Notification request connection from" << request->peer()->peerName();
	SAPConnection *conn = request->connection();
	new NotificationConn(conn, this);

	request->accept();
}

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

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

	channel.setChannelId(104);
	channel.setPayloadType(SAPChannelInfo::PayloadBinary);
	channel.setQoSType(SAPChannelInfo::QoSReliabilityDisable);
	channel.setQoSDataRate(SAPChannelInfo::QoSDataRateLow);
	channel.setQoSPriority(SAPChannelInfo::QoSPriorityLow);
	service.addChannel(channel);

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