/*! Opens a connection of type \a type to one of the known busses and associate with it the connection name \a name. Returns a QDBusConnection object associated with that connection. */ QDBusConnection QDBusConnection::connectToBus(BusType type, const QString &name) { // Q_ASSERT_X(QCoreApplication::instance(), "QDBusConnection::addConnection", // "Cannot create connection without a Q[Core]Application instance"); if (!qdbus_loadLibDBus()) { QDBusConnectionPrivate *d = 0; return QDBusConnection(d); } QMutexLocker locker(&_q_manager()->mutex); QDBusConnectionPrivate *d = _q_manager()->connection(name); if (d || name.isEmpty()) return QDBusConnection(d); d = new QDBusConnectionPrivate; DBusConnection *c = 0; QDBusErrorInternal error; switch (type) { case SystemBus: c = q_dbus_bus_get_private(DBUS_BUS_SYSTEM, error); break; case SessionBus: c = q_dbus_bus_get_private(DBUS_BUS_SESSION, error); break; case ActivationBus: c = q_dbus_bus_get_private(DBUS_BUS_STARTER, error); break; } d->setConnection(c, error); //setConnection does the error handling for us _q_manager()->setConnection(name, d); QDBusConnection retval(d); // create the bus service // will lock in QDBusConnectionPrivate::connectRelay() d->setBusService(retval); return retval; }
/*! Opens a connection to a private bus on address \a address and associate with it the connection name \a name. Returns a QDBusConnection object associated with that connection. */ QDBusConnection QDBusConnection::connectToBus(const QString &address, const QString &name) { // Q_ASSERT_X(QCoreApplication::instance(), "QDBusConnection::addConnection", // "Cannot create connection without a Q[Core]Application instance"); if (!qdbus_loadLibDBus()) { QDBusConnectionPrivate *d = 0; return QDBusConnection(d); } QMutexLocker locker(&_q_manager()->mutex); QDBusConnectionPrivate *d = _q_manager()->connection(name); if (d || name.isEmpty()) return QDBusConnection(d); d = new QDBusConnectionPrivate; // setConnection does the error handling for us QDBusErrorInternal error; DBusConnection *c = q_dbus_connection_open_private(address.toUtf8().constData(), error); if (c) { if (!q_dbus_bus_register(c, error)) { q_dbus_connection_unref(c); c = 0; } } d->setConnection(c, error); _q_manager()->setConnection(name, d); QDBusConnection retval(d); // create the bus service // will lock in QDBusConnectionPrivate::connectRelay() d->setBusService(retval); return retval; }