dbus类型整理(D-BUS、QT、gdbus、python)

qt-dbus类型整理,最近在做dbus的类型,发现关于类型整理并没有详细介绍,总结一下,关于xml文件对应的整理。

 

 

基础类型
xml    D-Bus 等价类型    Qt DBUS    gdbus    python
y    BYTE    uchar        dbus.Byte
b    BOOLEAN    bool        dbus.Boolean
n    INT16    short        dbus.Int16
q    UINT16    ushort        dbus.UInt16
i    INT32    int        dbus.Int32
u    UINT32    uint        dbus.UInt32
x    INT64    qlonglong        dbus.Int64
t    UINT64    qulonglong        dbus.UInt64
d    DOUBLE    double    double    dbus.Double
s    STRING    QString    gchar *    dbus.String dbus.UTF8String(only python2)
v    VARIANT    QDBusVariant        
o    OBJECT_PATH    QDBusObjectPath        dbus.ObjectPath
g    SIGNATURE    QDBusSignature        
as    Array of [string]    QStringList
QList<QString>        
ai    Array of [int32]    QList<int>        
{sv}    Dict of {String,Variant}    QMap,key为string
value为Variant        
a        QList        
()    struct of { }    QVariant        
{}        QMap        # 复杂类型
penSUSE imagewriter is a GPL licensed project which contains an example of how to do this. (Relevant files: udisks2_interface.*)
as is Array of [string] . QList<QString> would fit this signature.
a{sv} is a dict of string:variant pairs. QVariantMap would fit this signature.

a{sa{sv}} is a dict of string:a{sv} pairs. QMap<QString, QVariantMap> would fit this signature.

a{oa{sa{sv}}} is a dict of objectpath:a{sa{sv}} pairs. QMap<QDBusObjectPath, QMap<QString, QVariantMap>> would fit this signature.

We should hide those angle-brackets behind some typedefs in a header file:

typedef QMap<QString, QVariantMap> InterfaceList; typedef QMap<QDBusObjectPath, InterfaceList> ManagedObjectList; Then declare their QMetaTypes in the same header file:

Q_DECLARE_METATYPE(InterfaceList) Q_DECLARE_METATYPE(ManagedObjectList) Then register them with the Qt metatype system at runtime:

qDBusRegisterMetaType(); qDBusRegisterMetaType(); Then we can annotate the XML:

<method name="GetManagedObjects">
    <arg type="a{oa{sa{sv}}}" name="objects" direction="out"> 
         <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="ManagedObjectList"/>                                 
     </arg> 
 </method> 
 <signal name="InterfacesAdded"> 
     <arg type="o" name="object"/> 
     <arg type="a{sa{sv}}" name="interfaces"> 
         <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="InterfaceList"/>
     </arg> 
  </signal>



xml    D-Bus 等价类型    Qt 数据类型
as    Array of [string]    QList<QString>
a{sv}    dict of string    QVariantMap
a{sa{sv}}    dict of objectpath    QMap<QString, QVariantMap>
a{oa{sa{sv}}}    dict of objectpath    QMap<QDBusObjectPath, QMap<QString, QVariantMap>>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值