bool TransportTracker::btConnectivityStatus()
{
    FUNCTION_CALL_TRACE;

    bool btOn = false;
    QDBusConnection *systemBus = new QDBusConnection(QDBusConnection::connectToBus(QDBusConnection::SystemBus,
                                                                                    QStringLiteral("buteo_system_bus2")));
    QDBusMessage methodCallMsg = QDBusMessage::createMethodCall("org.bluez",
                                                                "/",
                                                                "org.bluez.Manager",
                                                                "DefaultAdapter");

    QDBusMessage reply = systemBus->call(methodCallMsg);
    if (reply.type() == QDBusMessage::ErrorMessage)
    {
        LOG_WARNING("This device does not have a BT adapter");
        delete systemBus;
        return btOn;
    }

    QList<QVariant> adapterList = reply.arguments();
    // We will take the first adapter in the list
    QString adapterPath = qdbus_cast<QDBusObjectPath>(adapterList.at(0)).path();

    if (!adapterPath.isEmpty() || !adapterPath.isNull())
    {
        // Retrive the properties of the adapter and check for "Powered" key
        methodCallMsg = QDBusMessage::createMethodCall("org.bluez",
                                                       adapterPath,
                                                       "org.bluez.Adapter",
                                                       "GetProperties");
        reply = systemBus->call(methodCallMsg);
        if (reply.type() == QDBusMessage::ErrorMessage)
        {
            LOG_WARNING("Error in retrieving bluetooth properties");
            delete systemBus;
            return btOn;
        }

        QDBusArgument arg = reply.arguments().at(0).value<QDBusArgument>();
        if (arg.currentType() == QDBusArgument::MapType)
        {
            // Scan through the dict returned and check for "Powered" entry
            QMap<QString,QVariant> dict = qdbus_cast<QMap<QString,QVariant> >(arg);
            QMap<QString,QVariant>::iterator iter;
            for(iter = dict.begin(); iter != dict.end(); ++iter)
            {
                if (iter.key() == "Powered")
                {
                    btOn = iter.value().toBool();
                    LOG_DEBUG ("Bluetooth powered on? " << btOn);
                    break;
                }
            }
        }
    }
    delete systemBus;
    return btOn;
}
Example #2
0
void
BTAdaptor::searchBtDevices ()
{
    // Connect to the signal DeviceFound to obtain the list of devices
    QDBusConnection bus = QDBusConnection::systemBus ();
    bool success = bus.connect ("org.bluez",
                                mAdapterPath,
                                "org.bluez.Adapter",
                                "DeviceFound",
                                this,
                                SLOT (deviceFound(QString,QMap<QString,QVariant>)));

    if (!success)
    {
        qDebug() << "Failure in connecting dbus signal";
        return;
    }
    
    QDBusMessage msg = QDBusMessage::createMethodCall ("org.bluez",
                                                       mAdapterPath,
                                                       "org.bluez.Adapter",
                                                       "StartDiscovery");

    QDBusMessage reply = bus.call (msg);
    if (reply.type () == QDBusMessage::ErrorMessage)
    {
        qWarning() << "Error in dbus call to search for devices";
        return ;
    }
}
bool DeclarativeDBusAdaptor::handleMessage(const QDBusMessage &message, const QDBusConnection &connection)
{
    QVariant variants[10];
    QGenericArgument arguments[10];

    const QMetaObject * const meta = metaObject();
    const QVariantList dbusArguments = message.arguments();

    QString member = message.member();
    QString interface = message.interface();

    // Don't try to handle introspect call. It will be handled
    // internally for QDBusVirtualObject derived classes.
    if (interface == QLatin1String("org.freedesktop.DBus.Introspectable")) {
        return false;
    } else if (interface == QLatin1String("org.freedesktop.DBus.Properties")) {
        if (member == QLatin1String("Get")) {
            interface = dbusArguments.value(0).toString();
            member = dbusArguments.value(1).toString();

            const QMetaObject * const meta = metaObject();
            if (!member.isEmpty() && member.at(0).isUpper())
                member = "rc" + member;

            for (int propertyIndex = meta->propertyOffset();
                    propertyIndex < meta->propertyCount();
                    ++propertyIndex) {
                QMetaProperty property = meta->property(propertyIndex);

                if (QLatin1String(property.name()) != member)
                    continue;

                QVariant value = property.read(this);
                if (value.userType() == qMetaTypeId<QJSValue>())
                    value = value.value<QJSValue>().toVariant();

                if (value.userType() == QVariant::List) {
                    QVariantList variantList = value.toList();
                    if (variantList.count() > 0) {

                        QDBusArgument list;
                        list.beginArray(variantList.first().userType());
                        foreach (const QVariant &listValue, variantList) {
                            list << listValue;
                        }
                        list.endArray();
                        value = QVariant::fromValue(list);
                    }
                }

                QDBusMessage reply = message.createReply(QVariantList() << value);
                connection.call(reply, QDBus::NoBlock);

                return true;
            }
Example #4
0
bool restoreExistSession()
{
    QDBusConnection bus = QDBusConnection::sessionBus();
    QDBusMessage request = QDBusMessage::createMethodCall(QString(DBUS_SERVICE),
                                                          QString(DBUS_OBJECT_PATH),
                                                          QString(DBUS_INTERFACE),
                                                          QString("Restore"));
    QDBusMessage response = bus.call(request);
    QList<QVariant> arguments = response.arguments();
    return ((arguments.size() == 1) && arguments[0].toBool());
}
Example #5
0
bool ApperdThread::nameHasOwner(const QString &name, const QDBusConnection &connection)
{
    QDBusMessage message;
    message = QDBusMessage::createMethodCall(QLatin1String("org.freedesktop.DBus"),
                                             QLatin1String("/"),
                                             QLatin1String("org.freedesktop.DBus"),
                                             QLatin1String("NameHasOwner"));
    message << qVariantFromValue(name);
    QDBusReply<bool> reply = connection.call(message);
    return reply.value();
}
Example #6
0
QList<QVariant> TestNetctlAuto::sendDBusRequest(const QString path, const QString cmd, const QList<QVariant> args)
{
    QDBusConnection bus = QDBusConnection::systemBus();
    QDBusMessage request = QDBusMessage::createMethodCall(DBUS_HELPER_SERVICE, path,
                                                          DBUS_HELPER_INTERFACE, cmd);
    if (!args.isEmpty()) request.setArguments(args);
    QDBusMessage response = bus.call(request);
    QList<QVariant> arguments = response.arguments();

    return arguments;
}
Example #7
0
QString DBusObject::introspect(const QString &path, int replyTimeout)
{
	QDBusConnection sys = QDBusConnection::systemBus();
	QDBusMessage introspect = QDBusMessage::createMethodCall(UDisks2::service(), 
			path, Interface::Introspectable(), "Introspect");

	QDBusReply<QString> reply = sys.call(introspect, QDBus::Block, replyTimeout);
	if (!reply.isValid())
		throw DBusException(reply.error().message().toStdString());

	return reply.value();
}
Example #8
0
bool TimeoutsTest::identityAlive(const QString &path)
{
    QDBusConnection conn = SIGNOND_BUS;

    QString interface = QLatin1String("com.google.code.AccountsSSO.SingleSignOn.Identity");
    QDBusMessage msg = QDBusMessage::createMethodCall(SIGNOND_SERVICE,
                                                      path,
                                                      interface,
                                                      "getInfo");
    QDBusMessage reply = conn.call(msg);
    return (reply.type() == QDBusMessage::ReplyMessage);
}
Example #9
0
// Figure out which devices we should allow a user to write to.
void
PlatformUdisks::findDevices()
{
    int i = 0;
    if (!udiskEnabled())
    {
        QMessageBox msgBox;
        msgBox.setText(QObject::tr("You don't have UDisks support."));
        msgBox.exec();
        return;
    }

    // First get the list of disks
    QDBusConnection connection = QDBusConnection::systemBus();
    QDBusMessage message;
    message = QDBusMessage::createMethodCall("org.freedesktop.UDisks", "/org/freedesktop/UDisks", "org.freedesktop.UDisks", "EnumerateDevices");

    QDBusReply<QList<QDBusObjectPath> > reply = connection.call(message);
    if (!reply.isValid())
    {
        qDebug() << "Failure: " <<  reply.error();
        return;
    }

    QList<QDBusObjectPath> list = reply.value();
    QStringList devList;
    QRegExp reg("[0-9]+$");

    // Ignore partition slices
    for (i = 0; i < list.size(); ++i)
        if (!list.at(i).path().contains(reg))
            devList << list.at(i).path();

    QStringList diskList;
    // Safe mode (the default) only handles USB devices
    if (!mUnsafe)
    {
        for (i = 0; i < devList.size(); ++i)
            if (isUSB(devList.at(i)))
                diskList << devList.at(i);
    }
    else
    {
        diskList = devList;
    }

    for (i = 0; i < diskList.size(); ++i)
    {
        getNewDevice(diskList.at(i));
    }

    return;
}
Example #10
0
bool TimeoutsTest::triggerDisposableCleanup()
{
    QDBusConnection conn = SIGNOND_BUS;

    /* create a new identity just to trigger the cleanup of disposable
     * objects */
    QDBusMessage msg = QDBusMessage::createMethodCall(SIGNOND_SERVICE,
                                                      SIGNOND_DAEMON_OBJECTPATH,
                                                      SIGNOND_DAEMON_INTERFACE,
                                                      "registerNewIdentity");
    QDBusMessage reply = conn.call(msg);
    return (reply.type() == QDBusMessage::ReplyMessage);
}
Example #11
0
QVariant DBusObject::dbusProperty(const QString &interface, const QString 
		&property) const
{
	QDBusConnection sys = QDBusConnection::systemBus();
	QDBusMessage getProperty = QDBusMessage::createMethodCall(UDisks2::service(),
			m_path.path(), Interface::Properties(), "Get");

	QVariantList arguments;
	arguments << interface << property;
	getProperty.setArguments(arguments);

	QDBusReply<QVariant> reply = sys.call(getProperty, QDBus::Block, m_replyTimeout);
	if (!reply.isValid())
		throw DBusException(reply.error().message().toStdString());

	return reply.value();
}
Example #12
0
void Partition::mount() const
{
	QDBusConnection sys = QDBusConnection::systemBus();
	QDBusMessage mount = QDBusMessage::createMethodCall(UDisks2::service(), 
			path().path(), Interface::UDisks2("Filesystem"), "Mount");

	QVariantList arguments;
	QVariantMap options;
	options["auth.no_user_interaction"] = true;
	arguments << options;

	mount.setArguments(arguments);

	QDBusReply<QString> reply = sys.call(mount, QDBus::Block, replyTimeout());
	if (!reply.isValid())
		throw DBusException(reply.error().message().toStdString());
}
void HomeApplication::sendStartupNotifications()
{
    static QDBusConnection systemBus = QDBusConnection::systemBus();
    QDBusMessage homeReadySignal =
        QDBusMessage::createSignal("/com/nokia/duihome",
                                   "com.nokia.duihome.readyNotifier",
                                   "ready");
    systemBus.send(homeReadySignal);

    /* Let systemd know that we are initialized */
    if (arguments().indexOf("--systemd") >= 0) {
        sd_notify(0, "READY=1");
    }

    /* Let timed know that the UI is up */
    systemBus.call(QDBusMessage::createSignal("/com/nokia/startup/signal", "com.nokia.startup.signal", "desktop_visible"), QDBus::NoBlock);
}
Example #14
0
void Partition::unmount(bool force) const
{
	QDBusConnection sys = QDBusConnection::systemBus();
	QDBusMessage unmount = QDBusMessage::createMethodCall(UDisks2::service(), 
			path().path(), Interface::UDisks2("Filesystem"), "Unmount");

	QVariantList arguments;
	QVariantMap options;
	if (force)
		options["force"] = true;

	arguments << options;

	unmount.setArguments(arguments);

	/* TODO: This can return an error. Please catch it … */
	sys.call(unmount, QDBus::NoBlock);
}
Example #15
0
void Camera::startCamera()
{
    QDBusConnection bus = QDBusConnection::sessionBus();

    bus.connect("com.nokia.maemo.CameraService",
                "/",
                "com.nokia.maemo.meegotouch.CameraInterface",
                "captureCanceled",
                this, SLOT(captureCanceled(QString)));

    bus.connect("com.nokia.maemo.CameraService",
                "/",
                "com.nokia.maemo.meegotouch.CameraInterface",
                "captureCompleted",
                this, SLOT(captureCompleted(QString,QString)));

    QDBusMessage message = QDBusMessage::createMethodCall(
                "com.nokia.maemo.CameraService",
                "/",
                "com.nokia.maemo.meegotouch.CameraInterface",
                "showCamera");

    QList<QVariant> args;
    args << (uint)0 << "" << "still-capture" << true;
    message.setArguments(args);

    QDBusMessage reply = bus.call(message);
    if (reply.type() == QDBusMessage::ErrorMessage) {
        qDebug() << Q_FUNC_INFO << "reply.type == errormessage; name=" << reply.errorName() << "; message=" << reply.errorMessage();
        bus.disconnect("com.nokia.maemo.CameraService",
                    "/",
                    "com.nokia.maemo.meegotouch.CameraInterface",
                    "captureCanceled",
                    this, SLOT(captureCanceled(QString)));

        bus.disconnect("com.nokia.maemo.CameraService",
                    "/",
                    "com.nokia.maemo.meegotouch.CameraInterface",
                    "captureCompleted",
                    this, SLOT(captureCompleted(QString,QString)));
        if (m_lastEcId)
            this->callback(m_lastEcId, "");
    }
}
int
PlatformUdisks2::open(DeviceItem* item)
{
    int ret = -1;

    QDBusConnection connection = QDBusConnection::systemBus();
    QList<QVariant> args;
    QVariantMap map;
    args << map;

    QString udi = QString("/org/freedesktop/UDisks2/block_devices/%1").arg(item->getUDI());
    QDBusMessage message = QDBusMessage::createMethodCall("org.freedesktop.UDisks2", udi, "org.freedesktop.UDisks2.Block", "OpenForRestore");
    message.setArguments(args);
    QDBusMessage reply = connection.call(message);

    if (reply.type() == QDBusMessage::ErrorMessage)
    {
        QMessageBox msgBox;
        msgBox.setText(QString("DBUS error (%1): %2").arg(item->getUDI()).arg(reply.errorMessage()));
        msgBox.exec();
        ret = -1;
    }
    else if (reply.arguments().empty() || reply.arguments()[0].userType() != qMetaTypeId<QDBusUnixFileDescriptor>())
    {
        QMessageBox msgBox;
        msgBox.setText(QString("got empty or invalid reply!?"));
        msgBox.exec();
	errno = EINVAL;
    }
    else
    {
	QDBusUnixFileDescriptor fd(qvariant_cast<QDBusUnixFileDescriptor>(reply.arguments()[0]));
	if (fd.isValid())
	{
	    ret = ::dup(fd.fileDescriptor());
	}
    }

    qDebug() << "ret" << ret;

    return ret;
}
Example #17
0
bool
PlatformUdisks::getIsDrive(const QString &path)
{
    bool ret;
    QDBusConnection connection = QDBusConnection::systemBus();
    QDBusMessage message;
    QList<QVariant> args;
    args << "org.freedesktop.UDisks";
    args << "DeviceIsDrive";

    message = QDBusMessage::createMethodCall("org.freedesktop.UDisks", path, "org.freedesktop.DBus.Properties", "Get");
    message.setArguments(args);

    QDBusReply<QDBusVariant> reply = connection.call(message);
    if (!reply.isValid())
        return(false);

    ret = reply.value().variant().toBool();
    return(ret);
}
Example #18
0
long long
PlatformUdisks::getSize(const QString &devicePath)
{
    long long ret;
    QDBusConnection connection = QDBusConnection::systemBus();
    QDBusMessage message;
    QList<QVariant> args;
    args << "org.freedesktop.UDisks";
    args << "DeviceSize";

    message = QDBusMessage::createMethodCall("org.freedesktop.UDisks", devicePath, "org.freedesktop.DBus.Properties", "Get");
    message.setArguments(args);

    QDBusReply<QDBusVariant> reply = connection.call(message);
    if (!reply.isValid())
        return(0);

    ret = reply.value().variant().toLongLong();
    return(ret);
}
Example #19
0
bool
PlatformUdisks::isUSB(const QString &udiskPath)
{
    QDBusConnection connection = QDBusConnection::systemBus();
    QDBusMessage message;
    QList<QVariant> args;
    args << "org.freedesktop.UDisks";
    args << "DriveConnectionInterface";

    message = QDBusMessage::createMethodCall("org.freedesktop.UDisks", udiskPath, "org.freedesktop.DBus.Properties", "Get");
    message.setArguments(args);

    QDBusReply<QDBusVariant> reply = connection.call(message);
    if (!reply.isValid())
        return false;

    if (reply.value().variant().toString() == "usb")
        return true;
    else
        return false;
}
Example #20
0
bool
PlatformUdisks::udiskEnabled()
{
    QDBusConnection connection = QDBusConnection::systemBus();
    QDBusMessage message, reply;
    QList<QVariant> args;
    args << "org.freedesktop.UDisks";
    args << "DaemonVersion";

    message = QDBusMessage::createMethodCall("org.freedesktop.UDisks", "/org/freedesktop/UDisks", "org.freedesktop.DBus.Properties", "Get");
    message.setArguments(args);

    reply = connection.call(message);
    if (reply.type() == QDBusMessage::ErrorMessage)
    {
        qDebug() << "Failure: " <<  reply;
        return false;
    }

    return true;
}
Example #21
0
bool
PlatformUdisks::performUnmount(QString udi)
{
    bool ret = true;
    QDBusConnection connection = QDBusConnection::systemBus();
    QDBusMessage message, reply;

    message = QDBusMessage::createMethodCall("org.freedesktop.UDisks", udi, "org.freedesktop.UDisks.Device", "FilesystemUnmount");
    message << QStringList();
    reply = connection.call(message);

    if (reply.type() == QDBusMessage::ErrorMessage)
    {
        QMessageBox msgBox;
        msgBox.setText(QString("DBUS error (%1): %2").arg(udi).arg(reply.errorMessage()));
        msgBox.exec();
        ret = false;
    }

    return ret;
}
Example #22
0
  /* FIXME: this makes a synchronous roundtrip to dbus daemon
   * and back during which time the timed process will be blocked.
   *
   * Note: We can't really handle this asynchronously without
   * handling the whole add_event asynchronously and this would
   * require modifications to the timed event state machine and
   * delaying sending add_event replies from QDBusAbstractAdaptor.
   * At the moment I do not know how to handle either of those ...
   * ;-(
   */
uint32_t get_name_owner_from_dbus_sync(const QDBusConnection &bus, const QString &name)
{
  // TODO make 'dbus_daemon' interface via QDBusAbstractInterface
  QString service   =  "org.freedesktop.DBus" ;
  QString path      = "/org/freedesktop/DBus" ;
  QString interface =  "org.freedesktop.DBus" ;
  QString method    = "GetConnectionUnixUser" ;
  // It seems, we can't get GID just by asking dbus daemon.

  QDBusMessage req  = QDBusMessage::createMethodCall(service, path, interface, method);
  req << name;

  QDBusReply<uint> reply = bus.call(req);

  if (reply.isValid())
    return reply.value() ;
  else
  {
    log_error("%s: did not get a valid reply", CSTR(method));
    return ~0 ;
  }
}
bool
PlatformUdisks2::doUnmount(const QString &partitionPath)
{
    bool ret = true;
    QDBusConnection connection = QDBusConnection::systemBus();
    QList<QVariant> args;
    QVariantMap map;
    args << map;

    QDBusMessage message = QDBusMessage::createMethodCall("org.freedesktop.UDisks2", partitionPath, "org.freedesktop.UDisks2.Filesystem", "Unmount");
    message.setArguments(args);
    QDBusMessage reply = connection.call(message);

    if (reply.type() == QDBusMessage::ErrorMessage)
    {
        QMessageBox msgBox;
        msgBox.setText(QString("DBUS error (%1): %2").arg(partitionPath).arg(reply.errorMessage()));
        msgBox.exec();
        ret = false;
    }
    return(ret);
}
Example #24
0
QStringList
PlatformUdisks::getPartitionList(const QString &devicePath)
{
    QStringList devList;
    // First get the list of disks
    QDBusConnection connection = QDBusConnection::systemBus();
    QDBusMessage message;
    message = QDBusMessage::createMethodCall("org.freedesktop.UDisks", "/org/freedesktop/UDisks", "org.freedesktop.UDisks", "EnumerateDevices");

    QDBusReply<QList<QDBusObjectPath> > reply = connection.call(message);
    if (!reply.isValid())
    {
        qDebug() << "Failure: " <<  reply.error();
        return(devList);
    }

    QList<QDBusObjectPath> list = reply.value();
    QRegExp reg(QString("%1[0-9]+$").arg(devicePath));
    for (int i = 0; i < list.size(); ++i)
        if (list.at(i).path().contains(reg))
            devList << list.at(i).path();

    return(devList);
}
Example #25
0
/*!
  Sends the request. Returns false if there was no application that could
  service the request.
*/
bool QtopiaServiceRequest::send() const
{
    if (isNull())
        return false;

#if defined(QTOPIA_DBUS_IPC)
    QDBusConnection dbc = QDBus::sessionBus();
    QString service = dbusInterface;
    service.append(".");
    service.append(m_Service);
    QString path = dbusPathBase;
    path.append(m_Service);

    qLog(Services) << "Sending service request on" << service << path << dbusInterface;
    /*
    QDBusInterface *iface = new QDBusInterface(service,
                                               path,
                                               dbusInterface, dbc);
    if (!iface) {
        qWarning("No interface registered!!");
        return false;
    }
    */

    int idx = m_Message.indexOf('(');
    QString dbusMethod = m_Message.left(idx);

    qLog(DBUS) << "Calling method" << dbusMethod;

    QDBusMessage msg = QDBusMessage::methodCall(service,
            path, dbusInterface, dbusMethod, dbc);
    msg.setArguments(m_arguments);
    dbc.call(msg, QDBus::NoBlock);

    /*
    iface->callWithArgumentList(QDBus::NoBlock,
                                dbusMethod, m_arguments);
    */
    qLog(DBUS) << "Calling method finished...";

    return true;
#elif !defined(QT_NO_COP) || defined(Q_WS_X11)
    QString ch;
    bool rawMessage = false;

    if(m_Service.startsWith("Application:")) {
        ch = "QPE/Application/" + m_Service.mid(12);
        rawMessage = true;
    } else if(m_Service.startsWith("Channel:")) {
        ch = m_Service.mid(8);
        rawMessage = true;
    } else {
        ch = QtopiaService::channel(m_Service, QString());
    }
    
    if (ch.isNull())
        return false;

    QBuffer *buffer = new QBuffer();
    QDataStream stream(buffer);
    stream.device()->open(QIODevice::WriteOnly);

    foreach(QVariant item, m_arguments) {
        QtopiaIpcAdaptorVariant copy( item );
        copy.save( stream );
    }
Example #26
0
void TimeoutsTest::identityRegisterTwice()
{
    QEventLoop loop;
    QTimer::singleShot(test_timeout, &loop, SLOT(quit()));
    QObject::connect(this, SIGNAL(finished()), &loop, SLOT(quit()));

    QMap<MethodName,MechanismsList> methods;
    methods.insert("dummy", QStringList() << "mech1" << "mech2");
    IdentityInfo info = IdentityInfo(QLatin1String("timeout test"),
                                     QLatin1String("timeout@test"),
                                     methods);
    info.setAccessControlList(QStringList() << "*");
    Identity *identity = Identity::newIdentity(info);
    QVERIFY(identity != NULL);

    QObject::connect(identity,
                     SIGNAL(credentialsStored(const quint32)),
                     this,
                     SLOT(credentialsStored(const quint32)));
    QObject::connect(identity,
                     SIGNAL(error(const SignOn::Error &)),
                     this,
                     SLOT(identityError(const SignOn::Error &)));

    identity->storeCredentials();

    loop.exec();
    QVERIFY(identity->id() != SSO_NEW_IDENTITY);

    QDBusConnection conn = SIGNOND_BUS;

    QDBusMessage msg = QDBusMessage::createMethodCall(SIGNOND_SERVICE,
                                                      SIGNOND_DAEMON_OBJECTPATH,
                                                      SIGNOND_DAEMON_INTERFACE,
                                                      "getIdentity");
    QList<QVariant> args;
    args << identity->id();
    msg.setArguments(args);

    QDBusMessage reply = conn.call(msg);
    QCOMPARE(reply.type(), QDBusMessage::ReplyMessage);

    QDBusObjectPath objectPath = reply.arguments()[0].value<QDBusObjectPath>();
    QString path = objectPath.path();
    qDebug() << "Got path" << path;
    QVERIFY(!path.isEmpty());

    bool success;

    QTest::qSleep(100);
    success = triggerDisposableCleanup();
    QVERIFY(success);

    /* The identity object must exist now */
    QVERIFY(identityAlive(path));

    QTest::qSleep(6 * 1000);
    /* now we register the same identity again. The expected behavior is that
     * the registration succeeds, possibly returning the same object path as
     * before.
     * This is to test a regression (NB#182914) which was happening because
     * signond was deleting the expired Identity immediately after returning
     * its object path to the client.
     */
    reply = conn.call(msg);
    QVERIFY(reply.type() == QDBusMessage::ReplyMessage);

    objectPath = reply.arguments()[0].value<QDBusObjectPath>();
    path = objectPath.path();
    qDebug() << "Got path" << path;
    QVERIFY(!path.isEmpty());

    QVERIFY(identityAlive(path));
}
Example #27
0
void TimeoutsTest::identityTimeout()
{
    QEventLoop loop;
    QTimer::singleShot(test_timeout, &loop, SLOT(quit()));
    QObject::connect(this, SIGNAL(finished()), &loop, SLOT(quit()));

    QMap<MethodName,MechanismsList> methods;
    methods.insert("dummy", QStringList() << "mech1" << "mech2");
    IdentityInfo info = IdentityInfo(QLatin1String("timeout test"),
                                     QLatin1String("timeout@test"),
                                     methods);
    info.setAccessControlList(QStringList() << "*");
    Identity *identity = Identity::newIdentity(info);
    QVERIFY(identity != NULL);

    QObject::connect(identity,
                     SIGNAL(credentialsStored(const quint32)),
                     this,
                     SLOT(credentialsStored(const quint32)));
    QObject::connect(identity,
                     SIGNAL(error(const SignOn::Error&)),
                     this,
                     SLOT(identityError(const SignOn::Error&)));

    identity->storeCredentials();

    loop.exec();
    QVERIFY(identity->id() != SSO_NEW_IDENTITY);

    QDBusConnection conn = SIGNOND_BUS;

    QDBusMessage msg = QDBusMessage::createMethodCall(SIGNOND_SERVICE,
                                                      SIGNOND_DAEMON_OBJECTPATH,
                                                      SIGNOND_DAEMON_INTERFACE,
                                                      "getIdentity");
    QList<QVariant> args;
    args << identity->id();
    msg.setArguments(args);

    QDBusMessage reply = conn.call(msg);
    QCOMPARE(reply.type(), QDBusMessage::ReplyMessage);

    QDBusObjectPath objectPath = reply.arguments()[0].value<QDBusObjectPath>();
    QString path = objectPath.path();
    qDebug() << "Got path" << path;
    QVERIFY(!path.isEmpty());

    bool success;

    QTest::qSleep(100);
    success = triggerDisposableCleanup();
    QVERIFY(success);

    /* The identity object must exist now */
    QVERIFY(identityAlive(path));

    QTest::qSleep(6 * 1000);
    success = triggerDisposableCleanup();
    QVERIFY(success);

    /* After SSO_IDENTITY_TIMEOUT seconds, the identity must have been
     * destroyed */
    QVERIFY(!identityAlive(path));

    /* Calling a method on the client should re-register the identity */
    QSignalSpy removed(identity, SIGNAL(removed()));
    QObject::connect(identity, SIGNAL(removed()),
                     &loop, SLOT(quit()), Qt::QueuedConnection);
    identity->remove();
    loop.exec();

    QCOMPARE(removed.count(), 1);
}
Example #28
0
QVariantHash PlayerSource::getPlayerMprisInfo(const QString mpris) const
{
    qCDebug(LOG_ESM) << "MPRIS" << mpris;

    QVariantHash info = defaultInfo();
    if (mpris.isEmpty())
        return info;

    QDBusConnection bus = QDBusConnection::sessionBus();
    // comes from the following request:
    // qdbus org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2
    // org.freedesktop.DBus.Properties.Get org.mpris.MediaPlayer2.Player
    // Metadata
    // or the same but using dbus-send:
    // dbus-send --print-reply --session --dest=org.mpris.MediaPlayer2.vlc
    // /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get
    // string:'org.mpris.MediaPlayer2.Player' string:'Metadata'
    QVariantList args = QVariantList()
                        << QString("org.mpris.MediaPlayer2.Player")
                        << QString("Metadata");
    QDBusMessage request = QDBusMessage::createMethodCall(
        QString("org.mpris.MediaPlayer2.%1").arg(mpris),
        QString("/org/mpris/MediaPlayer2"), QString(""), QString("Get"));
    request.setArguments(args);
    QDBusMessage response = bus.call(request, QDBus::BlockWithGui);
    if ((response.type() != QDBusMessage::ReplyMessage)
        || (response.arguments().isEmpty())) {
        qCWarning(LOG_ESM) << "Error message" << response.errorMessage();
    } else {
        // another portion of dirty magic
        QVariantHash map
            = qdbus_cast<QVariantHash>(response.arguments()
                                           .first()
                                           .value<QDBusVariant>()
                                           .variant()
                                           .value<QDBusArgument>());
        info[QString("player/album")]
            = map.value(QString("xesam:album"), QString("unknown"));
        // artist is array
        info[QString("player/artist")]
            = map.value(QString("xesam:artist"), QString("unknown")).toString();
        info[QString("player/duration")]
            = map.value(QString("mpris:length"), 0).toInt() / (1000 * 1000);
        info[QString("player/title")]
            = map.value(QString("xesam:title"), QString("unknown"));
    }

    // position
    args[1] = QString("Position");
    request.setArguments(args);
    response = bus.call(request, QDBus::BlockWithGui);
    if ((response.type() != QDBusMessage::ReplyMessage)
        || (response.arguments().isEmpty())) {
        qCWarning(LOG_ESM) << "Error message" << response.errorMessage();
    } else {
        // this cast is simpler than the previous one ;)
        info[QString("player/progress")] = response.arguments()
                                               .first()
                                               .value<QDBusVariant>()
                                               .variant()
                                               .toLongLong()
                                           / (1000 * 1000);
    }

    return info;
}