mirror of
https://gitee.com/openharmony/napi_generator
synced 2024-11-27 02:30:36 +00:00
在模板中增加注释
Signed-off-by: chen-zhongwei050 <chenzhongwei050@chinasoftinc.com>
This commit is contained in:
parent
90eb8134a3
commit
eda4d808a3
@ -1,6 +1,18 @@
|
||||
# Copyright (c) 2024 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.
|
||||
|
||||
import("//drivers/hdf_core/adapter/uhdf2/hdi.gni") # 编译idl必须要导入的模板
|
||||
hdi("[driver_name]") { # 目标名称,会生成两个so,分别对应 lib[driver_name]_client_v1.0.z.so 和 lib[driver_name]_stub_v1.0.z.so
|
||||
# package = "ohos.hdi.[driver_name].v1_0" # 包名,必须与idl路径匹配
|
||||
module_name = "[driver_name]_service" # module_name控制dirver文件中驱动描 述符(struct HdfDriverEntry)的moduleName
|
||||
sources = [ # 参与编译的idl文件
|
||||
"[driver_idl_name].idl", # 接口idl
|
||||
|
@ -1,4 +1,4 @@
|
||||
#Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
#Copyright (c) 2024 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
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2024 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
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2024 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
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
# Copyright (c) 2024 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
|
||||
|
@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
|
||||
#include <hdf_base.h>
|
||||
#include <hdf_device_desc.h>
|
||||
#include <hdf_log.h>
|
||||
@ -13,25 +28,37 @@ struct Hdf[driver_inter_name]Host {
|
||||
OHOS::sptr<OHOS::IRemoteObject> stub;
|
||||
};
|
||||
|
||||
// 处理客户端请求的Dispatch方法
|
||||
/*
|
||||
* 处理客户端请求的Dispatch方法: 处理来自客户端的IO请求
|
||||
* client:指向HdfDeviceIoClient结构体的指针,表示发起请求的客户端。
|
||||
* cmdId:命令ID,标识了要执行的命令或操作。
|
||||
* data:指向HdfSBuf结构体的指针,包含了请求的数据。
|
||||
* reply:指向另一个HdfSBuf结构体的指针,用于存放响应的数据。
|
||||
*/
|
||||
static int32_t [driver_inter_name]DriverDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data,
|
||||
struct HdfSBuf *reply)
|
||||
{
|
||||
auto *hdf[driver_inter_name]Host = CONTAINER_OF(client->device->service, struct Hdf[driver_inter_name]Host, ioService);
|
||||
|
||||
// 声明两个MessageParcel对象,用于序列化和反序列化IPC通信中的数据
|
||||
OHOS::MessageParcel *dataParcel = nullptr;
|
||||
OHOS::MessageParcel *replyParcel = nullptr;
|
||||
// 创建一个MessageOption对象,用于设置IPC通信的选项。
|
||||
OHOS::MessageOption option;
|
||||
|
||||
// 响应序列化:将HdfSBuf中的数据转换为MessageParcel对象。如果转换失败,记录错误并返回错误代码。
|
||||
if (SbufToParcel(data, &dataParcel) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%{public}s: invalid data sbuf object to dispatch", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
// 数据序列化:尝试将响应数据的HdfSBuf转换为MessageParcel对象。如果失败,也记录错误并返回错误代码。
|
||||
if (SbufToParcel(reply, &replyParcel) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%{public}s: invalid reply sbuf object to dispatch", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
// 调用stub对象的SendRequest方法,发送请求。这个方法执行实际的IPC调用,将cmdId和序列化后的请求数据dataParcel发送给服务端,并将响应数据反序列化到replyParcel中。
|
||||
return hdf[driver_inter_name]Host->stub->SendRequest(cmdId, *dataParcel, *replyParcel, option);
|
||||
}
|
||||
|
||||
@ -46,12 +73,14 @@ static int Hdf[driver_inter_name]DriverInit(struct HdfDeviceObject *deviceObject
|
||||
static int Hdf[driver_inter_name]DriverBind(struct HdfDeviceObject *deviceObject)
|
||||
{
|
||||
HDF_LOGI("%{public}s: driver bind start", __func__);
|
||||
// 创建对象:该对象是驱动服务的具体实现
|
||||
auto *hdf[driver_inter_name]Host = new (std::nothrow) Hdf[driver_inter_name]Host;
|
||||
if (hdf[driver_inter_name]Host == nullptr) {
|
||||
HDF_LOGE("%{public}s: failed to create create Hdf[driver_inter_name]Host object", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
// 为ioService结构体设置回调函数:设置的Dispatch函数用于处理IO请求
|
||||
hdf[driver_inter_name]Host->ioService.Dispatch = [driver_inter_name]DriverDispatch;
|
||||
hdf[driver_inter_name]Host->ioService.Open = NULL;
|
||||
hdf[driver_inter_name]Host->ioService.Release = NULL;
|
||||
@ -63,6 +92,7 @@ static int Hdf[driver_inter_name]DriverBind(struct HdfDeviceObject *deviceObject
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
// 使用ObjectCollector的GetOrNewObject方法获取或创建一个Stub对象。Stub对象是服务接口的客户端代理,用于发起远程调用。
|
||||
hdf[driver_inter_name]Host->stub = OHOS::HDI::ObjectCollector::GetInstance().GetOrNewObject(serviceImpl,
|
||||
OHOS::HDI::[driver_namespace_name]::V1_0::[driver_idl_name]::GetDescriptor());
|
||||
if (hdf[driver_inter_name]Host->stub == nullptr) {
|
||||
@ -71,6 +101,7 @@ static int Hdf[driver_inter_name]DriverBind(struct HdfDeviceObject *deviceObject
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
// 将ioService绑定到deviceObject,这样HDF框架就可以通过deviceObject来访问服务
|
||||
deviceObject->service = &hdf[driver_inter_name]Host->ioService;
|
||||
HDF_LOGI("%{public}s: driver bind end", __func__);
|
||||
return HDF_SUCCESS;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2024 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
|
||||
|
@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
|
||||
#include "v1_0/[driver_name]_interface_service.h"
|
||||
#include <hdf_base.h>
|
||||
#include "[driver_name]_log.h"
|
||||
@ -12,13 +27,16 @@ namespace [driver_namespace_name] {
|
||||
namespace V1_0 {
|
||||
extern "C" [driver_idl_name] *[driver_inter_name]ImplGetInstance(void)
|
||||
{
|
||||
// ×¢²áhidumper
|
||||
DevHostRegisterDumpHost(Get[driver_namespace_name]Dump);
|
||||
// [hdf-gen] Todo
|
||||
HDF_LOGI("%{public}s: [driver_idl_name] init", __func__);
|
||||
return new (std::nothrow) [driver_inter_name]Service();
|
||||
}
|
||||
|
||||
int32_t [driver_inter_name]Service::Helloworld(const std::string& sendMsg, std::string& recvMsg)
|
||||
{
|
||||
// [hdf-gen] Todo
|
||||
HDF_LOGI("%{public}s: [driver_namespace_name]Service::Helloworld print", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 OHOS_HDI_[upper_driver_name]_V1_0_[upper_driver_name]INTERFACESERVICE_H
|
||||
#define OHOS_HDI_[upper_driver_name]_V1_0_[upper_driver_name]INTERFACESERVICE_H
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Copyright (c) 2024 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
|
||||
|
Loading…
Reference in New Issue
Block a user