Skip to content

Commit

Permalink
follow mapmatching clients on dbus
Browse files Browse the repository at this point in the history
  • Loading branch information
rinigus committed Jul 19, 2018
1 parent aa90f44 commit 2bf9924
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 17 deletions.
6 changes: 4 additions & 2 deletions osmscout-server_silica.pro
Expand Up @@ -90,7 +90,8 @@ SOURCES += \
src/util.cpp \
src/mapboxglmaster.cpp \
src/valhallamapmatcher.cpp \
src/valhallamapmatcherdbus.cpp
src/valhallamapmatcherdbus.cpp \
src/valhallamapmatcherdbusadaptor.cpp

OTHER_FILES += rpm/osmscout-server.spec

Expand Down Expand Up @@ -122,7 +123,8 @@ HEADERS += \
src/util.hpp \
src/mapboxglmaster.h \
src/valhallamapmatcher.h \
src/valhallamapmatcherdbus.h
src/valhallamapmatcherdbus.h \
src/valhallamapmatcherdbusadaptor.h

use_osmscout {
DEFINES += USE_OSMSCOUT
Expand Down
6 changes: 4 additions & 2 deletions pro/osmscout-server_console.pro
Expand Up @@ -76,7 +76,8 @@ SOURCES += src/dbmaster.cpp \
src/mapboxglmaster.cpp \
src/mapmanager_urlcollection.cpp \
src/valhallamapmatcher.cpp \
src/valhallamapmatcherdbus.cpp
src/valhallamapmatcherdbus.cpp \
src/valhallamapmatcherdbusadaptor.cpp

OTHER_FILES += \
osmscout-server.desktop
Expand Down Expand Up @@ -107,7 +108,8 @@ HEADERS += \
src/mapboxglmaster.h \
src/mapmanager_urlcollection.h \
src/valhallamapmatcher.h \
src/valhallamapmatcherdbus.h
src/valhallamapmatcherdbus.h \
src/valhallamapmatcherdbusadaptor.h

use_osmscout {
DEFINES += USE_OSMSCOUT
Expand Down
6 changes: 4 additions & 2 deletions pro/osmscout-server_qtcontrols.pro
Expand Up @@ -83,7 +83,8 @@ SOURCES += src/dbmaster.cpp \
src/util.cpp \
src/mapboxglmaster.cpp \
src/valhallamapmatcher.cpp \
src/valhallamapmatcherdbus.cpp
src/valhallamapmatcherdbus.cpp \
src/valhallamapmatcherdbusadaptor.cpp

OTHER_FILES += \
osmscout-server.desktop
Expand Down Expand Up @@ -116,7 +117,8 @@ HEADERS += \
src/util.hpp \
src/mapboxglmaster.h \
src/valhallamapmatcher.h \
src/valhallamapmatcherdbus.h
src/valhallamapmatcherdbus.h \
src/valhallamapmatcherdbusadaptor.h

use_osmscout {
DEFINES += USE_OSMSCOUT
Expand Down
14 changes: 9 additions & 5 deletions src/main.cpp
Expand Up @@ -41,6 +41,7 @@

// DBus interface
#include "valhallamapmatcherdbus.h"
#include "valhallamapmatcherdbusadaptor.h"

// LIB OSM Scout interface
#include "dbmaster.h"
Expand Down Expand Up @@ -522,18 +523,21 @@ int main(int argc, char *argv[])
#endif

// establish d-bus connection
QDBusConnection dbussession = QDBusConnection::sessionBus();
QDBusConnection dbusconnection = QDBusConnection::sessionBus();

// add d-bus interface
#ifdef USE_VALHALLA
QObject objValhallaMapMatcher; // dummy object used by DBus interface
new ValhallaMapMatcherDBus(&objValhallaMapMatcher);
if (!dbussession.registerObject(DBUS_PATH_MAPMATCHING, &objValhallaMapMatcher))
ValhallaMapMatcherDBus valhallaMapMatcherDBus;
new ValhallaMapMatcherDBusAdaptor(&valhallaMapMatcherDBus);
if (!dbusconnection.registerObject(DBUS_PATH_MAPMATCHING, &valhallaMapMatcherDBus))
InfoHub::logWarning(app->tr("Failed to register DBus object: %1").arg(DBUS_PATH_MAPMATCHING));
else
dbusconnection.connect(QString(), "/org/freedesktop/DBus", "org.freedesktop.DBus", "NameOwnerChanged",
&valhallaMapMatcherDBus, SLOT(onNameOwnerChanged(QString,QString,QString)));
#endif

// register dbus service
if (!dbussession.registerService(DBUS_SERVICE))
if (!dbusconnection.registerService(DBUS_SERVICE))
InfoHub::logWarning(app->tr("Failed to register DBus service: %1").arg(DBUS_SERVICE));

return_code = app->exec();
Expand Down
14 changes: 12 additions & 2 deletions src/valhallamapmatcherdbus.cpp
@@ -1,11 +1,11 @@
#include "valhallamapmatcherdbus.h"
#include "infohub.h"

#include <QDebug>

ValhallaMapMatcherDBus::ValhallaMapMatcherDBus(QObject *parent):
QDBusAbstractAdaptor(parent)
QObject(parent)
{

}

ValhallaMapMatcherDBus::~ValhallaMapMatcherDBus()
Expand Down Expand Up @@ -48,3 +48,13 @@ bool ValhallaMapMatcherDBus::stop(const QDBusMessage &message)
m_matchers.remove(caller);
return true;
}

void ValhallaMapMatcherDBus::onNameOwnerChanged(QString name, QString /*old_owner*/, QString new_owner)
{
if (new_owner.length() < 1 &&
m_matchers.contains(name))
{
InfoHub::logInfo(tr("Closing map matching service for DBus client %1").arg(name));
m_matchers.remove(name);
}
}
13 changes: 9 additions & 4 deletions src/valhallamapmatcherdbus.h
@@ -1,30 +1,35 @@
#ifndef VALHALLAMAPMATCHERDBUS_H
#define VALHALLAMAPMATCHERDBUS_H

#include "config.h"
#include "valhallamapmatcher.h"

#include <QDBusAbstractAdaptor>
#include <QDBusConnection>
#include <QDBusMessage>
#include <QHash>
#include <QSharedPointer>

class ValhallaMapMatcherDBus : public QDBusAbstractAdaptor
class ValhallaMapMatcherDBus : public QObject
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", DBUS_INTERFACE_MAPMATCHING)

public:
ValhallaMapMatcherDBus(QObject *parent);
ValhallaMapMatcherDBus(QObject *parent=nullptr);
~ValhallaMapMatcherDBus();

public slots:
//////////////////////////////////////////////////////////////////////////////////////////
/// NB! when adding slots for DBus export, don't forget to add them in the adaptor as well

QString update(int mode, double lat, double lon, double accuracy, const QDBusMessage &message);

bool reset(int mode, const QDBusMessage &message);
bool stop(int mode, const QDBusMessage &message);
bool stop(const QDBusMessage &message);

// used to track lost clients - not for export on dbus
void onNameOwnerChanged(QString name, QString old_owner, QString new_owner);

protected:
QSharedPointer<ValhallaMapMatcher> get(int mode, const QString &caller);

Expand Down
26 changes: 26 additions & 0 deletions src/valhallamapmatcherdbusadaptor.cpp
@@ -0,0 +1,26 @@
#include "valhallamapmatcherdbusadaptor.h"

ValhallaMapMatcherDBusAdaptor::ValhallaMapMatcherDBusAdaptor(ValhallaMapMatcherDBus *p):
QDBusAbstractAdaptor(p), m(p)
{
}

QString ValhallaMapMatcherDBusAdaptor::update(int mode, double lat, double lon, double accuracy, const QDBusMessage &message)
{
return m->update(mode,lat,lon,accuracy,message);
}

bool ValhallaMapMatcherDBusAdaptor::reset(int mode, const QDBusMessage &message)
{
return m->reset(mode,message);
}

bool ValhallaMapMatcherDBusAdaptor::stop(int mode, const QDBusMessage &message)
{
return m->stop(mode,message);
}

bool ValhallaMapMatcherDBusAdaptor::stop(const QDBusMessage &message)
{
return m->stop(message);
}
30 changes: 30 additions & 0 deletions src/valhallamapmatcherdbusadaptor.h
@@ -0,0 +1,30 @@
#ifndef VALHALLAMAPMATCHERDBUSADAPTOR_H
#define VALHALLAMAPMATCHERDBUSADAPTOR_H

#include "valhallamapmatcherdbus.h"
#include "config.h"

#include <QDBusAbstractAdaptor>
#include <QDBusConnection>
#include <QDBusMessage>

class ValhallaMapMatcherDBusAdaptor : public QDBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", DBUS_INTERFACE_MAPMATCHING)

public:
ValhallaMapMatcherDBusAdaptor(ValhallaMapMatcherDBus *parent);

public slots:
QString update(int mode, double lat, double lon, double accuracy, const QDBusMessage &message);

bool reset(int mode, const QDBusMessage &message);
bool stop(int mode, const QDBusMessage &message);
bool stop(const QDBusMessage &message);

private:
ValhallaMapMatcherDBus *m;
};

#endif // VALHALLAMAPMATCHERDBUSADAPTOR_H

0 comments on commit 2bf9924

Please sign in to comment.