summaryrefslogtreecommitdiffstats
path: root/app/dbus_server.cpp
blob: d83528e28cfc92642ca334a94b7426697115bfda (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include"dbus_server.h"
#include <QDebug>

DBus_Server::DBus_Server(const QString &pathName,
                         const QString &objName,
                         const QString &serverName,
                         QObject *parent) :
  m_serverName(serverName),
  m_pathName(pathName + serverName),
  m_objName(objName + serverName)
{
    initDBus();
    initAPIs(parent);
}
DBus_Server::~DBus_Server(){}

void DBus_Server::initDBus(){

    new NaviapiAdaptor(this);

    if (!QDBusConnection::sessionBus().registerService(m_pathName))
        qDebug() << m_pathName << "registerService() failed";

    if (!QDBusConnection::sessionBus().registerObject(m_objName, this))
        qDebug() << m_objName << "registerObject() failed";

    QDBusConnection	sessionBus = QDBusConnection::connectToBus(QDBusConnection::SessionBus, m_serverName);
    if (!sessionBus.isConnected()) {
        qDebug() << m_serverName << "connectToBus() failed";
    }

    //for receive dbus signal
    org::agl::naviapi *mInterface;
    mInterface = new org::agl::naviapi(QString(),QString(),QDBusConnection::sessionBus(),this);
    if (!connect(mInterface,SIGNAL(getRouteInfo()),this,SLOT(getRouteInfoSlot()))){
        qDebug() << m_serverName << "sessionBus.connect():getRouteInfoSlot failed";
    }

}

void DBus_Server::initAPIs(QObject *parent){

    if(!QObject::connect(this,SIGNAL(doAddPOI(QVariant,QVariant,QVariant)),
                        parent,SLOT(addPoiIconSLOT(QVariant,QVariant,QVariant)))) {
        qDebug() << m_serverName << "cppSIGNAL:doAddPOI to qmlSLOT:addPoiIcon connect is failed";
    }

    if(!QObject::connect(this,SIGNAL(doRemovePOIs(QVariant)),
                         parent,SLOT(removePoiIconsSLOT(QVariant)))) {
        qDebug() << m_serverName << "cppSIGNAL:doRemovePOIs to qmlSLOT:removePoiIcons connect is failed";
    }

    if(!QObject::connect(this,SIGNAL(doGetRouteInfo()),
                         parent,SLOT(doGetRouteInfoSlot()))) {
        qDebug() << m_serverName << "cppSIGNAL:doGetRouteInfo to qmlSLOT:doGetRouteInfoSlot connect is failed";
    }

    if(!QObject::connect(parent,SIGNAL(qmlSignalRouteInfo(double,double,double,double)),
                         this,SLOT(sendSignalRouteInfo(double,double,double,double)))) {
        qDebug() << m_serverName << "qmlSIGNAL:qmlSignalRouteInfo to cppSLOT:sendSignalRouteInfo connect is failed";
    }

    if(!QObject::connect(parent,SIGNAL(qmlSignalPosInfo(double,double,double,double)),
                         this,SLOT(sendSignalPosInfo(double,double,double,double)))) {
        qDebug() << m_serverName << "qmlSIGNAL:qmlSignalPosInfo to cppSLOT:sendSignalPosInfo connect is failed";
    }

    if(!QObject::connect(parent,SIGNAL(qmlSignalStopDemo()),
                         this,SLOT(sendSignalStopDemo()))) {
        qDebug() << m_serverName << "qmlSIGNAL:qmlSignalStopDemo to cppSLOT:sendSignalStopDemo connect is failed";
    }

    if(!QObject::connect(parent,SIGNAL(qmlSignalArrvied()),
                         this,SLOT(sendSignalArrvied()))) {
        qDebug() << m_serverName << "qmlSIGNAL:qmlSignalArrvied to cppSLOT:sendSignalArrvied connect is failed";
    }
}

void DBus_Server::getRouteInfoSlot(){
    qDebug() << "call getRouteInfoSlot ";
    emit doGetRouteInfo();
    return;
}

// Signal
void DBus_Server::sendSignalRouteInfo(double srt_lat, double srt_lon, double end_lat, double end_lon){
    qDebug() << "call sendSignalRouteInfo ";
    QDBusMessage message = QDBusMessage::createSignal(m_objName,
                                                     org::agl::naviapi::staticInterfaceName(),
                                                     "signalRouteInfo");
    message << srt_lat << srt_lon << end_lat << end_lon;
    QDBusConnection::sessionBus().send(message);
    return;
}

void DBus_Server::sendSignalPosInfo(double lat, double lon, double drc, double dst){
//    qDebug() << "call sendSignalPosInfo ";
    QDBusMessage message = QDBusMessage::createSignal(m_objName,
                                                     org::agl::naviapi::staticInterfaceName(),
                                                     "signalPosInfo");
    message << lat << lon << drc << dst;
    QDBusConnection::sessionBus().send(message);
    return;
}

void DBus_Server::sendSignalStopDemo(){
    qDebug() << "call sendSignalStopDemo ";
    QDBusMessage message = QDBusMessage::createSignal(m_objName,
                                                     org::agl::naviapi::staticInterfaceName(),
                                                     "signalStopDemo");
    QDBusConnection::sessionBus().send(message);
    return;
}

void DBus_Server::sendSignalArrvied(){
    qDebug() << "call sendSignalArrvied ";
    QDBusMessage message = QDBusMessage::createSignal(m_objName,
                                                     org::agl::naviapi::staticInterfaceName(),
                                                     "signalArrvied");
    QDBusConnection::sessionBus().send(message);
    return;
}

// Method
void DBus_Server::addPOI(uint category_id, double poi_Lat, double poi_Lon){
    qDebug() << "call addPOI category_id: " << category_id << " poi_Lat: " << poi_Lat << " poi_Lon: " << poi_Lon;
    emit doAddPOI(poi_Lat,poi_Lon,category_id);
    return;
}
void DBus_Server::removePOIs(uint category_id){
    qDebug() << "call removePOIs category_id: " << category_id;
    emit doRemovePOIs(category_id);
    return;
}