dbus 数据类型

版权声明:本文系作者原创。未经许可,不得转载。

参考文档:
在XML文件中,定义dbus的信号和槽函数,然后用qdbusxml2cpp工具生成代码。
用命令查看版本号,必须大于等于0.8,否则不支持新特性。
$ qdbusxml2cpp  -V
qdbusxml2cpp version 0.8
D-Bus binding tool for Qt

XML解释如下:
name:参数名
direction: in为传入;out为传出
method: 槽函数
signal:信号函数
type:
s: string  对应于QT中的QString
b:bool   对应于QT中的bool
i:int32   对应于QT中的int
a:array   对应于QT中的QList
():struct   对应于QT中的QVariant        注:在信号函数中,不能用r表示struct。槽函数中可以。 
as: 类型为string的array,对应于QT中的QStringList 或者  QList < QString >
ai: 类型为int32的array,对应于QT中的QList < int >
(ii): 类型为含有两个int32的struct。对应于QT中的QVariant
a(sss):   类型为struct的array, struct中包含三个string字段.对应于QT中的QVariantList
{sv}: 键值对 其中 key为string,value为Variant, 对应于QT中的QMap
a{sv}: 类型为键值对的数组,键值对中 key为string,value为VariantQVariantMap

复合类型必须使用annotation来指定dbus数据类型与QT数据类型的对应值

<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
  <interface name="cn.cmos.profiled">
    <method name="get_profile">
      <arg name="profile" type="s" direction="out"/>
    </method>
    <method name="has_profile">
      <arg name="profile" type="s" direction="in"/>
      <arg name="exists" type="s" direction="out"/>
    </method>
    <method name="set_profile">
      <arg name="profile" type="s" direction="in"/>
      <arg name="success" type="b" direction="out"/>
    </method>
    <method name="get_profiles">
      <arg name="profiles" type="as" direction="out"/>
      <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QStringList"/>
    </method>
    <method name="get_keys">
      <arg name="keys" type="as" direction="out"/>
      <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QStringList"/>
    </method>
    <method name="get_value">
      <arg name="profile" type="s" direction="in"/>
      <arg name="key" type="s" direction="in"/>
      <arg name="value" type="as" direction="out"/>
      <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QStringList"/>
    </method>
    <method name="has_value">
      <arg name="key" type="s" direction="in"/>
      <arg name="exists" type="b" direction="out"/>
    </method>
    <method name="is_writable">
      <arg name="key" type="s" direction="in"/>
      <arg name="writable" type="b" direction="out"/>
    </method>
    <method name="set_value">
      <arg name="profile" type="s" direction="in"/>
      <arg name="key" type="s" direction="in"/>
      <arg name="val" type="s" direction="in"/>
      <arg name="success" type="b" direction="out"/>
    </method>
    <method name="get_type">
      <arg name="profile" type="s" direction="in"/>
      <arg name="key" type="s" direction="in"/>
      <arg name="type" type="s" direction="out"/>
    </method>
    <method name="get_values">
      <arg name="profile" type="s" direction="in"/>
      <arg name="values" type="a(sss)" direction="out"/>
      <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantList"/>
    </method>
    <signal name="profile_changed">
      <arg name="change" type="b"/>
      <arg name="active" type="b"/>
      <arg name="profile" type="s"/>
      <arg name="values" type="a(sss)"/>
      <annotation name="org.qtproject.QtDBus.QtTypeName.In3" value="QVariantList"/>
    </signal>
  </interface>
</node>



<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">

<node name="/org/freesmartphone/GSM/Device">
  <interface name="org.freesmartphone.GSM.SMS">
    <method name="SendMessage">
       <arg name="number" type="s"/>
       <arg name="contents" type="s"/>
       <arg type="i" direction="out"/>
    </method>
    <method name="windowInfo">
      <arg type="i" direction="in"/>
      <arg type="a{sv}" direction="out"/>
      <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
    </method>
    <signal name="IncomingMessage">
       <arg name="address" type="s"/>
       <arg name="contents" type="s"/>
       <arg name="features" type="a{sv}"/>
       <annotation name="org.qtproject.QtDBus.QtTypeName.In2" value="QVariantMap"/>
        <arg name="shit" type="ai"/>
      <annotation name="org.qtproject.QtDBus.QtTypeName.In3" value="QList &lt; int &gt; "/>
        <arg name="fuck" type="a(sss)"/>
      <annotation name="org.qtproject.QtDBus.QtTypeName.In4" value="QVariantList"/>
    </signal>
  </interface>
</node>
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值