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
|
#include "ambqt.h"
#include <QDBusConnection>
#include <QDBusInterface>
#include <QtDebug>
#include <QDBusReply>
AmbProperty::AmbProperty(QString op, QString iface, QString propName)
:QObject(), mPropertyName(propName),mInterfaceName(iface), mObjectPath(op),mDBusInterface(NULL),mZone(0)
{
connect();
}
void AmbProperty::propertyChangedSlot(QString, QVariantMap values, QVariantMap )
{
valueChanged(values);
}
void AmbProperty::propertyChanged1(QDBusVariant val, double t)
{
mTime = t;
mValue = val.variant();
signalChanged(mValue);
}
void AmbProperty::connect()
{
if(mDBusInterface)
{
delete mDBusInterface;
}
if(mObjectPath.isEmpty())
getObjectPath();
if(mInterfaceName.isEmpty())
mInterfaceName = "org.automotive."+mPropertyName;
mDBusInterface = new QDBusInterface("org.automotive.message.broker",objectPath(), interfaceName(), QDBusConnection::systemBus(),this);
if(!mDBusInterface->isValid())
{
qDebug()<<"Failed to create dbus interface for property "<<propertyName();
qDebug()<<"Path: "<<objectPath();
qDebug()<<"Interface: "<<interfaceName();
qDebug()<<"Error: "<<QDBusConnection::systemBus().lastError().message();
}
QString signalName = propertyName() + "Changed";
if(!QDBusConnection::systemBus().connect("org.automotive.message.broker", objectPath(), "org.freedesktop.DBus.Properties",
"PropertiesChanged", this, SLOT(propertyChangedSlot(QString,QVariantMap,QVariantMap))))
{
qDebug()<<"Failed to connect to signal";
qDebug()<<"path: "<<objectPath();
qDebug()<<"interface: "<<interfaceName();
qDebug()<<"signal: "<<propertyName();
qDebug()<<"Error: "<<QDBusConnection::systemBus().lastError().message();
}
///TODO: only use PropertiesChanged... treat AmbProperty like an object rather than a representation of just a single property in the object
if(!QDBusConnection::systemBus().connect("org.automotive.message.broker", objectPath(), mInterfaceName,
signalName, this, SLOT(propertyChanged1(QDBusVariant,double))))
{
qDebug()<<"Failed to connect to signal";
qDebug()<<"path: "<<objectPath();
qDebug()<<"interface: "<<interfaceName();
qDebug()<<"signal: "<<propertyName();
qDebug()<<"Error: "<<QDBusConnection::systemBus().lastError().message();
}
}
void AmbProperty::getObjectPath()
{
QDBusInterface managerIface("org.automotive.message.broker","/","org.automotive.Manager", QDBusConnection::systemBus(), this);
if(!managerIface.isValid())
{
qDebug()<<"Failed to create manager interface";
return;
}
QDBusReply<QDBusObjectPath> reply = managerIface.call("FindObjectForZone", mPropertyName, mZone);
if(reply.isValid())
{
mObjectPath = reply.value().path();
}
}
|