6

Openharmony 实现的一个IPC的客户端和服务端(L2)

 2 years ago
source link: https://os.51cto.com/article/711573.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Openharmony 实现的一个IPC的客户端和服务端(L2)-51CTO.COM

5916fb164111dc1cf87edbfbe1efaf36.png
Openharmony 实现的一个IPC的客户端和服务端(L2)
作者:拓维信息_青松 2022-06-14 15:07:04
挺长时间没接触L2的设备开发,再看openharmony 3.1代码时候,发现3.1与3.0相比:编译的ohos.build已经去掉,取而代之的是bundle.json,有的目录结构也发生了变化。
a25211a7936360443d22759dba91393334a0df.png

​想了解更多关于开源的内容,请访问:​

​51CTO 开源基础软件社区​

​https://ost.51cto.com​

挺长时间没接触L2的设备开发,再看openharmony 3.1代码时候,发现3.1与3.0相比:

编译的ohos.build已经去掉,取而代之的是bundle.json,有的目录结构也发生了变化。

此文档:openharmony 3.1代码基础。

  • 3.1的编译配置(与3.0比,有些调整)
  • IPC动态库服务端工程。
  • IPC客户端。
  • safwk加载动态库服务端。
  • 客户端和服务端的通信.
    想对IPC通信了解深入,可以结合下面两篇文章和代码一起分析学习:
    ​Openharmony IPC通信(L2)​OpenHarmony SA 动态库服务 拉起的main入口
  • 本用例开发板(3516开发板:HiSpark_AI_Hi3516D_One_Light_VER.B开发板上测试)。

子系统配置

build\subsystem_config.json:

"myapp": {
    "path":"myapp",
    "name": "myapp"
  }
#夏日挑战赛# Openharmony 实现的一个IPC的客户端和服务端(L2)-开源基础软件社区

productdefine\common\products\Hi3516DV300.json:

"myapp:myappservice_test":{}
#夏日挑战赛# Openharmony 实现的一个IPC的客户端和服务端(L2)-开源基础软件社区

myapp\myappservice\bundle.json:

#夏日挑战赛# Openharmony 实现的一个IPC的客户端和服务端(L2)-开源基础软件社区

myapp\myappservice\BUILD.gn:

#夏日挑战赛# Openharmony 实现的一个IPC的客户端和服务端(L2)-开源基础软件社区

代码目录结构

#夏日挑战赛# Openharmony 实现的一个IPC的客户端和服务端(L2)-开源基础软件社区

myapp的代码见附件,关键部分有注释,方便对IPC交互的了解。

服务ID的添加

服务ID有统一的头文件。

foundation\distributedschedule\samgr\interfaces\innerkits\samgr_proxy\include\system_ability_definition.h。

MY_APP_SERVICE_ID                                = 9000,
...
{ MY_APP_SERVICE_ID, "MyAppService"},
#夏日挑战赛# Openharmony 实现的一个IPC的客户端和服务端(L2)-开源基础软件社区
#夏日挑战赛# Openharmony 实现的一个IPC的客户端和服务端(L2)-开源基础软件社区

要全量编译9000.xml 才能生产myappservice_sa.xml。

编译命令:./build.sh --product-name Hi3516DV300 --ccache。

修改开发板的读写权限

进入终端:hdc_std.exe shell
修改权限:mount -o remount,rw /
添加test目录:mkdir /data/test/
#夏日挑战赛# Openharmony 实现的一个IPC的客户端和服务端(L2)-开源基础软件社区

将编译文件发送到开发板对应目录:

#夏日挑战赛# Openharmony 实现的一个IPC的客户端和服务端(L2)-开源基础软件社区

修改客户端可执行权限。

切到对应的目录:cd /data/test/
修改成可执行:chmod 0755 myappclient
#夏日挑战赛# Openharmony 实现的一个IPC的客户端和服务端(L2)-开源基础软件社区

终端1:抓取日志。

#夏日挑战赛# Openharmony 实现的一个IPC的客户端和服务端(L2)-开源基础软件社区

终端2:启动服务。

sa_main /system/profile/myappservice_sa.xml
#夏日挑战赛# Openharmony 实现的一个IPC的客户端和服务端(L2)-开源基础软件社区

终端3:启动客户端。

/data/test/myappclient

下图是客户端和服务端的交互输出结果。

#夏日挑战赛# Openharmony 实现的一个IPC的客户端和服务端(L2)-开源基础软件社区

注意:hdc_std.exe工具,如果3.1的编译不能连接设备。可以试一下最新主干代码来编译hdc工具。

编译命令:./build.sh --product-name ohos-sdk --ccache,参考​​​developtools_hdc​​。

​想了解更多关于开源的内容,请访问:​

​51CTO 开源基础软件社区​

​https://ost.51cto.com​​。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK