-
Notifications
You must be signed in to change notification settings - Fork 17
/
dbus_service.cpp
56 lines (50 loc) · 1.33 KB
/
dbus_service.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
#include <QStringList>
#include <veutil/qt/ve_qitem.hpp>
#include "dbus_service.h"
#include "QsLog.h"
DBusService::DBusService(VeQItem *serviceRoot, QObject *parent) :
QObject(parent),
mServiceRoot(serviceRoot),
mDeviceInstance(serviceRoot->itemGetOrCreate("/DeviceInstance"))
{
connect(mDeviceInstance, SIGNAL(valueChanged(QVariant)),
this, SLOT(onDeviceInstanceChanged()));
mDeviceInstance->getValue();
}
VeQItem *DBusService::getItem(const QString &path)
{
VeQItem *item = mItems.value(path);
if (item != 0)
return item;
item = mServiceRoot->itemGetOrCreate(path);
mItems[path] = item;
return item;
}
QString DBusService::getDeviceType(const QString &name)
{
QStringList elements = name.split(".");
if (elements.count() < 3)
return "Unknown";
return elements[2];
}
void DBusService::onDeviceInstanceChanged()
{
switch (mDeviceInstance->getState()) {
case VeQItem::Synchronized:
QLOG_INFO() << QString("[DBusService] Service online: %1 (%2)").
arg(mServiceRoot->id()).
arg(mDeviceInstance->getValue().toInt());
break;
case VeQItem::Offline:
QLOG_INFO() << QString("[DBusService] Service offline: %1 (%2)").
arg(mServiceRoot->id()).
arg(mDeviceInstance->getValue().toInt());
break;
default:
break;
}
}
bool DBusService::getConnected()
{
return mServiceRoot->getState() != VeQItem::Offline;
}