在模板中增加注释

Signed-off-by: chen-zhongwei050 <chenzhongwei050@chinasoftinc.com>
This commit is contained in:
chen-zhongwei050 2024-08-02 14:55:18 +08:00
parent 90eb8134a3
commit eda4d808a3
10 changed files with 84 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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