File Metadata

Author
aleksanderm
Created
Jul 11 2019, 11:01 AM

test.cpp

/*
$ g++ \
`pkg-config --cflags --libs Qt5DBus Qt5Core mm-glib` \
-I /usr/include/KF5/ModemManagerQt/ \
-lKF5ModemManagerQt \
-fPIC \
test.cpp \
-o test
*/
#include <QCoreApplication>
#include <QDebug>
#include <QtDBus>
#undef signals
#include <ModemManager.h>
#include <Manager>
#include <Modem3Gpp>
#include <Modem>
#include <libmm-glib.h>
#define signals Q_SIGNALS
int main (int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Q_FOREACH (ModemManager::ModemDevice::Ptr modemdevice, ModemManager::modemDevices()) {
ModemManager::Modem3gpp::Ptr modem3gpp = modemdevice->interface(ModemManager::ModemDevice::GsmInterface).objectCast<ModemManager::Modem3gpp>();;
if (modem3gpp) {
// Set explicit timeout for the operation
modem3gpp->setDefaultTimeout(300000);
// Launch scan
QDBusPendingReply<> async = modem3gpp->scan();
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async);
QObject::connect(
watcher, &QDBusPendingCallWatcher::finished,
[&a] (QDBusPendingCallWatcher *call) {
QDBusPendingReply<> reply = *call;
if (reply.isError()) {
QDBusError error = reply.error();
qWarning() << "Scan operation failed: " << error.message();
} else {
qInfo() << "Scan operation successful";
}
a.quit();
});
break;
}
}
return a.exec();
}