aboutsummaryrefslogtreecommitdiffstats
path: root/app/dbus_client.cpp
blob: 62dde46c351badeb1f2dbb3d1c977f362338b8fb (plain)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "dbus_client.h"

dbus_client::dbus_client(const QString &pathName,
                         const QString &objName,
                         const QString &serverName,
                         QObject *parent) :
  m_serverName(serverName),
  m_pathName(pathName + serverName),
  m_objName(objName + serverName)
{
    // DBus & api init
    initDBus();
    initAPIs(parent);
}

dbus_client::~dbus_client(){}

void dbus_client::initDBus(){

    new NaviapiAdaptor(this);

    // connect session to navigation service(add route info)
    if (!QDBusConnection::sessionBus().connect(
                QString(),
                QString(),
                m_pathName,
                "signalRouteInfo",
                this,
                SLOT(addRoutePointsSlot(double, double, double, double)))) {	//slot
        qWarning() << m_serverName << "sessionBus.connect(): signalRouteInfo failed";
    }

    // connect session to navigation service(current postion info)
    if (!QDBusConnection::sessionBus().connect(
                QString(),
                QString(),
                m_pathName,
                "signalPosInfo",
                this,
                SLOT(positionSlot(double, double, double, double)))) {	//slot
        qWarning() << m_serverName << "sessionBus.connect(): signalPosInfo failed";
    }

    // connect session to navigation service(when demo stopped)
    if (!QDBusConnection::sessionBus().connect(
                QString(),
                QString(),
                m_pathName,
                "signalStopDemo",
                this,
                SLOT(stopdemoSlot()))) {	//slot
        qWarning() << m_serverName << "sessionBus.connect(): signalStopDemo failed";
    }

    // connect session to navigation service(when arrived destination)
    if (!QDBusConnection::sessionBus().connect(
                QString(),
                QString(),
                m_pathName,
                "signalArrived",
                this,
                SLOT(arrivedestSlot()))) {	//slot
        qWarning() << m_serverName << "sessionBus.connect(): signalArrived failed";
    }
}

void dbus_client::initAPIs(QObject *parent){
    // connect the signal to qml inside function(addRoutePointsQml -> do_addRoutePoint)
    if(!QObject::connect(this, SIGNAL(addRoutePointsQml(QVariant, QVariant, QVariant, QVariant)),
                         parent, SLOT(do_addRoutePoint(QVariant, QVariant, QVariant, QVariant)))) {
        qWarning() << m_serverName << "SIGNAL:addRoutePointsQml to qmlSLOT:do_addRoutePoint connect failed";
    }

    // connect the signal to qml inside function(positionQml -> do_setCoordinate)
    if(!QObject::connect(this, SIGNAL(positionQml(QVariant, QVariant,QVariant, QVariant)),
                         parent, SLOT(do_setCoordinate(QVariant, QVariant,QVariant, QVariant)))) {
        qWarning() << m_serverName << "SIGNAL:positionQml to qmlSLOT:do_setCoordinate connect failed";
    }

    // connect the signal to qml inside function(stopdemoQml -> do_stopnavidemo)
    if(!QObject::connect(this, SIGNAL(stopdemoQml()),
                         parent, SLOT(do_stopnavidemo()))) {
        qWarning() << m_serverName << "SIGNAL:stopdemoQml to qmlSLOT:do_stopnavidemo connect failed";
    }

    // connect the signal to qml inside function(arrivedestQml -> do_arrivedest)
    if(!QObject::connect(this, SIGNAL(arrivedestQml()),
                         parent, SLOT(do_arrivedest()))) {
        qWarning() << m_serverName << "SIGNAL:arrivedestQml to qmlSLOT:do_arrivedest connect failed";
    }
}

// Signal&&Method
// addRoutePointsSlot -> addRoutePointsQml(use for qml)
void dbus_client::addRoutePointsSlot(double route_Lat_s, double route_Lon_s, double route_Lat_e, double route_Lon_e)
{
    emit addRoutePointsQml(route_Lat_s, route_Lon_s, route_Lat_e, route_Lon_e);
}

// positionSlot -> positionQml(use for qml)
void dbus_client::positionSlot(double cur_Lat_p, double cur_Lon_p,double cur_direction, double cur_distance)
{
    emit positionQml(cur_Lat_p, cur_Lon_p,cur_direction,cur_distance);
}

// stopdemoSlot -> stopdemoQml(use for qml)
void dbus_client::stopdemoSlot()
{
    emit stopdemoQml();
}

// arrivedestSlot -> arrivedestQml(use for qml)
void dbus_client::arrivedestSlot()
{
    emit arrivedestQml();
}