[SailfishDevel] Listening to Connman DBUS signals

Julius Loman lomo at kyberia.net
Wed Jan 22 16:18:16 UTC 2014


Hi

this is for sure a beginners question, but I hope somebody can help me to sort
it out. I want to listen to connman dbus events to determine connection changes
(I'm interested in receiving signal as soon as device connects to particular
WLAN network).

Using some examples I was able to capture dbus events on my KDE desktop (albeit
not connman related), but same code for SailfishOS does nothing. I guess my
understanding of Dbus or QtBus is bad :)

Here is my piece of code:

#include "wifimonitor.h"
#include <QtDBus>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    WifiMonitor* receiver = new WifiMonitor;

    qDebug() << "Starting dbus monitor";
    QDBusConnection system = QDBusConnection::systemBus();
    if (!system.isConnected())
    {
        qFatal("Cannot connect to the D-Bus session bus.");
        return 1;
    }
    system.connect("",
                   "/net/connman/technology/wifi",
                   "net.connman.Technology",
                   "PropertyChanged",
                   receiver,
                   SLOT(propertyChanged(const QDBusObjectPath&))
                   );

    return a.exec();
}

---- wifimonitor.h ----

#ifndef WIFIMONITOR_H
#define WIFIMONITOR_H

#include <QObject>
#include <QtDBus>

class WifiMonitor : public QObject
{
    Q_OBJECT
public:
    explicit WifiMonitor(QObject *parent = 0);

signals:

public slots:
    void propertyChanged(const QDBusObjectPath &in);
};

#endif // WIFIMONITOR_H

---- wifimonitor.cpp ----

#include "wifimonitor.h"
#include <QtDBus>

WifiMonitor::WifiMonitor(QObject *parent) :
    QObject(parent)
{
}

void WifiMonitor::propertyChanged(const QDBusObjectPath &in)
{
    qDebug() << "DBus signal received";
    qDebug() << "PropertyChanged, ObjectPath: " << in.path();
}


Thanks
Julius

-- 

[ Julius Loman ][ lomo at kyberia.net ][ http://lomo.kyberia.net ][ icq:35732873 ]


More information about the Devel mailing list