~autopilot/autopilot-qt/1.4

« back to all changes in this revision

Viewing changes to driver/rootnode.cpp

  • Committer: Tarmac
  • Author(s): Thomi Richards
  • Date: 2013-09-16 19:29:53 UTC
  • mfrom: (70.1.15 experimental)
  • Revision ID: tarmac-20130916192953-gfi8t8ot60cvm4ea
1.4 wire protocol changes. Fixes: https://bugs.launchpad.net/bugs/1195141, https://bugs.launchpad.net/bugs/1214128.

Approved by PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include "rootnode.h"
 
2
#include "introspection.h"
2
3
 
3
4
#include <QObject>
4
5
#include <QCoreApplication>
5
6
#include <QStringList>
 
7
#include <QDebug>
6
8
 
7
9
RootNode::RootNode(QCoreApplication* application)
8
 
    : QtNode(application, std::string())
 
10
    : QtNode(application)
9
11
    , application_(application)
10
12
{
11
13
}
12
14
 
13
 
QVariant RootNode::IntrospectNode() const
 
15
 
 
16
NodeIntrospectionData RootNode::GetIntrospectionData() const
14
17
{
15
 
    // return must be (name, state_map)
16
 
    QString object_name = QString::fromStdString(GetPath());
 
18
    NodeIntrospectionData data;
 
19
    data.object_path = QString::fromStdString(GetPath());
 
20
    data.state = GetNodeProperties(application_);
17
21
    QStringList child_names;
18
22
    foreach(QObject* child, children_)
19
23
    {
20
24
        child_names.append(child->metaObject()->className());
21
25
    }
22
26
 
23
 
    QVariantMap object_properties;
24
 
    object_properties["Children"] = child_names;
25
 
    object_properties["id"] = GetObjectId();
26
 
    QList<QVariant> object_tuple = { QVariant(object_name), QVariant(object_properties) };
27
 
    return QVariant(object_tuple);
28
 
}
29
 
 
30
 
qint64 RootNode::GetObjectId() const
31
 
{
32
 
    return 1;
 
27
    data.state["Children"] = PackProperty(child_names);
 
28
    data.state["id"] = PackProperty(GetId());
 
29
    return data;
33
30
}
34
31
 
35
32
void RootNode::AddChild(QObject* child)
48
45
    return "/" + GetName();
49
46
}
50
47
 
51
 
bool RootNode::MatchProperty(const std::string& name, const std::string& value) const
52
 
{
53
 
    if (name == "id")
54
 
        return QString::fromStdString(value).toLongLong() == GetObjectId();
55
 
 
56
 
    return false;
57
 
}
58
 
 
59
 
xpathselect::NodeList RootNode::Children() const
60
 
{
61
 
    xpathselect::NodeList children;
 
48
xpathselect::NodeVector RootNode::Children() const
 
49
{
 
50
    xpathselect::NodeVector children;
62
51
    foreach(QObject* child, children_)
63
 
        children.push_back(std::make_shared<QtNode>(child, GetPath()));
 
52
        children.push_back(std::make_shared<QtNode>(child, shared_from_this()));
64
53
    return children;
65
54
}