-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBTTest.cpp
More file actions
100 lines (80 loc) · 2.73 KB
/
BTTest.cpp
File metadata and controls
100 lines (80 loc) · 2.73 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "BTTest.h"
#include <QDebug>
#include <QFile>
#include <QtDBus>
BTTest::BTTest(QObject *parent) :
QObject(parent)
{
}
quint32
BTTest::addServiceRecord ()
{
// Initialize dbus
QDBusInterface mgrIface ("org.bluez", "/", "org.bluez.Manager", QDBusConnection::systemBus ());
if (!mgrIface.isValid ())
{
qDebug () << "Unable to initialize bluez manager interface";
return -1;
}
QDBusReply<QDBusObjectPath> reply = mgrIface.call (QLatin1String ("DefaultAdapter"));
if (!reply.isValid ())
{
qDebug () << "Default adapter path not found";
return -1;
}
QString defaultAdapterPath = reply.value ().path ();
qDebug () << "Path:" << defaultAdapterPath;
QDBusInterface serviceIface ("org.bluez", defaultAdapterPath, "org.bluez.Service", QDBusConnection::systemBus() );
if(!serviceIface.isValid ())
{
qDebug () << "Could not find service interface: " << serviceIface.lastError ();
return -1;
}
// Read service record file
QFile file ("syncml_server_sdp_record.xml");
if (!file.open (QIODevice::ReadOnly))
{
qDebug () << "Service record file does not exist";
return -1;
}
QByteArray sdpRecord = file.readAll ();
file.close ();
QDBusReply<unsigned int> addResponse = serviceIface.call (QLatin1String ("AddRecord"), QLatin1String (sdpRecord));
if( !addResponse.isValid() )
{
qDebug () << "Could not add service record";
return -1;
}
qDebug () << "Service record successfully added with handle " << addResponse.value ();
return addResponse.value ();
}
void
BTTest::removeServiceRecord (quint32 recordHandle)
{
// Initialize dbus
QDBusInterface mgrIface ("org.bluez", "/", "org.bluez.Manager", QDBusConnection::systemBus ());
if (!mgrIface.isValid ())
{
qDebug () << "Unable to initialize bluez manager interface";
return ;
}
QDBusReply<QDBusObjectPath> reply = mgrIface.call (QLatin1String ("DefaultAdapter"));
if (!reply.isValid ())
{
qDebug () << "Default adapter path not found";
return ;
}
QString defaultAdapterPath = reply.value ().path ();
qDebug () << "Path:" << defaultAdapterPath;
QDBusInterface serviceIface ("org.bluez", defaultAdapterPath, "org.bluez.Service", QDBusConnection::systemBus() );
if(!serviceIface.isValid ())
{
qDebug () << "Could not find service interface: " << serviceIface.lastError ();
return ;
}
QDBusReply<void> response = serviceIface.call (QLatin1String ("RemoveRecord"), recordHandle);
if (!response.isValid ())
{
qDebug () << "Unable to remove service record";
}
}