OpenHarmony 3.2 Release HDF的IDL文件初探(上)

1.IDL

安卓上我们熟知的aidl能够帮我们快速生成binder的代码,OpenHarmony 上也提供了此功能,用法与aidl相似.与安卓不同的地方以及和OpenHarmony 3.1不同的是:

  1. 不再需要在代码中分别引入proxy和sub,只需要在deps中是加入不同的包

  2. idl文件也与服务端解耦,需要单独编写bundle.json.

1. IDL 声明和引入.

1.IDL的bundle.json: drivers\interface\location\gnss\bundle.json
        "inner_kits": [
          {
            "name": "//drivers/interface/location/gnss/v1_0:liblocation_gnss_proxy_1.0",
            "header": {
              "header_files": [
              ],
              "header_base": "//drivers/interface/location/gnss"
            }
          },
          {
            "name": "//drivers/interface/location/gnss/v1_0:location_gnss_idl_headers",
            "header": {
              "header_files": [
              ],
              "header_base": "//drivers/interface/location/gnss"
            }
          }
        ]
2.proxy端引入:base\location\services\location_gnss\gnss\BUILD.gn
  external_deps = [
    ...
    "drivers_interface_location_agnss:liblocation_agnss_proxy_1.0",
    "drivers_interface_location_gnss:liblocation_gnss_proxy_1.0",
    ...
  ]
3.service端引入:drivers\peripheral\location\gnss\hdi_service\BUILD.gn
    external_deps = [
      "drivers_interface_location_agnss:location_gnss_idl_headers",
      ...
    ] 

2.IDL 文件编写

先看readme.md,可以简单了解一下idl文件规则 OpenHarmony IDL工具规格及使用说明书.目前OpenHarmony文档内容有点少,但是hdf中已经在使用,可能还没给上层开放.这里用的是HarmonyOS的介绍:

IDL文件编写规范

一个 HarmonyOS IDL 文件只能定义一个接口类,接口定义的形式使用 BNF 范式描述,示例如下:

<*interface_attributes_declaration*> ? interface <*interface_name_with_namespace*> { <*method_declaration*> ? }

<interface_attributes_declaration>是接口属性声明,当前支持 oneway、callback、full、lite 属性:(OpenHarmony的文档中只有oneway)

  1. oneway:表示该接口中的方法都是单向方法,即调用方法后不用等待该方法执行即可返回,该属性为可选项,如果无声明,则默认为同步调用方法
  2. callback:表示该接口为callback接口,即从下层实现中回调到上层服务中;
  3. full、lite:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值