1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <hdf_base.h>
17 #include <hdf_device_desc.h>
18 #include <hdf_sbuf_ipc.h>
19 #include <osal_mem.h>
20 #include "thermal_interface_impl.h"
21
22 using namespace OHOS::HDI::Thermal::V1_0;
23
24 struct HdfThermalInterfaceHost {
25 struct IDeviceIoService ioservice;
26 ThermalInterfaceImpl *service;
27 };
28
ThermalInterfaceDriverDispatch(struct HdfDeviceIoClient * client,int cmdId,struct HdfSBuf * data,struct HdfSBuf * reply)29 static int32_t ThermalInterfaceDriverDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data,
30 struct HdfSBuf *reply)
31 {
32 struct HdfThermalInterfaceHost *hdfThermalInterfaceHost =
33 CONTAINER_OF(client->device->service, struct HdfThermalInterfaceHost, ioservice);
34
35 OHOS::MessageParcel *dataParcel = nullptr;
36 OHOS::MessageParcel *replyParcel = nullptr;
37 OHOS::MessageOption option;
38
39 (void)SbufToParcel(reply, &replyParcel);
40 if (SbufToParcel(data, &dataParcel) != HDF_SUCCESS) {
41 return HDF_ERR_INVALID_PARAM;
42 }
43
44 return hdfThermalInterfaceHost->service->OnRemoteRequest(cmdId, *dataParcel, *replyParcel, option);
45 }
46
HdfThermalInterfaceDriverInit(struct HdfDeviceObject * deviceObject)47 int HdfThermalInterfaceDriverInit(struct HdfDeviceObject *deviceObject)
48 {
49 return HDF_SUCCESS;
50 }
51
HdfThermalInterfaceDriverBind(struct HdfDeviceObject * deviceObject)52 int HdfThermalInterfaceDriverBind(struct HdfDeviceObject *deviceObject)
53 {
54
55 struct HdfThermalInterfaceHost *hdfThermalInterfaceHost = (struct HdfThermalInterfaceHost *)OsalMemAlloc(
56 sizeof(struct HdfThermalInterfaceHost));
57 if (hdfThermalInterfaceHost == nullptr) {
58 return HDF_FAILURE;
59 }
60
61 hdfThermalInterfaceHost->ioservice.Dispatch = ThermalInterfaceDriverDispatch;
62 hdfThermalInterfaceHost->ioservice.Open = NULL;
63 hdfThermalInterfaceHost->ioservice.Release = NULL;
64 hdfThermalInterfaceHost->service = new ThermalInterfaceImpl();
65
66 deviceObject->service = &hdfThermalInterfaceHost->ioservice;
67 return HDF_SUCCESS;
68 }
69
HdfThermalInterfaceDriverRelease(struct HdfDeviceObject * deviceObject)70 void HdfThermalInterfaceDriverRelease(struct HdfDeviceObject *deviceObject)
71 {
72 struct HdfThermalInterfaceHost *hdfThermalInterfaceHost =
73 CONTAINER_OF(deviceObject->service, struct HdfThermalInterfaceHost, ioservice);
74 delete hdfThermalInterfaceHost->service;
75 OsalMemFree(hdfThermalInterfaceHost);
76 }
77
78 struct HdfDriverEntry g_thermalinterfaceDriverEntry = {
79 .moduleVersion = 1,
80 .moduleName = "thermal_interface_service",
81 .Bind = HdfThermalInterfaceDriverBind,
82 .Init = HdfThermalInterfaceDriverInit,
83 .Release = HdfThermalInterfaceDriverRelease,
84 };
85
86 #ifndef __cplusplus
87 extern "C" {
88 #endif
89 HDF_INIT(g_thermalinterfaceDriverEntry);
90 #ifndef __cplusplus
91 }
92 #endif
93
94