QDBus与gdbus的数据传递详解

在Linux平台的进程间通信多了一个dbus技术,应用还是非常广的,其中有一个应用模式是采用gdbus实现相关业务逻辑,采用QtService调用qdbus暴露出服务给客户使用。这种模式还是非常便捷的。不过QDBus和gdbus相关资料还请自行查找。这里只是针对他们的数据传递(函数的参数)进行详解。

1,框架的建立

首先我们需要根据业务需要建议一个xml文件hello.xml,描述interface以及包含的函数等信息,比如:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="introspect.xsl"?>
<node xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="/org/alibaba/kenton" xsi:noNamespaceSchemaLocation="introspect.xsd">
  <interface name="org.alibaba.kenton.hello">
    <version>1.0.0</version>
    <doc>
      <line>This is a test interface</line>
    </doc>
    <method name="GetVersion">
      <doc>
        <line>GetVersion = This method returns the API version implemented by the server application</line>
      </doc>
	  <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="SVersion"/>
      <arg name="version" type="(qqqs)" direction="out">
        <doc>
          <line>version = struct(major,minor,micro,date)</line>
          <line>major = major</line>
          <line>minor = minor</line>
          <line>micro = micro</line>
          <line>date = release date</line>
        </doc>
      </arg>
    </method>
  </interface>
</node>

a,QDBus端

这里,我们只是随便弄个interface以及一个函数名为GetVersion。有这个XML我们就可以利用工具qdbusxml2cpp创建对应的cpp文件。

qdbusxml2cpp hello.xml -i hello_type.h HelloInterface

这条命令用于创建qdbus对应的接口,HelloInterface.cpp/.h,供QtService接口调用

  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值