style: modify service tool docs

Signed-off-by: gou-jingjing <goujingjing@kaihong.com>
This commit is contained in:
gou-jingjing 2023-05-12 11:59:46 +08:00 committed by zhaojunxia
parent c7aa2520e0
commit 8a082b8186
12 changed files with 214 additions and 85 deletions

View File

@ -295,16 +295,6 @@
}
```
在vendor/hihope/rk3568/security_config/high_privilege_process_list.json中增加以下配置
```
{
"name": "napitest",
"uid": "system",
"gid": ["root", "system"]
}
```
### 编译验证
编译成功后,就会在 /out/产品名/packages/phone/system/lib/module/ 生成libnapitest.z.so如下所示

View File

@ -56,28 +56,17 @@
### 工具输出
根据使用者指定的.h头文件工具会输出SERVICE框架代码。为了方便使用者快速上手工具可供测试的.h文件内容如下所示
根据使用者指定的.h头文件工具会输出SERVICE框架代码。为了方便使用者快速上手工具可供测试的.h文件如下所示
[test.h](https://gitee.com/openharmony/napi_generator/tree/master/hdc/service/examples/test.h)
注意:.h文件中待生成的主class必须加注释@brief service服务提供IPC调用接口 ,如下所示:
```
#ifndef EXAM_H
#define EXAM_H
using namespace std;
namespace OHOS{
namespace Example{
/**
* @brief service服务提供IPC调用接口
* @ServiceClass
*/
class Exam{
public:
std::string getServName();
int32_t doSum(int32_t num1, int32_t num2);
};
}
}
#endif
/**
* @brief service服务提供IPC调用接口
* @ServiceClass
*/
```
在window环境下的根据输入.h文件生成的输出文件如下所示

View File

@ -6,18 +6,18 @@
## 编译
将生成的整个xxxservice目录复制到OpenHarmony源码根目录下与base、foundation目录平级
将生成的整个testservice目录复制到OpenHarmony源码根目录下与base、foundation目录平级
### 修改系统公共文件
### OpenHarmony 3.1 release
#### OpenHarmony 3.1 release
#### 修改系统公共文件
1. 服务配置
foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include/system_ability_definition.h增加以下两行(其中SERVICE_ID与sa_profile目录下的xml文件名保持一致)
foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include/system_ability_definition.h增加以下两行(ID说明 TEST_SERVICE_ID值与用户指定的ID一致TEST_SERVICE_ID宏值定义必须为这个因为代码中使用的就是这个)
```
XXX_SERVICE_ID = 9001,
{XXX_SERVICE_ID, "xxxservice" },
TEST_SERVICE_ID = 9016,
{TEST_SERVICE_ID, "testservice" },
```
2. 子系统配置
@ -25,9 +25,9 @@
增加以下内容
```
"xxxservice": {
"path":"xxxservice",
"name": "xxxservice"
"testservice": {
"path":"testservice",
"name": "testservice"
}
```
@ -35,18 +35,136 @@
productdefine/common/products/Hi3516DV300.json
```
"xxxservice:xxxservice_part":{}
"testservice:testservice_part":{}
```
#### OpenHarmony 3.2 release
### OpenHarmony 3.2 release
#### 修改编译文件
1. 修改testservice/BUILD.gn文件将utils/native 改为 commonlibrary/c_utils将samgr_standard改为samgr。修改后的BUILD.gn文件内容如下所示
```
import("//build/ohos.gni")
ohos_shared_library("testservice") {
sources = [
"//testservice/src/i_test_service.cpp",
"//testservice/src/test_service_stub.cpp",
"//testservice/src/test_service.cpp"
]
include_dirs = [
"//testservice/include",
"//testservice/interface",
"//commonlibrary/c_utils/base/include"
]
deps = [
"//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara",
"//commonlibrary/c_utils/base:utils",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
"startup_l2:syspara",
]
part_name = "testservice_part"
subsystem_name = "testservice"
}
ohos_executable("testclient") {
sources = [
"//testservice/src/i_test_service.cpp",
"//testservice/src/test_service_proxy.cpp",
"//testservice/src/test_client.cpp"
]
include_dirs = [
"//testservice/include",
"//testservice/interface",
"//commonlibrary/c_utils/base/include"
]
deps = [
"//commonlibrary/c_utils/base:utils",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"samgr:samgr_proxy",
]
part_name = "testservice_part"
subsystem_name = "testservice"
}
```
2. 修改testservice/bundle.json文件将"name": "@ohos/testservice"修改为 "name": "@ohos/testservice_part";将"samgr_standard"改为"samgr""utils_base"修改为"c_utils"修改后的bundle.json文件内容如下所示
```
{
"name": "@ohos/testservice_part",
"description": "system ability framework test",
"homePage": "https://gitee.com/",
"version": "3.1",
"license": "Apache License 2.0",
"repository": "",
"publishAs": "code-segment",
"segment": {
"destPath": "testservice"
},
"dirs": {},
"scripts": {},
"component": {
"name": "testservice_part",
"subsystem": "testservice",
"adapted_system_type": [
"standard"
],
"rom": "2048KB",
"ram": "~4096KB",
"deps": {
"components": [
"hiviewdfx_hilog_native",
"ipc",
"samgr",
"c_utils",
"safwk",
"startup_l2"
],
"third_party": [ "libxml2" ]
},
"build": {
"sub_component": [
"//testservice:testservice",
"//testservice/sa_profile:testservice_sa_profile",
"//testservice:testclient",
"//testservice/etc:test_service_init"
],
"inner_kits": [
],
"test": [
]
}
}
}
```
#### 修改系统公共文件
1. 服务配置
foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include/system_ability_definition.h增加以下两行(其中SERVICE_ID与sa_profile目录下的xml文件名保持一致)
foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include/system_ability_definition.h增加以下两行(ID说明 TEST_SERVICE_ID值与用户指定的ID一致TEST_SERVICE_ID宏值定义必须为这个因为代码中使用的就是这个)
```
XXX_SERVICE_ID = 9001,
{XXX_SERVICE_ID, "xxxservice" },
TEST_SERVICE_ID = 9016,
{TEST_SERVICE_ID, "testservice" },
```
2. 子系统配置
@ -56,9 +174,9 @@
增加以下内容
```
"xxxservice": {
"path":"xxxservice",
"name": "xxxservice"
"testservice": {
"path":"testservice",
"name": "testservice"
}
```
@ -76,10 +194,10 @@
```
{
"subsystem": "xxxservice",
"subsystem": "testservice",
"components": [
{
"component": "xxxservice_part",
"component": "testservice_part",
"features": []
}
]
@ -98,7 +216,7 @@
```
{
"name": "xxxservice",
"name": "testservice",
"uid": "system",
"gid": ["root", "system"]
}
@ -107,14 +225,20 @@
### 补充 服务端/客户端 业务逻辑实现
**服务端**
xxx_service.cpp
在注释“// TODO: Invoke the business implementation”处添加各个接口的服务端实现代码
远程方法的参数包装已在生成代码xxx_service_stub.cpp中统一处理开发人员无需关注
test_service.cpp
在testservice/src/test_service.cpp注释“// TODO: Invoke the business implementation”处添加各个接口的服务端实现代码当前版本生成服务端代码需要用户先初始化给int ret值赋初值0如下所示
![](./../figures/service_init_example.png)
远程方法的参数包装已在生成代码test_service_stub.cpp中统一处理开发人员无需关注
**客户端**
xxx_client.cpp 为自动生成的客户端样例代码。编译烧录后,会在/system/bin/目录下生成可执行程序xxx_client
在main中使用proxy对象进行远程方法调用参考注释示例。
远程方法的参数包装已在生成代码xxx_service_proxy.cpp中统一处理开发人员无需关注
test_client.cpp 为自动生成的客户端样例代码。编译烧录后,会在/system/bin/目录下生成可执行程序test_client
在testservice/src/test_client.cpp的main函数中使用proxy对象进行远程方法调用参考注释示例。如下图
![](./../figures/service_client_proxy_example.png)
远程方法的参数包装已在生成代码test_service_proxy.cpp中统一处理开发人员无需关注
编码完成后,执行镜像编译命令
@ -140,17 +264,20 @@ xxx_client.cpp 为自动生成的客户端样例代码。编译烧录后,会
查看服务端进程是否已正常启动
```
ps -ef | grep xxxservice
system 288 1 0 00:02:13 ? 00:00:00 xxxservice_sa --- 服务进程已正常运行
ps -ef | grep testservice
system 288 1 0 00:02:13 ? 00:00:00 testservice_sa --- 服务进程已正常运行
```
如下图所示:
![](./../figures/service_init_success.png)
运行客户端
```
/system/bin/xxxclient
/system/bin/testclient
```
(客户端具体执行哪些远程调用方法请在xxx_client.cpp的main方法中实现)
(客户端具体执行哪些远程调用方法请在test_client.cpp的main方法中实现)

View File

@ -7,7 +7,7 @@ SERVICE框架生成工具支持三种入口分别是可执行程序、VS Code
下载文件说明如下:
│ │ |── service-gen-0.0.1.vsix # VS Code插件
│ │ |── service-gen-0.0.1.vsix # VS Code插件
│ │ |── header_parser.exe # python脚本独立程序
│ │ |── header_parser # python脚本独立程序
│ │ |── service-gen-linux # Linux可执行程序
@ -32,11 +32,11 @@ SERVICE框架生成工具支持三种入口分别是可执行程序、VS Code
2.将待转换的.h文件放到任意目录下建议放到可执行程序service-gen-linux与header_parser同级目录下如下所示
harmony@Ubuntu-64:~/service/napi_generator_8/hdc/service-gen/examples$ ls
exam.h header_parser service-gen-linux
test.h header_parser service-gen-linux
3.在终端中进入到可执行程序service-gen-linux所在的目录并运行service-gen-linux命令如下
harmony@Ubuntu-64:~/service/napi_generator_8/hdc/service-gen/examples$ ./service-gen-linux -f exam.h -o ./ -s 9001
harmony@Ubuntu-64:~/service/napi_generator_8/hdc/service-gen/examples$ ./service-gen-linux -f test.h -o ./ -s 9016
其中,参数详情如下:
-f定义远程服务的.h文件
@ -47,24 +47,24 @@ SERVICE框架生成工具支持三种入口分别是可执行程序、VS Code
4.运行成功后会在当前目录下生成对应的文件,如下所示:
harmony@Ubuntu-64:~/service/napi_generator_8/hdc/service-gen/examples$ ls
exam.h header_parser napi_gen.log service-gen-linux testaservice
test.h header_parser napi_gen.log service-gen-linux testservice
#### Windows
1.下载python脚本可执行程序header_parser.exe与linux可执行程序service-gen-win.exe下载链接如下
1.下载python脚本可执行程序header_parser.exe与windows可执行程序service-gen-win.exe下载链接如下
[下载链接](暂无)
2.将要转换的.h文件放到任意目录下建议放到可执行程序service-gen-win.exe与header_parser.exe同级目录下如下所示
E:\demo\service>dir /B
exam.h
test.h
header_parser.exe
service-gen-win.exe
3.在终端中进入到可执行程序service-gen-win.exe所在的目录并运行service-gen-win.exe命令如下
E:\demo\service>service-gen-win.exe -f exam.h -o ./ -s 9001
E:\demo\service>service-gen-win.exe -f test.h -o ./ -s 9016
其中,参数详情如下:
-f定义远程服务的.h文件
@ -75,11 +75,11 @@ SERVICE框架生成工具支持三种入口分别是可执行程序、VS Code
4.运行成功后会在当前目录下生成对应的文件,如下所示:
E:\demo\service>dir /B
exam.h
test.h
header_parser.exe
napi_gen.log
service-gen-win.exe
testaservice
testservice
#### Mac

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TEST_H
#define TEST_H
namespace OHOS {
namespace Example {
/**
* @brief service服务IPC调用接口
* @ServiceClass
*/
class test {
public:
int testFunc(int v1, int v2, bool v3);
};
} // namespace Example
} // namespace OHOS
#endif // TEST_H

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 KiB

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

@ -42,24 +42,17 @@ SERVICE框架生成工具根据用户提供的.h头文件工具会自动
### 工具输出
根据使用者指定的.h头文件工具会输出SERVICE框架代码。为了方便使用者快速上手工具可供测试的.h文件内容如下所示
根据使用者指定的.h头文件工具会输出SERVICE框架代码。为了方便使用者快速上手工具可供测试的.h文件如下所示
[test.h](https://gitee.com/openharmony/napi_generator/tree/master/hdc/service/examples/test.h)
注意:.h文件中待生成的主class必须加注释@brief service服务提供IPC调用接口 ,如下所示:
```
#ifndef EXAM_H
#define EXAM_H
using namespace std;
namespace OHOS{
namespace Example{
class Exam{
public:
std::string getServName();
int32_t doSum(int32_t num1, int32_t num2);
};
}
}
#endif
/**
* @brief service服务提供IPC调用接口
* @ServiceClass
*/
```
在window环境下的根据输入.h文件生成的输出文件如下所示