| 1 |
/*! |
| 2 |
@~chinese |
| 3 |
@ingroup dutil |
| 4 |
@file include/util/ddbusextendedabstractinterface.h |
| 5 |
|
| 6 |
该文件提供了一个扩展DBus接口工具类 |
| 7 |
|
| 8 |
@class Dtk::Core::DDBusExtendedAbstractInterface |
| 9 |
@brief 扩展DBus接口, 继承自QDBusAbstractInterface |
| 10 |
@details 和QDBusAbstractInterface相比, 该类连接了org.freedesktop.DBus.Properties接口, 提供了异步访问属性的接口, 可以方便地通过此类进行异步DBus通信. <br> |
| 11 |
同时此类提供了属性改变信号的分发和中继. |
| 12 |
|
| 13 |
@fn DDBusExtendedAbstractInterface::DDBusExtendedAbstractInterface(const QString &service, const QString &path, const char *interface, const QDBusConnection &connection, QObject *parent) |
| 14 |
@brief 构造函数 |
| 15 |
@param[in] service 该interface属于的服务 |
| 16 |
@param[in] path 该interface属于的对象路径 |
| 17 |
@param[in] interface 该interface实际连接的接口 |
| 18 |
@param[in] connection 用于连接该interface的DBus连接 |
| 19 |
@param[in] parent 父对象 |
| 20 |
@note 该构造函数受到保护, 只有子对象才能访问. |
| 21 |
|
| 22 |
@property Dtk::Core::DDBusExtendedAbstractInterface::sync |
| 23 |
@brief 是否同步获取属性 |
| 24 |
@details 当sync为false的时候, 在调用属性的get函数的时候会一直返回空值, 解决方法是监听属性的changed信号并自行保存一份缓存, 让changed信号修改这个缓存. |
| 25 |
|
| 26 |
@property Dtk::Core::DDBusExtendedAbstractInterface::useCache |
| 27 |
@brief 是否使用缓存 |
| 28 |
@details 如果使用缓存, 在内部获取属性的时候将不再进行DBus调用更新属性. |
| 29 |
|
| 30 |
@fn inline bool DDBusExtendedAbstractInterface::sync() const |
| 31 |
@brief 获取是否同步 |
| 32 |
@sa [sync](@ref Dtk::Core::DDBusExtendedAbstractInterface::sync) |
| 33 |
|
| 34 |
@fn void DDBusExtendedAbstractInterface::setSync(bool sync, bool autoStart) |
| 35 |
@brief 设置是否同步和自启动 |
| 36 |
@param[in] sync 是否同步 |
| 37 |
@param[in] autoStart 是否自启动 |
| 38 |
@sa [sync](@ref Dtk::Core::DDBusExtendedAbstractInterface::sync) |
| 39 |
|
| 40 |
|
| 41 |
@fn void DDBusExtendedAbstractInterface::setSync(bool sync) |
| 42 |
@brief 设置是否同步 |
| 43 |
@param[in] sync 是否是同步模式 |
| 44 |
@sa [sync](@ref Dtk::Core::DDBusExtendedAbstractInterface::sync) |
| 45 |
@details 该函数内部实现调用[setSync](@ref DDBusExtendedAbstractInterface::setSync(bool sync, bool autoStart)), autoStart参数值为true, 即默认自启动. |
| 46 |
|
| 47 |
@fn inline bool DDBusExtendedAbstractInterface::useCache() const |
| 48 |
@brief 获取是否使用缓存 |
| 49 |
@sa [useCache](@ref Dtk::Core::DDBusExtendedAbstractInterface::useCache) |
| 50 |
|
| 51 |
@fn inline void DDBusExtendedAbstractInterface::setUseCache() |
| 52 |
@brief 设置是否使用缓存 |
| 53 |
@sa [useCache](@ref Dtk::Core::DDBusExtendedAbstractInterface::useCache) |
| 54 |
|
| 55 |
@fn void DDBusExtendedAbstractInterface::getAllProperties() |
| 56 |
@brief 获取所有属性 |
| 57 |
@sa [sync](@ref Dtk::Core::DDBusExtendedAbstractInterface::sync) |
| 58 |
@details 该方法会调用org.freedesktop.DBus.Properties接口的GetAll方法, 获取所有属性并且发送属性改变信号, 如果是同步模式(sync为true), 该方法会使用同步调用call. <br> |
| 59 |
sync为false的时候会使用异步调用asyncCall. |
| 60 |
|
| 61 |
@fn inline QDBusError DDBusExtendedAbstractInterface::lastExtendedError() const |
| 62 |
@brief 获取上一次的错误 |
| 63 |
@return QDBusError 上一次由DBus调用引起的错误 |
| 64 |
|
| 65 |
@fn void DDBusExtendedAbstractInterface::startServiceProcess() |
| 66 |
@brief 启动服务进程 |
| 67 |
@details 该函数会调用org.freedesktop.DBus的服务的/路径的StartServiceByName方法启动DDBusExtendedAbstractInterface对应的Service. |
| 68 |
|
| 69 |
@fn void DDBusExtendedAbstractInterface::serviceValidChanged(const bool valid) const |
| 70 |
@brief 服务是否有效状态改变信号 |
| 71 |
@param[in] valid 服务是否有效 |
| 72 |
|
| 73 |
@fn void DDBusExtendedAbstractInterface::serviceStartFinished(const quint32 ret) const |
| 74 |
@brief 服务启动完成通知信号 |
| 75 |
@param[in] ret 启动服务的返回值 |
| 76 |
@details 启动服务是调用org.freedesktop.DBus服务的/路径的StartServiceByName方法, ret为StartServiceByName的返回值. |
| 77 |
|
| 78 |
@fn void DDBusExtendedAbstractInterface::propertyChanged(const QString &propertyName, const QVariant &value) |
| 79 |
@brief 属性改变信号 |
| 80 |
@param[in] propertyName 改变的属性名 |
| 81 |
@param[in] value 改变后的属性值 |
| 82 |
|
| 83 |
@fn void DDBusExtendedAbstractInterface::propertyInvalidated(const QString &propertyName) |
| 84 |
@brief 属性失效通知信号 |
| 85 |
@param[in] propertyName 失效的属性名 |
| 86 |
@details 该信号会在DBus属性改变但是本地反序列化失败的情况下发出. |
| 87 |
|
| 88 |
@fn void DDBusExtendedAbstractInterface::asyncPropertyFinished(const QString &propertyName) |
| 89 |
@brief 异步获取属性完成通知信号 |
| 90 |
@param[in] propertyName 获取成功的属性名 |
| 91 |
|
| 92 |
@fn void DDBusExtendedAbstractInterface::asyncSetPropertyFinished(const QString &propertyName) |
| 93 |
@brief 异步设置属性完成通知信号 |
| 94 |
@param[in] propertyName 设置成功的属性名 |
| 95 |
|
| 96 |
@fn void DDBusExtendedAbstractInterface::asyncGetAllPropertiesFinished() |
| 97 |
@brief 异步获取所有属性完成的通知信号 |
| 98 |
@sa [getAllProperties](@ref Dtk::Core::DDBusExtendedAbstractInterface::getAllProperties()) |
| 99 |
@details getAllProperties方法并没有返回值, 须监听此信号以实现完整功能. |
| 100 |
|
| 101 |
|
| 102 |
@fn void DDBusExtendedAbstractInterface::connectNotify(const QMetaMethod &signal) |
| 103 |
@brief 信号连接通知函数 |
| 104 |
@param[in] signal 连接到该对象的信号 |
| 105 |
@details 该函数重写了QObject的connectNotify函数, 当有某一个信号连接到该对象的时候, 该函数就会被调用. |
| 106 |
|
| 107 |
@fn void DDBusExtendedAbstractInterface::disconnectNotify(const QMetaMethod &signal) |
| 108 |
@brief 信号断开连接通知函数 |
| 109 |
@param[in] signal 断连的信号 |
| 110 |
@details 该函数重写了QObject的disconnectNotify函数, 当有某一个连接到该对象的信号断连时, 该函数就会被调用. |
| 111 |
|
| 112 |
@fn QVariant DDBusExtendedAbstractInterface::internalPropGet(const char *propname, void *propertyPtr) |
| 113 |
@brief 内部属性获取函数 |
| 114 |
@param[in] propname 属性名 |
| 115 |
@param[in] propertyPtr 属性缓存指针 |
| 116 |
@sa [useCache](@ref Dtk::Core::DDBusExtendedAbstractInterface::useCache) |
| 117 |
@sa [sync](@ref Dtk::Core::DDBusExtendedAbstractInterface::sync) |
| 118 |
@details 当useCache为true的时候, 该函数仅仅返回propertyPtr指向的内存拷贝. |
| 119 |
|
| 120 |
@fn void DDBusExtendedAbstractInterface::internalPropSet(const char *propname, const QVariant &value, void *propertyPtr) |
| 121 |
@brief 内部属性设置函数 |
| 122 |
@param[in] propname 属性名 |
| 123 |
@param[in] value 要设置的值 |
| 124 |
@param[in] propertyPtr 属性缓存指针 |
| 125 |
@sa [sync](@ref Dtk::Core::DDBusExtendedAbstractInterface::sync) |
| 126 |
|
| 127 |
*/ |