aboutsummaryrefslogtreecommitdiffstats
path: root/app/dbus_server.cpp
blob: ea3acadf5b887630868a390b42a2e463e8675d66 (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
#include"dbus_server.h"
#include <QDebug>

DBus_Server::DBus_Server(QObject *parent) :
  m_serverName("naviapi"),
  m_pathName("org.agl.naviapi"),
  m_objName("/org/agl/naviapi")
{
    initDBus();
    initAPIs(parent);
}

DBus_Server::~DBus_Server(){
    QDBusConnection::sessionBus().unregisterObject(m_objName);
    QDBusConnection::sessionBus().unregisterService(m_pathName);
}

void DBus_Server::initDBus(){

    new NaviapiAdaptor(this);

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

    if (!QDBusConnection::sessionBus().registerObject(m_objName, this))
        qDebug() << m_serverName << "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(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){
    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