⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qdbusconnection.cpp

📁 QT 开发环境里面一个很重要的文件
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    return false;}/*!    Registers the object \a object at path \a path and returns true if    the registration was successful. The \a options parameter    specifies how much of the object \a object will be exposed through    D-Bus.    This function does not replace existing objects: if there is already an object registered at    path \a path, this function will return false. Use unregisterObject() to unregister it first.    You cannot register an object as a child object of an object that    was registered with QDBusConnection::ExportChildObjects.*/bool QDBusConnection::registerObject(const QString &path, QObject *object, RegisterOptions options){    Q_ASSERT_X(QDBusUtil::isValidObjectPath(path), "QDBusConnection::registerObject",               "Invalid object path given");    if (!d || !d->connection || !object || !options || !QDBusUtil::isValidObjectPath(path))        return false;    QStringList pathComponents = path.split(QLatin1Char('/'));    if (pathComponents.last().isEmpty())        pathComponents.removeLast();    QWriteLocker locker(&d->lock);    // lower-bound search for where this object should enter in the tree    QDBusConnectionPrivate::ObjectTreeNode *node = &d->rootNode;    int i = 1;    while (node) {        if (pathComponents.count() == i) {            // this node exists            // consider it free if there's no object here and the user is not trying to            // replace the object sub-tree            if ((options & ExportChildObjects && !node->children.isEmpty()) || node->obj)                return false;            // we can add the object here            node->obj = object;            node->flags = options;            d->registerObject(node);            //qDebug("REGISTERED FOR %s", path.toLocal8Bit().constData());            return true;        }        // find the position where we'd insert the node        QVector<QDBusConnectionPrivate::ObjectTreeNode::Data>::Iterator it =            qLowerBound(node->children.begin(), node->children.end(), pathComponents.at(i));        if (it != node->children.constEnd() && it->name == pathComponents.at(i)) {            // match: this node exists            node = it->node;            // are we allowed to go deeper?            if (node->flags & ExportChildObjects) {                // we're not                qDebug("Cannot register object at %s because %s exports its own child objects",                       qPrintable(path), qPrintable(pathComponents.at(i)));                return false;            }        } else {            // add entry            QDBusConnectionPrivate::ObjectTreeNode::Data entry;            entry.name = pathComponents.at(i);            entry.node = new QDBusConnectionPrivate::ObjectTreeNode;            node->children.insert(it, entry);            node = entry.node;        }        // iterate        ++i;    }    Q_ASSERT_X(false, "QDBusConnection::registerObject", "The impossible happened");    return false;}/*!    Unregisters an object that was registered with the registerObject() at the object path given by    \a path and, if \a mode is QDBusConnection::UnregisterTree, all of its sub-objects too.    Note that you cannot unregister objects that were not registered with registerObject().*/void QDBusConnection::unregisterObject(const QString &path, UnregisterMode mode){    if (!d || !d->connection || !QDBusUtil::isValidObjectPath(path))        return;    QStringList pathComponents = path.split(QLatin1Char('/'));    QWriteLocker locker(&d->lock);    QDBusConnectionPrivate::ObjectTreeNode *node = &d->rootNode;    int i = 1;    // find the object    while (node) {        if (pathComponents.count() == i) {            // found it            node->obj = 0;            node->flags = 0;            if (mode == UnregisterTree) {                // clear the sub-tree as well                node->clear();  // can't disconnect the objects because we really don't know if they can                                // be found somewhere else in the path too            }            return;        }        QVector<QDBusConnectionPrivate::ObjectTreeNode::Data>::ConstIterator it =            qLowerBound(node->children.constBegin(), node->children.constEnd(), pathComponents.at(i));        if (it == node->children.constEnd() || it->name != pathComponents.at(i))            break;              // node not found        node = it->node;        ++i;    }}/*!    Return the object that was registered with the registerObject() at the object path given by    \a path.*/QObject *QDBusConnection::objectRegisteredAt(const QString &path) const{    Q_ASSERT_X(QDBusUtil::isValidObjectPath(path), "QDBusConnection::registeredObject",               "Invalid object path given");    if (!d || !d->connection || !QDBusUtil::isValidObjectPath(path))        return false;    QStringList pathComponents = path.split(QLatin1Char('/'));    if (pathComponents.last().isEmpty())        pathComponents.removeLast();    // lower-bound search for where this object should enter in the tree    QDBusConnectionPrivate::ObjectTreeNode *node = &d->rootNode;    int i = 1;    while (node) {        if (pathComponents.count() == i)            return node->obj;        QVector<QDBusConnectionPrivate::ObjectTreeNode::Data>::ConstIterator it =            qLowerBound(node->children.constBegin(), node->children.constEnd(), pathComponents.at(i));        if (it == node->children.constEnd() || it->name != pathComponents.at(i))            break;              // node not found        node = it->node;        ++i;    }    return 0;}/*!    Returns a QDBusConnectionInterface object that represents the    D-BUS server interface on this connection.*/QDBusConnectionInterface *QDBusConnection::interface() const{    if (!d)        return 0;    return d->busService;}/*!    Returns true if this QDBusConnection object is connected.    If it isn't connected, calling connectToBus() on the same    connection name will not make be connected. You need to call the    QDBusConnection constructor again.*/bool QDBusConnection::isConnected() const{    return d && d->connection && dbus_connection_get_is_connected(d->connection);}/*!    Returns the last error that happened in this connection.    This function is provided for low-level code. If you're using    QDBusInterface::call(), error codes are reported by its return    value.    \sa QDBusInterface, QDBusMessage*/QDBusError QDBusConnection::lastError() const{    return d ? d->lastError : QDBusError();}/*!    Returns the unique connection name for this connection, if this QDBusConnection object is    connected, or an empty QString otherwise.    A Unique Connection Name is a string in the form ":x.xxx" (where x    are decimal digits) that is assigned by the D-Bus server daemon    upon connection. It uniquely identifies this client in the bus.    This function returns an empty QString for peer-to-peer connections.*/QString QDBusConnection::baseService() const{    return d->baseService();}/*!    Attempts to register the \a serviceName on the D-BUS server and    returns true if the registration succeded. The registration will    fail if the name is already registered by another application.    \sa unregisterService(), QDBusConnectionInterface::registerService()*/bool QDBusConnection::registerService(const QString &serviceName){    if (d) d->registerService(serviceName);    return interface()->registerService(serviceName);}/*!    Unregisters the service \a serviceName that was previously    registered with registerService() and returns true if it    succeeded.    \sa registerService(), QDBusConnectionInterface::unregisterService()*/bool QDBusConnection::unregisterService(const QString &serviceName){    if (d) d->unregisterService(serviceName);    return interface()->unregisterService(serviceName);}static const char _q_sessionBusName[] = "qt_default_session_bus";static const char _q_systemBusName[] = "qt_default_system_bus";class QDBusDefaultConnection: public QDBusConnection{    const char *ownName;public:    inline QDBusDefaultConnection(BusType type, const char *name)        : QDBusConnection(connectToBus(type, QString::fromLatin1(name))), ownName(name)    { }    inline ~QDBusDefaultConnection()    { disconnectFromBus(QString::fromLatin1(ownName)); }};Q_GLOBAL_STATIC_WITH_ARGS(QDBusDefaultConnection, _q_sessionBus,                          (QDBusConnection::SessionBus, _q_sessionBusName))Q_GLOBAL_STATIC_WITH_ARGS(QDBusDefaultConnection, _q_systemBus,                          (QDBusConnection::SystemBus, _q_systemBusName))QDBusConnection QDBusConnection::sessionBus(){    return *_q_sessionBus();}QDBusConnection QDBusConnection::systemBus(){    return *_q_systemBus();}/*!  Returns the connection that sent the signal, if called in a slot activated  by QDBus; otherwise it returns 0.*/QDBusConnection QDBusConnection::sender(){    return QDBusConnection(_q_manager()->sender());}/*!  \internal*/void QDBusConnectionPrivate::setSender(const QDBusConnectionPrivate *s){    _q_manager()->setSender(s);}/*!    \namespace QDBus    \inmodule QtDBus    \brief The QDBus namespace contains miscellaneous identifiers used    throughout the QtDBus library.*//*!    \enum QDBus::CallMode    This enum describes the various ways of placing a function call. The valid modes are:    \value NoBlock              Place the call but don't wait for the reply (the reply's contents                                will be discarded).    \value Block                Don't use an event loop to wait for a reply, but instead block on                                network operations while waiting. This means the                                user-interface may not be updated until the function returns.    \value BlockWithGui         Use the Qt event loop to wait for a reply. This means that the                                user-interface will stay responsive (processing input events),                                but it also means other events may happen, like signal delivery                                and other D-Bus method calls.    \value AutoDetect           Automatically detect if the called function has a reply.    When using BlockWithGui, applications must be prepared for reentrancy in any function.*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -