-
Notifications
You must be signed in to change notification settings - Fork 0
/
BlueToothMidwareDBusRegistant.cpp
59 lines (57 loc) · 1.59 KB
/
BlueToothMidwareDBusRegistant.cpp
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
#include "BlueToothMidwareDBusRegistant.h"
BlueToothMidwareDBusRegistant *BlueToothMidwareDBusRegistant::m_instance = nullptr;
BlueToothMidwareDBusRegistant* BlueToothMidwareDBusRegistant::getInstance()
{
fprintf(stderr, "bluetooth getInstance\n");
if (!m_instance)
{
m_instance = new BlueToothMidwareDBusRegistant();
if (!m_instance->connectDBus())
{
delete m_instance;
m_instance = nullptr;
}
}
return m_instance;
}
#include "TcBtMusicConvertor.h"
#include "TcBtPhoneConvertor.h"
#include <QtDBus>
BlueToothMidwareDBusRegistant::BlueToothMidwareDBusRegistant() :
QObject(),
m_btmusic(TcBtMusicConvertor::getIntance()),
m_btphone(TcBtPhoneConvertor::getInstance())
{
}
BlueToothMidwareDBusRegistant::~BlueToothMidwareDBusRegistant()
{
m_instance = nullptr;
}
bool BlueToothMidwareDBusRegistant::connectDBus()
{
auto dbus = getDBusConnection();
auto registerObject = [&dbus](QObject* convertor) -> bool {
return dbus.registerObject(DBUS_BLUETOOTH_MIDWARE_OBJECT_PATH + convertor->property("interfaceClassName").toString(), convertor);
};
if(!dbus.registerService(DBUS_BLUETOOTH_MIDWARE_BUS_NAME))
{
qDebug() << dbus.lastError();
}
else if(!registerObject(m_btmusic))
{
qDebug() << dbus.lastError();
}
else if(!registerObject(m_btphone))
{
qDebug() << dbus.lastError();
}
else
{
return true;
}
return false;
}
inline QDBusConnection BlueToothMidwareDBusRegistant::getDBusConnection() const
{
return QDBusConnection::systemBus();
}