From cc86c5e69aff716e0325c1263b11187c0684f31e Mon Sep 17 00:00:00 2001 From: yuanbo Date: Sat, 20 Nov 2021 18:38:40 +0800 Subject: [PATCH] support dynamic register device Signed-off-by: yuanbo --- khdf/liteos/BUILD.gn | 2 + khdf/liteos/Makefile | 2 + khdf/liteos/model/usb/host/BUILD.gn | 5 +- .../model/usb/host/include/usb_pnp_manager.h | 51 ---- .../model/usb/host/src/usb_pnp_manager.c | 41 +-- .../model/usb/host/src/usb_pnp_notify.c | 35 ++- khdf/liteos_m/core/BUILD.gn | 2 + .../core/common/src/devmgr_service_start.c | 21 +- uhdf2/hdi/src/devmgr_hdi.c | 82 ++--- .../servmgr/service_manager_hdi_c_test.cpp | 86 +++++- .../test/servmgr/service_manager_hdi_test.cpp | 17 +- uhdf2/host/BUILD.gn | 6 +- uhdf2/host/include/hdf_device_thread.h | 2 +- uhdf2/host/src/devhost_object_config.c | 5 +- uhdf2/host/src/devhost_service_full.c | 2 +- uhdf2/host/src/devhost_service_stub.c | 19 +- uhdf2/host/src/device_service_stub.c | 48 ++- uhdf2/host/src/devmgr_service_proxy.c | 51 +++- uhdf2/host/src/devsvc_manager_proxy.c | 1 - uhdf2/host/src/driver_loader_full.c | 2 +- uhdf2/host/src/hdf_device_full.c | 117 -------- uhdf2/host/src/hdf_device_thread.c | 28 +- .../test/unittest/sample_driver/sample_hdi.h | 4 + .../sample_driver/sample_hdi_service.c | 83 ++++- .../sample_driver/sample_hdi_service_stub.c | 28 ++ uhdf2/include/devhost/hdf_device_full.h | 1 - uhdf2/include/hdf_devmgr.h | 42 --- uhdf2/include/hdi/devmgr_hdi.h | 6 +- uhdf2/include/hdi/iservmgr_hdi.h | 2 +- uhdf2/manager/BUILD.gn | 12 +- uhdf2/manager/include/devmgr_pnp_service.h | 37 --- uhdf2/manager/include/devmgr_service_stub.h | 6 +- uhdf2/manager/include/usb_pnp_manager.h | 37 --- uhdf2/manager/src/devhost_service_proxy.c | 6 +- uhdf2/manager/src/devmgr_pnp_service.c | 284 ------------------ uhdf2/manager/src/devmgr_query_device.c | 2 +- uhdf2/manager/src/devmgr_service_full.c | 7 +- uhdf2/manager/src/devmgr_service_stub.c | 56 ++-- uhdf2/manager/src/devmgr_virtual_service.c | 77 ----- uhdf2/manager/src/hdf_get_attribute.c | 272 ----------------- uhdf2/manager/src/usb_pnp_manager.c | 137 --------- ...ute_parcel.h => dev_attribute_serialize.h} | 13 +- uhdf2/shared/include/hdf_device_info_full.h | 31 -- ...ute_parcel.c => dev_attribute_serialize.c} | 120 +++----- ...df_attribute_full.c => hcb_config_entry.c} | 24 +- uhdf2/shared/src/hdf_device_info_full.c | 67 ----- 46 files changed, 484 insertions(+), 1495 deletions(-) delete mode 100644 khdf/liteos/model/usb/host/include/usb_pnp_manager.h mode change 100755 => 100644 khdf/liteos/model/usb/host/src/usb_pnp_manager.c mode change 100755 => 100644 khdf/liteos/model/usb/host/src/usb_pnp_notify.c mode change 100755 => 100644 uhdf2/host/BUILD.gn delete mode 100644 uhdf2/host/src/hdf_device_full.c delete mode 100755 uhdf2/include/hdf_devmgr.h delete mode 100755 uhdf2/manager/include/devmgr_pnp_service.h delete mode 100644 uhdf2/manager/include/usb_pnp_manager.h mode change 100755 => 100644 uhdf2/manager/src/devhost_service_proxy.c delete mode 100644 uhdf2/manager/src/devmgr_pnp_service.c delete mode 100755 uhdf2/manager/src/devmgr_virtual_service.c delete mode 100644 uhdf2/manager/src/hdf_get_attribute.c delete mode 100755 uhdf2/manager/src/usb_pnp_manager.c rename uhdf2/shared/include/{dev_attribute_parcel.h => dev_attribute_serialize.h} (63%) delete mode 100755 uhdf2/shared/include/hdf_device_info_full.h rename uhdf2/shared/src/{dev_attribute_parcel.c => dev_attribute_serialize.c} (40%) mode change 100755 => 100644 rename uhdf2/shared/src/{hdf_attribute_full.c => hcb_config_entry.c} (77%) delete mode 100644 uhdf2/shared/src/hdf_device_info_full.c diff --git a/khdf/liteos/BUILD.gn b/khdf/liteos/BUILD.gn index 55371bd..44f5404 100644 --- a/khdf/liteos/BUILD.gn +++ b/khdf/liteos/BUILD.gn @@ -34,6 +34,7 @@ module_name = "hdf" hdf_driver(module_name) { sources = [ "$HDF_FRAMEWORKS_PATH/core/adapter/vnode/src/hdf_vnode_adapter.c", + "$HDF_FRAMEWORKS_PATH/core/common/src/buildin_config_entry.c", "$HDF_FRAMEWORKS_PATH/core/common/src/devlite_object_config.c", "$HDF_FRAMEWORKS_PATH/core/common/src/devmgr_service_start.c", "$HDF_FRAMEWORKS_PATH/core/common/src/hdf_attribute.c", @@ -64,6 +65,7 @@ hdf_driver(module_name) { "$HDF_FRAMEWORKS_PATH/core/shared/src/hdf_service_record.c", "$HDF_FRAMEWORKS_PATH/utils/src/hcs_parser/device_resource_if.c", "$HDF_FRAMEWORKS_PATH/utils/src/hcs_parser/hcs_blob_if.c", + "$HDF_FRAMEWORKS_PATH/utils/src/hcs_parser/hcs_buildin_parser.c", "$HDF_FRAMEWORKS_PATH/utils/src/hcs_parser/hcs_generate_tree.c", "$HDF_FRAMEWORKS_PATH/utils/src/hcs_parser/hcs_parser.c", "$HDF_FRAMEWORKS_PATH/utils/src/hcs_parser/hcs_tree_if.c", diff --git a/khdf/liteos/Makefile b/khdf/liteos/Makefile index 5342dcb..acf43e8 100644 --- a/khdf/liteos/Makefile +++ b/khdf/liteos/Makefile @@ -78,9 +78,11 @@ LOCAL_SRCS := ./osal/src/osal_timer.c \ $(HDF_FRAMEWORKS)/core/adapter/vnode/src/hdf_vnode_adapter.c \ $(HDF_FRAMEWORKS)/core/common/src/devlite_object_config.c \ $(HDF_FRAMEWORKS)/core/common/src/hdf_attribute.c \ + $(HDF_FRAMEWORKS)/core/common/src/buildin_config_entry.c, \ $(HDF_FRAMEWORKS)/core/common/src/devmgr_service_start.c \ $(HDF_FRAMEWORKS)/core/common/src/hdf_device_node_ext.c \ $(HDF_FRAMEWORKS)/utils/src/hcs_parser/hcs_blob_if.c \ + $(HDF_FRAMEWORKS)/utils/src/hcs_parser/hcs_buildin_parser.c \ $(HDF_FRAMEWORKS)/utils/src/hcs_parser/hcs_parser.c \ $(HDF_FRAMEWORKS)/utils/src/hcs_parser/hcs_generate_tree.c \ $(HDF_FRAMEWORKS)/utils/src/hcs_parser/hcs_tree_if.c \ diff --git a/khdf/liteos/model/usb/host/BUILD.gn b/khdf/liteos/model/usb/host/BUILD.gn index 351e629..e097284 100755 --- a/khdf/liteos/model/usb/host/BUILD.gn +++ b/khdf/liteos/model/usb/host/BUILD.gn @@ -51,7 +51,10 @@ hdf_driver(module_name) { "src/usb_pnp_notify.c", "src/usb_test_pnp_notify.c", ] - include_dirs += [ "$USB_PNP_NOTIFY_SHARED_ROOT/include" ] + include_dirs += [ + "$USB_PNP_NOTIFY_SHARED_ROOT/include", + "$FRAMEWORKS_USB_DDK_HOST/include", + ] public_configs = [ ":public" ] } diff --git a/khdf/liteos/model/usb/host/include/usb_pnp_manager.h b/khdf/liteos/model/usb/host/include/usb_pnp_manager.h deleted file mode 100644 index 0373081..0000000 --- a/khdf/liteos/model/usb/host/include/usb_pnp_manager.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used - * to endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef USB_PNP_MANAGER_H -#define USB_PNP_MANAGER_H - -#include "devmgr_service_if.h" - -struct UsbPnpManagerDeviceInfo { - struct IDevmgrService *devmgrSvc; - const char *moduleName; - const char *serviceName; - const char *deviceMatchAttr; - const void *privateData; - bool isReg; -}; - -bool UsbPnpManagerWriteModuleName(struct HdfSBuf *sbuf, const char *moduleName); -int32_t UsbPnpManagerRegisterOrUnregisterDevice(struct UsbPnpManagerDeviceInfo managerInfo); - -bool UsbPnpManagerAddPrivateData(struct HdfDeviceInfo *deviceInfo, const void *privateData); - -#endif /* USB_PNP_MANAGER_H */ - diff --git a/khdf/liteos/model/usb/host/src/usb_pnp_manager.c b/khdf/liteos/model/usb/host/src/usb_pnp_manager.c old mode 100755 new mode 100644 index 864e8e0..5467bfa --- a/khdf/liteos/model/usb/host/src/usb_pnp_manager.c +++ b/khdf/liteos/model/usb/host/src/usb_pnp_manager.c @@ -45,45 +45,6 @@ bool UsbPnpManagerWriteModuleName(struct HdfSBuf *sbuf, const char *moduleName) return HdfSbufWriteString(sbuf, moduleName); } -int32_t UsbPnpManagerRegisterOrUnregisterDevice(struct UsbPnpManagerDeviceInfo managerInfo) -{ - if (managerInfo.isReg) { - struct HdfDeviceObject *devObj = HdfRegisterDevice(managerInfo.moduleName, managerInfo.serviceName, - (const void *)managerInfo.privateData); - if (devObj == NULL) { - HDF_LOGE("%s:%d devObj is NULL!", __func__, __LINE__); - return HDF_FAILURE; - } - } else { - HdfUnregisterDevice(managerInfo.moduleName, managerInfo.serviceName); - } - - return HDF_SUCCESS; -} - -bool UsbPnpManagerAddPrivateData(struct HdfDeviceInfo *deviceInfo, const void *privateData) -{ - int ret; - - if (privateData != NULL) { - deviceInfo->private = (const void *)OsalMemCalloc(sizeof(struct UsbPnpNotifyServiceInfo)); - if (deviceInfo->private != NULL) { - uint32_t length = ((struct UsbPnpNotifyServiceInfo *)(privateData))->length; - - ret = memcpy_s((void *)(deviceInfo->private), sizeof(struct UsbPnpNotifyServiceInfo), privateData, length); - if ((ret != EOK) || (deviceInfo->private == NULL)) { - HDF_LOGE("%s: memcpy_s private error", __func__); - return false; - } - } else { - HDF_LOGE("%s: OsalMemCalloc private error", __func__); - return false; - } - } - - return true; -} - static int32_t UsbPnpManagerDispatch(struct HdfDeviceIoClient *client, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply) { @@ -94,7 +55,7 @@ static int32_t UsbPnpManagerDispatch(struct HdfDeviceIoClient *client, int cmd, HDF_LOGI("%s:%d received cmd = %d", __func__, __LINE__, cmd); - return UsbDdkPnpLoaderEventReceived(NULL, cmd, data); + return UsbDdkPnpLoaderEventReceived((void *)client->device, cmd, data); } static int32_t UsbPnpManagerBind(struct HdfDeviceObject *device) diff --git a/khdf/liteos/model/usb/host/src/usb_pnp_notify.c b/khdf/liteos/model/usb/host/src/usb_pnp_notify.c old mode 100755 new mode 100644 index c69f5c6..dcfe2d3 --- a/khdf/liteos/model/usb/host/src/usb_pnp_notify.c +++ b/khdf/liteos/model/usb/host/src/usb_pnp_notify.c @@ -37,7 +37,7 @@ #include "osal_time.h" #include "devsvc_manager_clnt.h" #include "hdf_log.h" -#include "hdf_device_desc.h" +#include "hdf_device_object.h" #include "implementation/global_implementation.h" #include "fs/fs.h" #include "usbdi.h" @@ -830,7 +830,7 @@ static void UsbPnpNotifyReadPnpInfo(struct HdfSBuf *data) g_usbPnpInfo.interfaceProtocol); } -static int32_t UsbPnpNotifyDriverRegisterDevice(struct HdfSBuf *data) +static int32_t UsbPnpNotifyDriverRegisterDevice(struct HdfDeviceObject *device, struct HdfSBuf *data) { if (data == NULL) { return HDF_FAILURE; @@ -845,11 +845,27 @@ static int32_t UsbPnpNotifyDriverRegisterDevice(struct HdfSBuf *data) return HDF_FAILURE; } - struct HdfDeviceObject *devObj = HdfRegisterDevice(moduleName, serviceName, NULL); + int ret = HDF_FAILURE; + struct HdfDeviceObject *devObj = HdfDeviceObjectAlloc(device, moduleName); if (devObj == NULL) { - return HDF_FAILURE; + HDF_LOGE("%s: failed to alloc device object", __func__); + return HDF_DEV_ERR_NO_MEMORY; } - return HDF_SUCCESS; + + ret = HdfDeviceObjectRegister(devObj); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: failed to regitst device %s", __func__, moduleName); + HdfDeviceObjectRelease(devObj); + return ret; + } + + ret = HdfDeviceObjectPublishService(devObj, serviceName, SERVICE_POLICY_CAPACITY, 0664); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: failed to regitst device %s", __func__, serviceName); + HdfDeviceObjectRelease(devObj); + } + + return ret; } static int32_t UsbPnpNotifyDriverUnregisterDevice(struct HdfSBuf *data) @@ -866,7 +882,12 @@ static int32_t UsbPnpNotifyDriverUnregisterDevice(struct HdfSBuf *data) if (serviceName == NULL) { return HDF_FAILURE; } - HdfUnregisterDevice(moduleName, serviceName); + + struct HdfDeviceObject *devObj = DevSvcManagerClntGetDeviceObject(serviceName); + if (devObj == NULL) { + return HDF_DEV_ERR_NO_DEVICE; + } + HdfDeviceObjectRelease(devObj); return HDF_SUCCESS; } @@ -910,7 +931,7 @@ static int32_t UsbPnpNotifyDispatch(struct HdfDeviceIoClient *client, int cmd, break; #endif case USB_PNP_DRIVER_REGISTER_DEVICE: - ret = UsbPnpNotifyDriverRegisterDevice(data); + ret = UsbPnpNotifyDriverRegisterDevice(client->device, data); break; case USB_PNP_DRIVER_UNREGISTER_DEVICE: ret = UsbPnpNotifyDriverUnregisterDevice(data); diff --git a/khdf/liteos_m/core/BUILD.gn b/khdf/liteos_m/core/BUILD.gn index 9d5beda..0e9e098 100644 --- a/khdf/liteos_m/core/BUILD.gn +++ b/khdf/liteos_m/core/BUILD.gn @@ -32,6 +32,7 @@ import("//drivers/adapter/khdf/liteos_m/hdf.gni") module_switch = defined(LOSCFG_DRIVERS_HDF) hdf_driver("hdf_core") { sources = [ + "$HDF_FRAMEWORKS_PATH/core/common/src/buildin_config_entry.c", "$HDF_FRAMEWORKS_PATH/core/common/src/devlite_object_config.c", "$HDF_FRAMEWORKS_PATH/core/common/src/hdf_attribute.c", "$HDF_FRAMEWORKS_PATH/core/host/src/devhost_service.c", @@ -59,6 +60,7 @@ hdf_driver("hdf_core") { "$HDF_FRAMEWORKS_PATH/core/shared/src/hdf_service_record.c", "$HDF_FRAMEWORKS_PATH/utils/src/hcs_parser/device_resource_if.c", "$HDF_FRAMEWORKS_PATH/utils/src/hcs_parser/hcs_blob_if.c", + "$HDF_FRAMEWORKS_PATH/utils/src/hcs_parser/hcs_buildin_parser.c", "$HDF_FRAMEWORKS_PATH/utils/src/hcs_parser/hcs_generate_tree.c", "$HDF_FRAMEWORKS_PATH/utils/src/hcs_parser/hcs_parser.c", "$HDF_FRAMEWORKS_PATH/utils/src/hcs_parser/hcs_tree_if.c", diff --git a/khdf/liteos_m/core/common/src/devmgr_service_start.c b/khdf/liteos_m/core/common/src/devmgr_service_start.c index 36ec96a..6aa8944 100644 --- a/khdf/liteos_m/core/common/src/devmgr_service_start.c +++ b/khdf/liteos_m/core/common/src/devmgr_service_start.c @@ -45,29 +45,12 @@ static int g_isQuickLoad = DEV_MGR_SLOW_LOAD; int32_t HdfGetServiceNameByDeviceClass(DeviceClass deviceClass, struct HdfSBuf *reply) { - struct HdfSListIterator itDeviceInfo; - struct HdfDeviceInfo *deviceInfo = NULL; - struct DevHostServiceClnt *hostClnt = NULL; - struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance(); - if (devMgrSvc == NULL || reply == NULL) { + if (reply == NULL) { return HDF_ERR_INVALID_PARAM; } HdfSbufFlush(reply); - DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) { - HdfSListIteratorInit(&itDeviceInfo, hostClnt->deviceInfos); - while (HdfSListIteratorHasNext(&itDeviceInfo)) { - deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo); - if (deviceInfo->policy == SERVICE_POLICY_CAPACITY) { - struct HdfDeviceObject *deviceObject = DevSvcManagerClntGetDeviceObject(deviceInfo->svcName); - if (deviceObject == NULL || (deviceObject->deviceClass != deviceClass)) { - continue; - } - HdfSbufWriteString(reply, deviceInfo->svcName); - } - } - } - + DevSvcManagerListService(reply, deviceClass); HdfSbufWriteString(reply, NULL); return HDF_SUCCESS; } diff --git a/uhdf2/hdi/src/devmgr_hdi.c b/uhdf2/hdi/src/devmgr_hdi.c index f708175..d496515 100644 --- a/uhdf2/hdi/src/devmgr_hdi.c +++ b/uhdf2/hdi/src/devmgr_hdi.c @@ -77,6 +77,7 @@ static int32_t HdfObtainDeviceInfo(struct DeviceInfoList *list, struct HdfSBuf * return HDF_SUCCESS; } + static int32_t DevmgrQueryDeviceInfo(struct HDIDeviceManager *iDevMgr, struct DeviceInfoList *list, int32_t type) { struct HdfSBuf *reply = NULL; @@ -151,57 +152,60 @@ static void DevmgrFreeQueryDeviceList(struct HDIDeviceManager *self, struct Devi DevmgrFreeQueryDeviceListImpl(list); } -static int32_t HdfOpsDevice(struct HDIDeviceManager *iDevMgr, - const char *moduleName, const char *serviceName, int opsId) +int32_t DevmgrLoadDevice(struct HDIDeviceManager *iDevMgr, const char *serviceName) { int32_t status = HDF_FAILURE; - if (iDevMgr == NULL || moduleName == NULL || serviceName == NULL) { + if (iDevMgr == NULL || serviceName == NULL) { return HDF_ERR_INVALID_PARAM; } struct HdfSBuf *data = HdfSBufTypedObtain(SBUF_IPC); - struct HdfSBuf *reply = HdfSBufTypedObtain(SBUF_IPC); - if (data == NULL || reply == NULL) { - status = HDF_ERR_MALLOC_FAIL; - goto out; - } + do { + if (data == NULL) { + status = HDF_ERR_MALLOC_FAIL; + break; + } + + if (!HdfSbufWriteString(data, serviceName)) { + HDF_LOGE("%{public}s: writing service name failed!", __func__); + break; + } + status = DeviceManagerHdiCall(iDevMgr, DEVMGR_SERVICE_LOAD_DEVICE, data, NULL); + if (status != HDF_SUCCESS) { + HDF_LOGE("failed to load device %{public}s", serviceName); + } + } while (0); - if (!HdfSbufWriteString(data, moduleName)) { - HDF_LOGE("%{public}s: writing module name failed!", __func__); - goto out; - } - if (!HdfSbufWriteString(data, serviceName)) { - HDF_LOGE("%{public}s: writing service name failed!", __func__); - goto out; - } - status = DeviceManagerHdiCall(iDevMgr, opsId, data, reply); - if (status == HDF_SUCCESS) { - HdfSbufReadInt32(reply, &status); - } -out: HdfSBufRecycle(data); - HdfSBufRecycle(reply); return status; } -static int32_t DevmgrRegPnpDevice(struct HDIDeviceManager *self, const char *moduleName, const char *serviceName) +int32_t DevmgrUnloadDevice(struct HDIDeviceManager *iDevMgr, const char *serviceName) { - return HdfOpsDevice(self, moduleName, serviceName, DEVMGR_SERVICE_REGIST_PNP_DEVICE); -} + int32_t status = HDF_FAILURE; + if (iDevMgr == NULL || serviceName == NULL) { + return HDF_ERR_INVALID_PARAM; + } -static int32_t DevmgrUnRegPnpDevice(struct HDIDeviceManager *self, const char *moduleName, const char *serviceName) -{ - return HdfOpsDevice(self, moduleName, serviceName, DEVMGR_SERVICE_UNREGIST_PNP_DEVICE); -} + struct HdfSBuf *data = HdfSBufTypedObtain(SBUF_IPC); + do { + if (data == NULL) { + status = HDF_ERR_MALLOC_FAIL; + break; + } -static int32_t DevmgrRegVirtualDevice(struct HDIDeviceManager *self, const char *moduleName, const char *serviceName) -{ - return HdfOpsDevice(self, moduleName, serviceName, DEVMGR_SERVICE_REGISTER_VIRTUAL_DEVICE); -} + if (!HdfSbufWriteString(data, serviceName)) { + HDF_LOGE("%{public}s: writing service name failed!", __func__); + break; + } + status = DeviceManagerHdiCall(iDevMgr, DEVMGR_SERVICE_UNLOAD_DEVICE, data, NULL); + if (status != HDF_SUCCESS) { + HDF_LOGE("failed to unload device %{public}s", serviceName); + } + } while (0); -static int32_t DevmgrUnRegVirtualDevice(struct HDIDeviceManager *self, const char *moduleName, const char *serviceName) -{ - return HdfOpsDevice(self, moduleName, serviceName, DEVMGR_SERVICE_UNREGISTER_VIRTUAL_DEVICE); + HdfSBufRecycle(data); + return status; } static void HDIDeviceManagerConstruct(struct HDIDeviceManager *inst) @@ -209,10 +213,8 @@ static void HDIDeviceManagerConstruct(struct HDIDeviceManager *inst) inst->FreeQueryDeviceList = DevmgrFreeQueryDeviceList; inst->QueryUsableDeviceInfo = DevmgrQueryUsableDeviceInfo; inst->QueryUnusableDeviceInfo = DevmgrQueryUnusableDeviceInfo; - inst->RegPnpDevice = DevmgrRegPnpDevice; - inst->UnRegPnpDevice = DevmgrUnRegPnpDevice; - inst->RegVirtualDevice = DevmgrRegVirtualDevice; - inst->UnRegVirtualDevice = DevmgrUnRegVirtualDevice; + inst->LoadDevice = DevmgrLoadDevice; + inst->UnloadDevice = DevmgrUnloadDevice; } struct HDIDeviceManager *HDIDeviceManagerGet(void) diff --git a/uhdf2/hdi/test/servmgr/service_manager_hdi_c_test.cpp b/uhdf2/hdi/test/servmgr/service_manager_hdi_c_test.cpp index 6e8c7fc..165f316 100644 --- a/uhdf2/hdi/test/servmgr/service_manager_hdi_c_test.cpp +++ b/uhdf2/hdi/test/servmgr/service_manager_hdi_c_test.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include "sample_hdi.h" #define HDF_LOG_TAG service_manager_test @@ -30,8 +31,20 @@ constexpr int PAYLOAD_NUM = 1234; class HdfServiceMangerHdiCTest : public testing::Test { public: - static void SetUpTestCase() {}; - static void TearDownTestCase() {}; + static void SetUpTestCase() + { + struct HDIDeviceManager *devmgr = HDIDeviceManagerGet(); + if (devmgr != nullptr) { + devmgr->LoadDevice(devmgr, TEST_SERVICE_NAME); + } + } + static void TearDownTestCase() + { + struct HDIDeviceManager *devmgr = HDIDeviceManagerGet(); + if (devmgr != nullptr) { + devmgr->UnloadDevice(devmgr, TEST_SERVICE_NAME); + } + } void SetUp() {}; void TearDown() {}; }; @@ -205,6 +218,75 @@ HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest006, TestSize.Level1) ASSERT_EQ(retBuffer[i], i); } + HdfSBufRecycle(data); + HdfSBufRecycle(reply); +} + +HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest007, TestSize.Level1) +{ + struct HDIDeviceManager *devmgr = HDIDeviceManagerGet(); + ASSERT_TRUE(devmgr != nullptr); + devmgr->UnloadDevice(devmgr, TEST_SERVICE_NAME); + + struct HDIServiceManager *servmgr = HDIServiceManagerGet(); + ASSERT_TRUE(servmgr != nullptr); + + struct HdfRemoteService *sampleService = servmgr->GetService(servmgr, TEST_SERVICE_NAME); + ASSERT_TRUE(sampleService == nullptr); + + int ret = devmgr->LoadDevice(devmgr, TEST_SERVICE_NAME); + ASSERT_EQ(ret, HDF_SUCCESS); + + sampleService = servmgr->GetService(servmgr, TEST_SERVICE_NAME); + ASSERT_TRUE(sampleService != nullptr); + + struct HdfSBuf *data = HdfSBufTypedObtain(SBUF_IPC); + struct HdfSBuf *reply = HdfSBufTypedObtain(SBUF_IPC); + ASSERT_TRUE(data != nullptr); + ASSERT_TRUE(reply != nullptr); + + const char *newServName = "sample_driver_service2"; + ret = HdfSbufWriteString(data, newServName); + ASSERT_TRUE(ret); + + int status = sampleService->dispatcher->Dispatch(sampleService, SAMPLE_REGISTER_DEVICE, data, reply); + ASSERT_EQ(status, HDF_SUCCESS); + + struct HdfRemoteService *sampleService2 = servmgr->GetService(servmgr, newServName); + ASSERT_TRUE(sampleService != nullptr); + + HdfSbufFlush(data); + HdfSbufFlush(reply); + HdfSbufWriteInt32(data, PAYLOAD_NUM); + HdfSbufWriteInt32(data, PAYLOAD_NUM); + + status = sampleService2->dispatcher->Dispatch(sampleService2, SAMPLE_SERVICE_SUM, data, reply); + ASSERT_EQ(status, 0); + int32_t result; + ret = HdfSbufReadInt32(reply, &result); + ASSERT_TRUE(ret); + + int32_t expRes = PAYLOAD_NUM + PAYLOAD_NUM; + ASSERT_EQ(result, expRes); + HdfRemoteServiceRecycle(sampleService2); + + HdfSbufFlush(data); + ret = HdfSbufWriteString(data, newServName); + ASSERT_TRUE(ret); + + status = sampleService->dispatcher->Dispatch(sampleService, SAMPLE_UNREGISTER_DEVICE, data, reply); + ASSERT_EQ(status, HDF_SUCCESS); + + sampleService2 = servmgr->GetService(servmgr, newServName); + ASSERT_TRUE(sampleService2 == nullptr); + + ret = devmgr->UnloadDevice(devmgr, TEST_SERVICE_NAME); + ASSERT_EQ(ret, HDF_SUCCESS); + + HdfRemoteServiceRecycle(sampleService); + sampleService = servmgr->GetService(servmgr, TEST_SERVICE_NAME); + ASSERT_TRUE(sampleService == nullptr); + HdfSBufRecycle(data); HdfSBufRecycle(reply); } \ No newline at end of file diff --git a/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp b/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp index af81fd4..88f33b6 100644 --- a/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp +++ b/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include #include #include #include @@ -31,8 +32,20 @@ constexpr int PAYLOAD_NUM = 1234; class HdfServiceMangerHdiTest : public testing::Test { public: - static void SetUpTestCase() {}; - static void TearDownTestCase() {}; + static void SetUpTestCase() + { + struct HDIDeviceManager *devmgr = HDIDeviceManagerGet(); + if (devmgr != nullptr) { + devmgr->LoadDevice(devmgr, TEST_SERVICE_NAME); + } + } + static void TearDownTestCase() + { + struct HDIDeviceManager *devmgr = HDIDeviceManagerGet(); + if (devmgr != nullptr) { + devmgr->UnloadDevice(devmgr, TEST_SERVICE_NAME); + } + } void SetUp() {}; void TearDown() {}; }; diff --git a/uhdf2/host/BUILD.gn b/uhdf2/host/BUILD.gn old mode 100755 new mode 100644 index a2a3adf..6ab243a --- a/uhdf2/host/BUILD.gn +++ b/uhdf2/host/BUILD.gn @@ -72,12 +72,10 @@ ohos_shared_library("libhdf_host") { "$hdf_uhdf_path/host/src/devmgr_service_proxy.c", "$hdf_uhdf_path/host/src/devsvc_manager_proxy.c", "$hdf_uhdf_path/host/src/driver_loader_full.c", - "$hdf_uhdf_path/host/src/hdf_device_full.c", "$hdf_uhdf_path/host/src/hdf_device_thread.c", "$hdf_uhdf_path/host/src/hdf_devsvc_manager_clnt.c", - "$hdf_uhdf_path/shared/src/dev_attribute_parcel.c", - "$hdf_uhdf_path/shared/src/hdf_attribute_full.c", - "$hdf_uhdf_path/shared/src/hdf_device_info_full.c", + "$hdf_uhdf_path/shared/src/dev_attribute_serialize.c", + "$hdf_uhdf_path/shared/src/hcb_config_entry.c", ] deps = [ diff --git a/uhdf2/host/include/hdf_device_thread.h b/uhdf2/host/include/hdf_device_thread.h index 0f36912..b6daec2 100644 --- a/uhdf2/host/include/hdf_device_thread.h +++ b/uhdf2/host/include/hdf_device_thread.h @@ -38,6 +38,6 @@ enum { struct DeviceThread *DeviceThreadNewInstance(void); void DeviceThreadFreeInstance(struct DeviceThread *thread); void DeviceThreadMain(void *args); -void DeviceThreadAttach(struct DeviceThread *inst, struct IHdfDevice *device, struct HdfDeviceNode *service); +int DeviceThreadAttach(struct DeviceThread *inst, struct IHdfDevice *device, struct HdfDeviceNode *service); #endif /* DEVICE_THREAD_H */ diff --git a/uhdf2/host/src/devhost_object_config.c b/uhdf2/host/src/devhost_object_config.c index eeacba0..0da41a7 100644 --- a/uhdf2/host/src/devhost_object_config.c +++ b/uhdf2/host/src/devhost_object_config.c @@ -18,7 +18,6 @@ #include "devmgr_service_proxy.h" #include "devsvc_manager_proxy.h" #include "driver_loader_full.h" -#include "hdf_device_full.h" #include "device_service_stub.h" #include "hdf_log.h" #include "hdf_object_manager.h" @@ -48,8 +47,8 @@ static const struct HdfObjectCreator g_fullDevHostObjectCreators[] = { }, [HDF_OBJECT_ID_DEVICE] = { - .Create = HdfDeviceFullCreate, - .Release = HdfDeviceFullRelease, + .Create = HdfDeviceCreate, + .Release = HdfDeviceRelease, }, [HDF_OBJECT_ID_DEVICE_TOKEN] = { diff --git a/uhdf2/host/src/devhost_service_full.c b/uhdf2/host/src/devhost_service_full.c index 0eab2aa..029ab42 100644 --- a/uhdf2/host/src/devhost_service_full.c +++ b/uhdf2/host/src/devhost_service_full.c @@ -15,13 +15,13 @@ #include "devhost_service_full.h" #include "devmgr_service_clnt.h" +#include "dev_attribute_serialize.h" #include "hdf_device_node.h" #include "power_state_token.h" #include "hdf_base.h" #include "hdf_device_info.h" #include "hdf_log.h" #include "osal_message.h" -#include "hdf_device_info_full.h" #define HDF_LOG_TAG devhost_service_full diff --git a/uhdf2/host/src/devhost_service_stub.c b/uhdf2/host/src/devhost_service_stub.c index 5a721c0..88f412b 100644 --- a/uhdf2/host/src/devhost_service_stub.c +++ b/uhdf2/host/src/devhost_service_stub.c @@ -15,7 +15,7 @@ #include "devhost_service_stub.h" #include "devhost_service_proxy.h" -#include "dev_attribute_parcel.h" +#include "dev_attribute_serialize.h" #include "hdf_base.h" #include "hdf_log.h" #include "hdf_sbuf.h" @@ -35,6 +35,7 @@ static int DevHostServiceStubDispatch( { (void)reply; int ret = HDF_FAILURE; + uint32_t deviceId = 0; if (stub == NULL || data == NULL) { return ret; } @@ -48,16 +49,16 @@ static int DevHostServiceStubDispatch( HDF_LOGE("serviceIf or serviceIf->AddDevice is NULL"); break; } - struct HdfDeviceInfoFull *attribute = DeviceAttributeFullRead(data); + struct HdfDeviceInfo *attribute = DeviceAttributeDeserialize(data); if (attribute == NULL) { HDF_LOGE("Dispatch failed, attribute is null"); break; } - ret = serviceIf->AddDevice(serviceIf, &attribute->super); + ret = serviceIf->AddDevice(serviceIf, attribute); if (ret != HDF_SUCCESS) { HDF_LOGE("Dispatch failed, add service failed and ret is %{public}d", ret); } - HdfDeviceInfoFullFreeInstance(attribute); + DeviceSerializedAttributeRelease(attribute); break; } case DEVHOST_SERVICE_DEL_DEVICE: { @@ -65,14 +66,14 @@ static int DevHostServiceStubDispatch( HDF_LOGE("serviceIf or serviceIf->DelDevice is NULL"); break; } - struct HdfDeviceInfoFull *attribute = DeviceAttributeFullRead(data); - if (attribute == NULL) { - HDF_LOGE("Dispatch failed, attribute is null"); + if (!HdfSbufReadUint32(data, &deviceId)) { + HDF_LOGE("failed to del device, invalid device id"); break; } - ret = serviceIf->DelDevice(serviceIf, attribute->super.deviceId); + + ret = serviceIf->DelDevice(serviceIf, deviceId); if (ret != HDF_SUCCESS) { - HDF_LOGE("Dispatch failed, del service failed and ret is %{public}d", ret); + HDF_LOGE("del service failed, ret is %{public}d", ret); } break; } diff --git a/uhdf2/host/src/device_service_stub.c b/uhdf2/host/src/device_service_stub.c index 4191424..323e9e8 100644 --- a/uhdf2/host/src/device_service_stub.c +++ b/uhdf2/host/src/device_service_stub.c @@ -13,12 +13,12 @@ * limitations under the License. */ -#include "hdf_sbuf.h" #include "device_service_stub.h" #include "devsvc_manager_clnt.h" #include "hdf_base.h" -#include "osal_mem.h" #include "hdf_log.h" +#include "hdf_sbuf.h" +#include "osal_mem.h" int DeviceServiceStubDispatch( struct HdfRemoteService *stub, int code, struct HdfSBuf *data, struct HdfSBuf *reply) @@ -61,27 +61,53 @@ int DeviceServiceStubPublishService(struct HdfDeviceNode *service) return HDF_ERR_INVALID_OBJECT; } - if (service->policy == SERVICE_POLICY_PUBLIC || service->policy == SERVICE_POLICY_CAPACITY) { - fullService->remote = HdfRemoteServiceObtain((struct HdfObject *)fullService, &g_deviceServiceDispatcher); - if (fullService->remote == NULL) { - return HDF_ERR_MALLOC_FAIL; + if (service->policy != SERVICE_POLICY_PUBLIC && service->policy != SERVICE_POLICY_CAPACITY) { + return HDF_ERR_NOT_SUPPORT; + } + + fullService->remote = HdfRemoteServiceObtain((struct HdfObject *)fullService, &g_deviceServiceDispatcher); + if (fullService->remote == NULL) { + return HDF_ERR_MALLOC_FAIL; + } + + do { + struct DevSvcManagerClnt *serviceManager = DevSvcManagerClntGetInstance(); + if (serviceManager == NULL) { + HDF_LOGE("device service stub failed to publish, svcmgr clnt invalid"); + status = HDF_DEV_ERR_NO_DEVICE; + break; } - struct DevSvcManagerClnt *serviceManager = - (struct DevSvcManagerClnt *)DevSvcManagerClntGetInstance(); - if (serviceManager != NULL) { - status = DevSvcManagerClntAddService(service->servName, &fullService->super.deviceObject); + + status = DevSvcManagerClntAddService(service->servName, &fullService->super.deviceObject); + if (status != HDF_SUCCESS) { + break; } - } + service->servStatus = true; + return HDF_SUCCESS; + } while (0); + HdfRemoteServiceRecycle(fullService->remote); + fullService->remote = NULL; return status; } +int DeviceServiceStubRemoveService(struct HdfDeviceNode *deviceNode) +{ + struct DevSvcManagerClnt *serviceManager = DevSvcManagerClntGetInstance(); + if (serviceManager == NULL) { + return HDF_FAILURE; + } + DevSvcManagerClntRemoveService(deviceNode->servName); + return HDF_SUCCESS; +} + void DeviceServiceStubConstruct(struct DeviceServiceStub *inst) { HdfDeviceNodeConstruct(&inst->super); struct IDeviceNode *serviceIf = (struct IDeviceNode *)inst; if (serviceIf != NULL) { serviceIf->PublishService = DeviceServiceStubPublishService; + serviceIf->RemoveService = DeviceServiceStubRemoveService; } } diff --git a/uhdf2/host/src/devmgr_service_proxy.c b/uhdf2/host/src/devmgr_service_proxy.c index 2618d9e..53c01c6 100644 --- a/uhdf2/host/src/devmgr_service_proxy.c +++ b/uhdf2/host/src/devmgr_service_proxy.c @@ -103,6 +103,43 @@ finished: } return status; } +int DevmgrServiceProxyLoadDevice(struct IDevmgrService *inst, const char *svcName) +{ + int status = HDF_FAILURE; + struct DevmgrServiceProxy *serviceProxy = (struct DevmgrServiceProxy *)inst; + if (serviceProxy == NULL || serviceProxy->remote == NULL || svcName == NULL) { + HDF_LOGE("DevmgrServiceProxyLoadDevice failed"); + return HDF_ERR_INVALID_PARAM; + } + + struct HdfSBuf *data = HdfSBufTypedObtain(SBUF_IPC); + struct HdfRemoteService *remoteService = serviceProxy->remote; + HdfSbufWriteString(data, svcName); + + status = remoteService->dispatcher->Dispatch(remoteService, DEVMGR_SERVICE_LOAD_DEVICE, data, NULL); + + HdfSBufRecycle(data); + return status; +} + +int DevmgrServiceProxyUnLoadDevice(struct IDevmgrService *inst, const char *svcName) +{ + int status = HDF_FAILURE; + struct DevmgrServiceProxy *serviceProxy = (struct DevmgrServiceProxy *)inst; + if (serviceProxy == NULL || serviceProxy->remote == NULL || svcName == NULL) { + HDF_LOGE("DevmgrServiceProxyLoadDevice failed"); + return HDF_ERR_INVALID_PARAM; + } + + struct HdfSBuf *data = HdfSBufTypedObtain(SBUF_IPC); + struct HdfRemoteService *remoteService = serviceProxy->remote; + HdfSbufWriteString(data, svcName); + + status = remoteService->dispatcher->Dispatch(remoteService, DEVMGR_SERVICE_UNLOAD_DEVICE, data, NULL); + + HdfSBufRecycle(data); + return status; +} static void DevmgrServiceProxyConstruct(struct DevmgrServiceProxy *inst) { @@ -110,6 +147,8 @@ static void DevmgrServiceProxyConstruct(struct DevmgrServiceProxy *inst) pvtbl->AttachDeviceHost = DevmgrServiceProxyAttachDeviceHost; pvtbl->AttachDevice = DevmgrServiceProxyAttachDevice; pvtbl->DetachDevice = DevmgrServiceProxyDetachDevice; + pvtbl->LoadDevice = DevmgrServiceProxyLoadDevice; + pvtbl->UnloadDevice = DevmgrServiceProxyUnLoadDevice; pvtbl->StartService = NULL; } @@ -165,15 +204,3 @@ void DevmgrServiceProxyRelease(struct HdfObject *object) OsalMemFree(instance); } } - -int DevmgrServiceLoadDevice(const char *svcName) -{ - (void)svcName; - return HDF_SUCCESS; -} - -int DevmgrServiceUnLoadDevice(const char *svcName) -{ - (void)svcName; - return HDF_SUCCESS; -} diff --git a/uhdf2/host/src/devsvc_manager_proxy.c b/uhdf2/host/src/devsvc_manager_proxy.c index babd66b..fdc8a7d 100644 --- a/uhdf2/host/src/devsvc_manager_proxy.c +++ b/uhdf2/host/src/devsvc_manager_proxy.c @@ -177,4 +177,3 @@ void DevSvcManagerProxyRelease(struct HdfObject *object) OsalMemFree(instance); } } - diff --git a/uhdf2/host/src/driver_loader_full.c b/uhdf2/host/src/driver_loader_full.c index 99f81b4..be51a3a 100644 --- a/uhdf2/host/src/driver_loader_full.c +++ b/uhdf2/host/src/driver_loader_full.c @@ -20,7 +20,7 @@ #include #include #include "hdf_device.h" -#include "hdf_device_info_full.h" +#include "dev_attribute_serialize.h" #include "hdf_device_node.h" #include "hdf_log.h" #include "hdf_object_manager.h" diff --git a/uhdf2/host/src/hdf_device_full.c b/uhdf2/host/src/hdf_device_full.c deleted file mode 100644 index b9526c5..0000000 --- a/uhdf2/host/src/hdf_device_full.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device 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_device_full.h" -#include "device_service_stub.h" -#include "hdf_base.h" -#include "hdf_device_info_full.h" -#include "devhost_service.h" -#include "hdf_log.h" -#include "osal_mem.h" -#include "hdf_service_observer.h" - -#define HDF_LOG_TAG hdf_device_full - -struct HdfDeviceFull *HdfDeviceFullReinterpretCast(struct IHdfDevice *device) -{ - return (struct HdfDeviceFull *)device; -} - -static int HdfDeviceFullAttach( - struct IHdfDevice *device, struct HdfDeviceNode *deviceService) -{ - struct DeviceThread *deviceThread = NULL; - struct HdfDeviceFull *fullDevice = HdfDeviceFullReinterpretCast(device); - if (fullDevice == NULL) { - HDF_LOGE("HdfDeviceFullAttach failed, fullDevice is null"); - return HDF_FAILURE; - } - - if (fullDevice->deviceThread == NULL) { - fullDevice->deviceThread = DeviceThreadNewInstance(); - } - - deviceThread = fullDevice->deviceThread; - if (deviceThread != NULL) { - struct HdfThread *thread = (struct HdfThread *)&deviceThread->super; - if (!thread->IsRunning(thread)) { - thread->Start(thread); - } - // modified list operation. - DListInsertTail(&deviceService->entry, &fullDevice->super.devNodes); - DeviceThreadAttach(deviceThread, device, deviceService); - } - return HDF_SUCCESS; -} - -static int HdfDeviceFullDettach(struct IHdfDevice *device, struct HdfDeviceNode *devNode) -{ - struct HdfDeviceFull *fullDevice = HdfDeviceFullReinterpretCast(device); - if (fullDevice == NULL || devNode == NULL) { - HDF_LOGE("%{public}s input is null", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if (devNode->driver->entry != NULL && devNode->driver->entry->Release != NULL) { - devNode->driver->entry->Release(&devNode->deviceObject); - } - struct DevHostService *hostService = devNode->hostService; - if (hostService != NULL) { - HdfServiceObserverRemoveRecord(&hostService->observer, devNode->servName); - } - - DeviceServiceStubRelease(&devNode->super.object); - if (fullDevice->deviceThread != NULL) { - fullDevice->deviceThread->looper.Stop(&fullDevice->deviceThread->looper); - DeviceThreadFreeInstance(fullDevice->deviceThread); - fullDevice->deviceThread = NULL; - } - - return HDF_SUCCESS; -} - -void HdfDeviceFullConstruct(struct HdfDeviceFull *inst) -{ - if (inst != NULL) { - struct IHdfDevice *deviceIf = (struct IHdfDevice *)&inst->super; - HdfDeviceConstruct(&inst->super); - deviceIf->Attach = HdfDeviceFullAttach; - deviceIf->Detach = HdfDeviceFullDettach; - } -} - -struct HdfObject *HdfDeviceFullCreate(void) -{ - struct HdfDeviceFull *device = - (struct HdfDeviceFull *)OsalMemCalloc(sizeof(struct HdfDeviceFull)); - if (device != NULL) { - HdfDeviceFullConstruct(device); - } - return (struct HdfObject *)device; -} - - -void HdfDeviceFullRelease(struct HdfObject *object) -{ - struct HdfDeviceFull *fullDevice = (struct HdfDeviceFull *)object; - if (fullDevice != NULL) { - HdfDeviceDestruct(&fullDevice->super); - if (fullDevice->deviceThread != NULL) { - DeviceThreadFreeInstance(fullDevice->deviceThread); - } - OsalMemFree(fullDevice); - } -} - diff --git a/uhdf2/host/src/hdf_device_thread.c b/uhdf2/host/src/hdf_device_thread.c index f835404..9bb01a6 100644 --- a/uhdf2/host/src/hdf_device_thread.c +++ b/uhdf2/host/src/hdf_device_thread.c @@ -47,21 +47,23 @@ int32_t DeviceThreadMessageHandler(struct HdfMessageTask *task, struct HdfMessag return HDF_SUCCESS; } -void DeviceThreadAttach(struct DeviceThread *inst, struct IHdfDevice *device, struct HdfDeviceNode *service) +int DeviceThreadAttach(struct DeviceThread *inst, struct IHdfDevice *device, struct HdfDeviceNode *service) { - if (inst != NULL) { - // Thread is already running - struct HdfMessageTask *task = &inst->task; - struct HdfMessage *message = HdfMessageObtain(sizeof(struct HdfDeviceNode *)); - if (message == NULL) { - HDF_LOGE("Get message error"); - return; - } - message->messageId = DEVICE_SERVICE_MESSAGE_LAUNCH; - message->data[0] = (void *)device; - message->data[1] = (void *)service; - task->SendMessage(task, message, true); + if (inst != NULL || device == NULL || service == NULL) { + return HDF_ERR_INVALID_PARAM; + } + + // Thread is already running + struct HdfMessageTask *task = &inst->task; + struct HdfMessage *message = HdfMessageObtain(sizeof(struct HdfDeviceNode *)); + if (message == NULL) { + HDF_LOGE("DeviceThreadAttach:obtain message error"); + return HDF_ERR_MALLOC_FAIL; } + message->messageId = DEVICE_SERVICE_MESSAGE_LAUNCH; + message->data[0] = (void *)device; + message->data[1] = (void *)service; + return task->SendMessage(task, message, true); } void DeviceThreadMain(void *args) diff --git a/uhdf2/host/test/unittest/sample_driver/sample_hdi.h b/uhdf2/host/test/unittest/sample_driver/sample_hdi.h index 914f949..fb13061 100644 --- a/uhdf2/host/test/unittest/sample_driver/sample_hdi.h +++ b/uhdf2/host/test/unittest/sample_driver/sample_hdi.h @@ -37,12 +37,16 @@ enum { SAMPLE_SERVICE_CALLBACK, SAMPLE_STRUCT_TRANS, SAMPLE_BUFFER_TRANS, + SAMPLE_REGISTER_DEVICE, + SAMPLE_UNREGISTER_DEVICE, }; struct SampleHdi { int32_t (*ping)(struct HdfDeviceObject *device, const char* info, char** infoOut); int32_t (*sum)(struct HdfDeviceObject *device, int32_t x0, int32_t x1, int32_t *result); int32_t (*callback)(struct HdfDeviceObject *device, struct HdfRemoteService *callback, int32_t code); + int32_t (*registerDevice)(struct HdfDeviceObject *device, const char *servName); + int32_t (*unregisterDevice)(struct HdfDeviceObject *device, const char *servName); }; const struct SampleHdi *SampleHdiImplInstance(); diff --git a/uhdf2/host/test/unittest/sample_driver/sample_hdi_service.c b/uhdf2/host/test/unittest/sample_driver/sample_hdi_service.c index 7f68592..a05b10b 100644 --- a/uhdf2/host/test/unittest/sample_driver/sample_hdi_service.c +++ b/uhdf2/host/test/unittest/sample_driver/sample_hdi_service.c @@ -13,13 +13,23 @@ * limitations under the License. */ +#include "sample_hdi.h" #include -#include -#include +#include +#include #include -#include "sample_hdi.h" +#include + +#define HDF_LOG_TAG sample_driver + +struct SampleDevice { + struct DListHead listNode; + struct HdfDeviceObject *devobj; +}; + +struct DListHead g_sampleDeviceList = { NULL }; -int32_t SampleServicePing(struct HdfDeviceObject *device, const char* info, char** infoOut) +int32_t SampleServicePing(struct HdfDeviceObject *device, const char *info, char **infoOut) { (void)device; HDF_LOGI("Sample:info is %{public}s", info); @@ -31,7 +41,6 @@ int32_t SampleServiceSum(struct HdfDeviceObject *device, int32_t x0, int32_t x1, { (void)device; *result = x0 + x1; - return 0; } @@ -48,10 +57,72 @@ int32_t SampleServiceCallback(struct HdfDeviceObject *device, struct HdfRemoteSe return ret; } -static const struct SampleHdi g_sampleHdiImpl = { +int32_t SampleServiceRegisterDevice(struct HdfDeviceObject *device, const char *servName) +{ + struct HdfDeviceObject *dev = HdfDeviceObjectAlloc(device, "libsample_driver.z.so"); + if (dev == NULL) { + HDF_LOGE("failed to alloc device object"); + return HDF_DEV_ERR_NO_DEVICE; + } + + if (HdfDeviceObjectRegister(dev) != HDF_SUCCESS) { + HDF_LOGE("failed to register device"); + HdfDeviceObjectRelease(dev); + return HDF_DEV_ERR_NO_DEVICE; + } + + if (HdfDeviceObjectPublishService(dev, servName, SERVICE_POLICY_CAPACITY, 0) != HDF_SUCCESS) { + HDF_LOGE("failed to publish device service %{public}s", servName); + HdfDeviceObjectRelease(dev); + return HDF_DEV_ERR_NO_DEVICE; + } + + HDF_LOGE("publish device service %{public}s success", servName); + struct SampleDevice *sampleDev = OsalMemAlloc(sizeof(struct SampleDevice)); + if (sampleDev == NULL) { + HdfDeviceObjectRelease(dev); + return HDF_DEV_ERR_NO_MEMORY; + } + + sampleDev->devobj = dev; + if (g_sampleDeviceList.next == NULL) { + DListHeadInit(&g_sampleDeviceList); + } + DListInsertTail(&sampleDev->listNode, &g_sampleDeviceList); + + HDF_LOGI("register device %{public}s success", servName); + return HDF_SUCCESS; +} + +int32_t SampleServiceUnregisterDevice(struct HdfDeviceObject *device, const char *servName) +{ + struct SampleDevice *sampleDev = NULL; + struct SampleDevice *sampleDevTmp = NULL; + + DLIST_FOR_EACH_ENTRY_SAFE(sampleDev, sampleDevTmp, &g_sampleDeviceList, struct SampleDevice, listNode) { + if (sampleDev->devobj == NULL || HdfDeviceGetServiceName(sampleDev->devobj) == NULL) { + DListRemove(&sampleDev->listNode); + OsalMemFree(sampleDev); + continue; + } + + if (strcmp(HdfDeviceGetServiceName(sampleDev->devobj), servName) == 0) { + HdfDeviceObjectRelease(sampleDev->devobj); + DListRemove(&sampleDev->listNode); + OsalMemFree(sampleDev); + HDF_LOGI("remove device %{public}s success", servName); + } + } + + return HDF_SUCCESS; +} + +static const struct SampleHdi g_sampleHdiImpl = { .ping = SampleServicePing, .sum = SampleServiceSum, .callback = SampleServiceCallback, + .registerDevice = SampleServiceRegisterDevice, + .unregisterDevice = SampleServiceUnregisterDevice, }; const struct SampleHdi *SampleHdiImplInstance() diff --git a/uhdf2/host/test/unittest/sample_driver/sample_hdi_service_stub.c b/uhdf2/host/test/unittest/sample_driver/sample_hdi_service_stub.c index 75e0cc7..6162093 100644 --- a/uhdf2/host/test/unittest/sample_driver/sample_hdi_service_stub.c +++ b/uhdf2/host/test/unittest/sample_driver/sample_hdi_service_stub.c @@ -117,6 +117,30 @@ static int32_t SampleServiceStubBufferTrans(struct HdfDeviceIoClient *client, return HDF_SUCCESS; } +static int32_t SampleServiceRegisterDevice(struct HdfDeviceIoClient *client, + struct HdfSBuf *data, struct HdfSBuf *reply) +{ + (void)reply; + const char *deviceName = HdfSbufReadString(data); + if (deviceName == NULL) { + return HDF_ERR_INVALID_PARAM; + } + + return SampleHdiImplInstance()->registerDevice(client->device, deviceName); +} + +static int32_t SampleServiceUnregisterDevice(struct HdfDeviceIoClient *client, + struct HdfSBuf *data, struct HdfSBuf *reply) +{ + (void)reply; + const char *deviceName = HdfSbufReadString(data); + if (deviceName == NULL) { + return HDF_ERR_INVALID_PARAM; + } + + return SampleHdiImplInstance()->unregisterDevice(client->device, deviceName); +} + int32_t SampleServiceOnRemoteRequest(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply) { @@ -131,6 +155,10 @@ int32_t SampleServiceOnRemoteRequest(struct HdfDeviceIoClient *client, int cmdId return SampleServiceStubStructTrans(client, data, reply); case SAMPLE_BUFFER_TRANS: return SampleServiceStubBufferTrans(client, data, reply); + case SAMPLE_REGISTER_DEVICE: + return SampleServiceRegisterDevice(client, data, reply); + case SAMPLE_UNREGISTER_DEVICE: + return SampleServiceUnregisterDevice(client, data, reply); default: HDF_LOGE("SampleServiceDispatch: not support cmd %{public}d", cmdId); return HDF_ERR_INVALID_PARAM; diff --git a/uhdf2/include/devhost/hdf_device_full.h b/uhdf2/include/devhost/hdf_device_full.h index f456dda..644edae 100644 --- a/uhdf2/include/devhost/hdf_device_full.h +++ b/uhdf2/include/devhost/hdf_device_full.h @@ -16,7 +16,6 @@ #ifndef HDF_DEVICE_FULL_H #define HDF_DEVICE_FULL_H -#include "hdf_attribute.h" #include "hdf_dev_token.h" #include "hdf_device.h" diff --git a/uhdf2/include/hdf_devmgr.h b/uhdf2/include/hdf_devmgr.h deleted file mode 100755 index 12380c4..0000000 --- a/uhdf2/include/hdf_devmgr.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device 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 __HDF_DEVMGR_H__ -#define __HDF_DEVMGR_H__ - -#if defined(__KERNEL__) - -#elif defined(CONFIG_LITE_OS) - -#else -#include "devhost/hdf_attribute.h" -#include "devhost/hdf_device.h" -#include "devhost/hdf_device_full.h" -#include "devhost/hdf_driver.h" -#include "devhost/dm_service_if.h" -#include "devhost/ds_manager_if.h" - -#include "hidl/hdf_dev_token.h" -#include "hidl/hdf_ds_manager_clnt.h" - -#include "mock/hdf_sbuf.h" -#include "mock/hdf_remote_object.h" -#include "mock/hdf_service_registry.h" - -#include "../third_party/utils/include/of/fdt_convertor.h" -#include "../third_party/utils/include/of/of.h" -#endif - -#endif /* __HDF_DEVMGR_H__ */ diff --git a/uhdf2/include/hdi/devmgr_hdi.h b/uhdf2/include/hdi/devmgr_hdi.h index 810e4a6..881f2ae 100644 --- a/uhdf2/include/hdi/devmgr_hdi.h +++ b/uhdf2/include/hdi/devmgr_hdi.h @@ -47,10 +47,8 @@ struct HDIDeviceManager { void (*FreeQueryDeviceList)(struct HDIDeviceManager *self, struct DeviceInfoList *list); int32_t (*QueryUsableDeviceInfo)(struct HDIDeviceManager *self, struct DeviceInfoList *list); int32_t (*QueryUnusableDeviceInfo)(struct HDIDeviceManager *self, struct DeviceInfoList *list); - int32_t (*RegPnpDevice)(struct HDIDeviceManager *self, const char *moduleName, const char *serviceName); - int32_t (*UnRegPnpDevice)(struct HDIDeviceManager *self, const char *moduleName, const char *serviceName); - int32_t (*RegVirtualDevice)(struct HDIDeviceManager *self, const char *moduleName, const char *serviceName); - int32_t (*UnRegVirtualDevice)(struct HDIDeviceManager *self, const char *moduleName, const char *serviceName); + int32_t (*LoadDevice)(struct HDIDeviceManager *self, const char *serviceName); + int32_t (*UnloadDevice)(struct HDIDeviceManager *self, const char *serviceName); }; struct HDIDeviceManager *HDIDeviceManagerGet(void); diff --git a/uhdf2/include/hdi/iservmgr_hdi.h b/uhdf2/include/hdi/iservmgr_hdi.h index 7c0f261..b6a2503 100644 --- a/uhdf2/include/hdi/iservmgr_hdi.h +++ b/uhdf2/include/hdi/iservmgr_hdi.h @@ -23,7 +23,7 @@ namespace HDI { namespace ServiceManager { namespace V1_0 { -struct IServiceManager : public IRemoteBroker { +class IServiceManager : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"HDI.IServiceManager.V1_0"); static ::OHOS::sptr Get(); diff --git a/uhdf2/manager/BUILD.gn b/uhdf2/manager/BUILD.gn index aefd870..d459b5c 100644 --- a/uhdf2/manager/BUILD.gn +++ b/uhdf2/manager/BUILD.gn @@ -21,7 +21,6 @@ ohos_executable("hdf_devmgr") { "$hdf_framework_path/core/common/include/manager/", "$hdf_framework_path/core/host/include", "$hdf_framework_path/core/shared/include", - "$hdf_framework_path/model/usb/include", "$hdf_uhdf_path/ipc/include", "$hdf_uhdf_path/osal/include/", "$hdf_uhdf_path/include/osal", @@ -35,6 +34,7 @@ ohos_executable("hdf_devmgr") { ] sources = [ + "$hdf_framework_path/core/common/src/hdf_attribute.c", "$hdf_framework_path/core/manager/src/devhost_service_clnt.c", "$hdf_framework_path/core/manager/src/device_token_clnt.c", "$hdf_framework_path/core/manager/src/devmgr_service.c", @@ -44,23 +44,17 @@ ohos_executable("hdf_devmgr") { "$hdf_framework_path/core/shared/src/hdf_device_info.c", "$hdf_framework_path/core/shared/src/hdf_object_manager.c", "$hdf_framework_path/core/shared/src/hdf_service_record.c", - "$hdf_framework_path/model/usb/src/usb_ddk_pnp_loader.c", - "$hdf_uhdf_path/shared/src/dev_attribute_parcel.c", - "$hdf_uhdf_path/shared/src/hdf_attribute_full.c", - "$hdf_uhdf_path/shared/src/hdf_device_info_full.c", + "$hdf_uhdf_path/shared/src/dev_attribute_serialize.c", + "$hdf_uhdf_path/shared/src/hcb_config_entry.c", "device_manager.c", "src/devhost_service_proxy.c", "src/device_token_proxy.c", "src/devmgr_object_config.c", - "src/devmgr_pnp_service.c", "src/devmgr_query_device.c", "src/devmgr_service_full.c", "src/devmgr_service_stub.c", - "src/devmgr_virtual_service.c", "src/devsvc_manager_stub.c", "src/driver_installer_full.c", - "src/hdf_get_attribute.c", - "src/usb_pnp_manager.c", ] deps = [ diff --git a/uhdf2/manager/include/devmgr_pnp_service.h b/uhdf2/manager/include/devmgr_pnp_service.h deleted file mode 100755 index d674527..0000000 --- a/uhdf2/manager/include/devmgr_pnp_service.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device 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 DEVMGR_PNP_SERVICE_H -#define DEVMGR_PNP_SERVICE_H - -#include "devmgr_service.h" -#include "hdf_slist.h" - -#define PNP_HOST_NAME "pnp_host" - -struct HdfSList *DevmgrServiceGetPnpDeviceInfo(); - -struct DevHostServiceClnt *DevmgrServiceGetPnpHostClnt(struct DevmgrService *inst); - -int32_t DevmgrServiceStartPnpHost(struct DevmgrService *inst); - -int32_t DevmgrServiceRegPnpDevice( - struct IDevmgrService *devmgrSvc, const char *moduleName, const char *serviceName, - const char *deviceMatchAttr, const void *privateData); - -int32_t DevmgrServiceUnRegPnpDevice( - struct IDevmgrService *devmgrSvc, const char *moduleName, const char *serviceName); - -#endif diff --git a/uhdf2/manager/include/devmgr_service_stub.h b/uhdf2/manager/include/devmgr_service_stub.h index cde0960..c0ac543 100755 --- a/uhdf2/manager/include/devmgr_service_stub.h +++ b/uhdf2/manager/include/devmgr_service_stub.h @@ -32,11 +32,9 @@ enum { DEVMGR_SERVICE_ATTACH_DEVICE_HOST = 1, DEVMGR_SERVICE_ATTACH_DEVICE, DEVMGR_SERVICE_DETACH_DEVICE, - DEVMGR_SERVICE_REGIST_PNP_DEVICE, - DEVMGR_SERVICE_UNREGIST_PNP_DEVICE, + DEVMGR_SERVICE_LOAD_DEVICE, + DEVMGR_SERVICE_UNLOAD_DEVICE, DEVMGR_SERVICE_QUERY_DEVICE, - DEVMGR_SERVICE_REGISTER_VIRTUAL_DEVICE, - DEVMGR_SERVICE_UNREGISTER_VIRTUAL_DEVICE, }; struct HdfObject *DevmgrServiceStubCreate(void); diff --git a/uhdf2/manager/include/usb_pnp_manager.h b/uhdf2/manager/include/usb_pnp_manager.h deleted file mode 100644 index 1b5dec4..0000000 --- a/uhdf2/manager/include/usb_pnp_manager.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device 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 USB_PNP_MANAGE_H -#define USB_PNP_MANAGE_H - -#include "devmgr_service_if.h" -#include "hdf_device_info_full.h" - -struct UsbPnpManagerDeviceInfo { - struct IDevmgrService *devmgrSvc; - const char *moduleName; - const char *serviceName; - const char *deviceMatchAttr; - const void *privateData; - bool isReg; -}; - -bool UsbPnpManagerWriteModuleName(struct HdfSBuf *sbuf, const char *moduleName); -int32_t UsbPnpManagerRegisterOrUnregisterDevice(struct UsbPnpManagerDeviceInfo managerInfo); - -int DevmgrUsbPnpManageEventHandle(struct IDevmgrService *inst); -bool DevmgrUsbPnpManageAddPrivateData(struct HdfDeviceInfoFull *deviceInfo, const void *privateData); - -#endif /* USB_PNP_MANAGE_H */ diff --git a/uhdf2/manager/src/devhost_service_proxy.c b/uhdf2/manager/src/devhost_service_proxy.c old mode 100755 new mode 100644 index 7986b99..0aed2cb --- a/uhdf2/manager/src/devhost_service_proxy.c +++ b/uhdf2/manager/src/devhost_service_proxy.c @@ -14,10 +14,9 @@ */ #include "devhost_service_proxy.h" -#include "dev_attribute_parcel.h" +#include "dev_attribute_serialize.h" #include "devmgr_service_full.h" #include "hdf_base.h" -#include "hdf_device_info_full.h" #include "hdf_log.h" #include "hdf_sbuf.h" #include "osal_mem.h" @@ -29,7 +28,6 @@ static int32_t DevHostServiceProxyOpsDevice( struct IDevHostService *inst, const struct HdfDeviceInfo *attribute, int opsCode) { int status = HDF_FAILURE; - const struct HdfDeviceInfoFull *fullAttribute = HdfDeviceInfoFullReinterpretCast(attribute); struct HdfSBuf *data = HdfSBufTypedObtain(SBUF_IPC); struct DevHostServiceProxy *hostClnt = (struct DevHostServiceProxy *)inst; if (hostClnt->remote == NULL || data == NULL) { @@ -37,7 +35,7 @@ static int32_t DevHostServiceProxyOpsDevice( goto finished; } - DeviceAttributeFullWrite(fullAttribute, data); + DeviceAttributeSerialize(attribute, data); status = hostClnt->remote->dispatcher->Dispatch(hostClnt->remote, DEVHOST_SERVICE_ADD_DEVICE, data, NULL); finished: if (data != NULL) { diff --git a/uhdf2/manager/src/devmgr_pnp_service.c b/uhdf2/manager/src/devmgr_pnp_service.c deleted file mode 100644 index 0134215..0000000 --- a/uhdf2/manager/src/devmgr_pnp_service.c +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device 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 "devmgr_pnp_service.h" -#include "devhost_service_clnt.h" -#include "hdf_device_info_full.h" -#include "hdf_dlist.h" -#include "hdf_driver_installer.h" -#include "hdf_log.h" -#include "osal_mem.h" -#include "osal_time.h" -#include "usb_pnp_manager.h" - -#define PNP_SLEEP_TIME 50 // ms - -static struct HdfSList *g_deviceInfos = NULL; -static uint16_t g_hostId = 0xFFFF; -static uint32_t g_deviceId = 0; - -struct HdfSList *DevmgrServiceGetPnpDeviceInfo(void) -{ - return g_deviceInfos; -} - -void DevmgrServiceSetPnpHostId(uint16_t hostId) -{ - struct HdfSListIterator it; - struct HdfDeviceInfoFull *deviceInfo = NULL; - g_hostId = hostId; - HdfSListIteratorInit(&it, g_deviceInfos); - while (HdfSListIteratorHasNext(&it)) { - deviceInfo = (struct HdfDeviceInfoFull *)HdfSListIteratorNext(&it); - deviceInfo->super.hostId = hostId; - } -} - -static bool DevmgrServiceIsPnpDeviceExist(const char *moduleName, const char *serviceName) -{ - struct HdfSListIterator it; - struct HdfDeviceInfoFull *deviceInfo = NULL; - HdfSListIteratorInit(&it, g_deviceInfos); - while (HdfSListIteratorHasNext(&it)) { - deviceInfo = (struct HdfDeviceInfoFull *)HdfSListIteratorNext(&it); - if ((strcmp(deviceInfo->super.moduleName, moduleName) == 0) && - (strcmp(deviceInfo->super.svcName, serviceName) == 0)) { - return true; - } - } - return false; -} - -static bool DevmgrServiceAddPnpDeviceInfo(struct HdfDeviceInfoFull *deviceInfo) -{ - if (g_deviceInfos == NULL) { - g_deviceInfos = OsalMemCalloc(sizeof(struct HdfSList)); - if (g_deviceInfos == NULL) { - return false; - } - } - deviceInfo->super.deviceId = g_deviceId++; // HdfSListCount g_deviceInfos - deviceInfo->super.hostId = g_hostId; - deviceInfo->super.policy = SERVICE_POLICY_PUBLIC; - deviceInfo->super.preload = DEVICE_PRELOAD_ENABLE; - HdfSListAdd(g_deviceInfos, &deviceInfo->super.node); - return true; -} - -static bool DevmgrServiceAddPnpDevice( - const char *moduleName, const char *serviceName, const char *deviceMatchAttr, const void *privateData) -{ - if (moduleName == NULL || serviceName == NULL) { - return false; - } - if (DevmgrServiceIsPnpDeviceExist(moduleName, serviceName)) { - HDF_LOGE("%{public}s adding pnp device failed, %{public}s already exist", __func__, moduleName); - return false; - } - struct HdfDeviceInfoFull *deviceInfo = HdfDeviceInfoFullNewInstance(); - if (deviceInfo == NULL) { - return false; - } - deviceInfo->super.moduleName = strdup(moduleName); - if (deviceInfo->super.moduleName == NULL) { - HdfDeviceInfoFullFreeInstance(deviceInfo); - return false; - } - deviceInfo->super.svcName = strdup(serviceName); - if (deviceInfo->super.svcName == NULL) { - HdfDeviceInfoFullFreeInstance(deviceInfo); - return false; - } - - deviceInfo->super.deviceMatchAttr = strdup(deviceMatchAttr); - if (deviceInfo->super.deviceMatchAttr == NULL) { - HdfDeviceInfoFullFreeInstance(deviceInfo); - return false; - } - - if (!DevmgrUsbPnpManageAddPrivateData(deviceInfo, privateData)) { - HdfDeviceInfoFullFreeInstance(deviceInfo); - return false; - } - - if (!DevmgrServiceAddPnpDeviceInfo(deviceInfo)) { - HdfDeviceInfoFullFreeInstance(deviceInfo); - return false; - } - return true; -} - -static void DevmgrServiceDelPnpDevice(const char *moduleName, const char *serviceName) -{ - struct HdfSListIterator it; - struct HdfDeviceInfoFull *deviceInfo = NULL; - HdfSListIteratorInit(&it, g_deviceInfos); - while (HdfSListIteratorHasNext(&it)) { - deviceInfo = (struct HdfDeviceInfoFull *)HdfSListIteratorNext(&it); - if ((strcmp(deviceInfo->super.moduleName, moduleName) == 0) && - (strcmp(deviceInfo->super.svcName, serviceName) == 0)) { - HdfSListRemove(g_deviceInfos, &deviceInfo->super.node); - HdfDeviceInfoFullFreeInstance(deviceInfo); - return; - } - } -} - -struct DevHostServiceClnt *DevmgrServiceGetPnpHostClnt(struct DevmgrService *inst) -{ - struct DevHostServiceClnt *hostClnt = NULL; - if (inst == NULL) { - return NULL; - } - - DLIST_FOR_EACH_ENTRY(hostClnt, &inst->hosts, struct DevHostServiceClnt, node) { - if (strcmp(hostClnt->hostName, PNP_HOST_NAME) == 0) { - return hostClnt; - } - } - return NULL; -} - -int32_t DevmgrServiceStartPnpHost(struct DevmgrService *inst) -{ - struct DevHostServiceClnt *hostClnt = NULL; - struct IDriverInstaller *installer = NULL; - int32_t ret = HDF_FAILURE; - - installer = DriverInstallerGetInstance(); - if ((installer == NULL) || (installer->StartDeviceHost == NULL)) { - HDF_LOGE("%{public}s installer or installer->StartDeviceHost is null", __func__); - return ret; - } - - uint16_t hostId = DlistGetCount(&inst->hosts); - DevmgrServiceSetPnpHostId(hostId); - hostClnt = DevHostServiceClntNewInstance(hostId, PNP_HOST_NAME); - if (hostClnt == NULL) { - HDF_LOGW("%{public}s creating new device host client failed", __func__); - return ret; - } - DListInsertTail(&hostClnt->node, &inst->hosts); - ret = installer->StartDeviceHost(hostClnt->hostId, hostClnt->hostName); - if (ret != HDF_SUCCESS) { - HDF_LOGW("%{public}s starting host failed, host name is %{public}s", __func__, hostClnt->hostName); - DListRemove(&hostClnt->node); - DevHostServiceClntFreeInstance(hostClnt); - } - return ret; -} - -static int DevmgrServiceInstallDevice(struct DevHostServiceClnt *hostClnt, const char *serviceName) -{ - int ret = HDF_FAILURE; - struct HdfSListIterator it; - struct HdfDeviceInfo *deviceInfo = NULL; - struct IDevHostService *devHostSvcIf = NULL; - - devHostSvcIf = (struct IDevHostService *)hostClnt->hostService; - if (devHostSvcIf == NULL || devHostSvcIf->AddDevice == NULL) { - HDF_LOGE("devHostSvcIf or devHostSvcIf->AddDevice is null"); - return ret; - } - HdfSListIteratorInit(&it, hostClnt->deviceInfos); - while (HdfSListIteratorHasNext(&it)) { - deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&it); - if (strcmp(deviceInfo->svcName, serviceName) == 0) { - ret = devHostSvcIf->AddDevice(devHostSvcIf, deviceInfo); - if (ret != HDF_SUCCESS) { - HDF_LOGE("Installing %{public}s driver failed, ret = %{public}d", deviceInfo->svcName, ret); - } - break; - } - } - return ret; -} - -int32_t DevmgrServiceRegPnpDevice( - struct IDevmgrService *devmgrSvc, const char *moduleName, const char *serviceName, - const char *deviceMatchAttr, const void *privateData) -{ - int32_t ret = HDF_FAILURE; - struct DevmgrService *inst = (struct DevmgrService *)devmgrSvc; - if (inst == NULL) { - return HDF_ERR_INVALID_PARAM; - } - struct DevHostServiceClnt *hostClnt = DevmgrServiceGetPnpHostClnt(inst); - if (hostClnt == NULL) { - ret = DevmgrServiceStartPnpHost(inst); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%{public}s add pnp device failed!", __func__); - return ret; - } - OsalMSleep(PNP_SLEEP_TIME); - hostClnt = DevmgrServiceGetPnpHostClnt(inst); - } - if (hostClnt == NULL || hostClnt->hostService == NULL) { - HDF_LOGE("%{public}s host service is null!", __func__); - return HDF_ERR_INVALID_OBJECT; - } - if (!DevmgrServiceAddPnpDevice(moduleName, serviceName, deviceMatchAttr, privateData)) { - HDF_LOGE("%{public}s add pnp device failed!", __func__); - return ret; - } - - hostClnt->deviceInfos = DevmgrServiceGetPnpDeviceInfo(); - ret = DevmgrServiceInstallDevice(hostClnt, serviceName); - if (ret != HDF_SUCCESS) { - DevmgrServiceDelPnpDevice(moduleName, serviceName); - HDF_LOGE("%{public}s: failed %{public}d %{public}s", __func__, hostClnt->hostId, hostClnt->hostName); - } - return ret; -} - - -int32_t DevmgrServiceUnRegPnpDevice( - struct IDevmgrService *devmgrSvc, const char *moduleName, const char *serviceName) -{ - int ret = HDF_FAILURE; - struct DevmgrService *inst = (struct DevmgrService *)devmgrSvc; - struct DevHostServiceClnt *hostClnt = DevmgrServiceGetPnpHostClnt(inst); - if (hostClnt == NULL || hostClnt->hostService == NULL) { - HDF_LOGE("%{public}s host service is not init", __func__); - OsalMSleep(PNP_SLEEP_TIME); - hostClnt = DevmgrServiceGetPnpHostClnt(inst); - if (hostClnt == NULL || hostClnt->hostService == NULL) { - HDF_LOGE("%{public}s host service is not init", __func__); - return ret; - } - } - - struct HdfSListIterator it; - struct HdfDeviceInfo *deviceInfo = NULL; - struct IDevHostService *devHostSvcIf = NULL; - - devHostSvcIf = (struct IDevHostService *)hostClnt->hostService; - if (devHostSvcIf->DelDevice == NULL) { - HDF_LOGE("%{public}s host del device is not init", __func__); - return ret; - } - HdfSListIteratorInit(&it, hostClnt->deviceInfos); - while (HdfSListIteratorHasNext(&it)) { - deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&it); - if ((strcmp(deviceInfo->moduleName, moduleName) == 0) && - (strcmp(deviceInfo->svcName, serviceName) == 0)) { - deviceInfo->status = HDF_SERVICE_UNUSABLE; - ret = devHostSvcIf->DelDevice(devHostSvcIf, deviceInfo->deviceId); - DevmgrServiceDelPnpDevice(moduleName, serviceName); - } - } - return ret; -} - diff --git a/uhdf2/manager/src/devmgr_query_device.c b/uhdf2/manager/src/devmgr_query_device.c index 7b36c45..eaf3a8f 100644 --- a/uhdf2/manager/src/devmgr_query_device.c +++ b/uhdf2/manager/src/devmgr_query_device.c @@ -43,7 +43,7 @@ int DevFillQueryDeviceInfo(struct IDevmgrService *inst, struct HdfSBuf *data, st } DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) { - HdfSListIteratorInit(&itDeviceInfo, hostClnt->deviceInfos); + HdfSListIteratorInit(&itDeviceInfo, &hostClnt->unloadDevInfos); HDF_LOGD("%{public}s, host:%{public}s %{public}d", __func__, hostClnt->hostName, hostClnt->hostId); while (HdfSListIteratorHasNext(&itDeviceInfo)) { deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo); diff --git a/uhdf2/manager/src/devmgr_service_full.c b/uhdf2/manager/src/devmgr_service_full.c index 4d2774c..4bcd58e 100644 --- a/uhdf2/manager/src/devmgr_service_full.c +++ b/uhdf2/manager/src/devmgr_service_full.c @@ -33,7 +33,7 @@ static Map g_hostMap = {0}; static int32_t DevmgrServiceFullHandleDeviceHostDied(struct DevHostServiceClnt *hostClnt) { - if (!HdfSListIsEmpty(hostClnt->deviceInfos)) { + if (!HdfSListIsEmpty(&hostClnt->devices)) { if (g_hostMap.nodeSize == 0) { MapInit(&g_hostMap); } @@ -43,13 +43,14 @@ static int32_t DevmgrServiceFullHandleDeviceHostDied(struct DevHostServiceClnt * MapSet(&g_hostMap, hostClnt->hostName, &hostDieNum, sizeof(int)); } else { if (*hostDieValue > HOST_MAX_DIE_NUM) { + HDF_LOGE("host %{public}s die 4 times, remove it", hostClnt->hostName); *hostDieValue = 0; return INVALID_PID; } (*hostDieValue)++; } struct IDriverInstaller *installer = DriverInstallerGetInstance(); - if ((installer != NULL) && (installer->StartDeviceHost)) { + if (installer != NULL && installer->StartDeviceHost != NULL) { hostClnt->hostPid = installer->StartDeviceHost(hostClnt->hostId, hostClnt->hostName); return hostClnt->hostPid; } @@ -69,7 +70,7 @@ void DevmgrServiceFullOnDeviceHostDied(struct DevmgrServiceFull *inst, uint32_t DLIST_FOR_EACH_ENTRY_SAFE(hostClnt, hostClntTmp, &inst->super.hosts, struct DevHostServiceClnt, node) { if (hostClnt->hostId == hostId) { int32_t ret = DevmgrServiceFullHandleDeviceHostDied(hostClnt); - if (ret == INVALID_PID) { + if (ret == INVALID_PID && HdfSListIsEmpty(&hostClnt->dynamicDevInfos)) { DListRemove(&hostClnt->node); DevHostServiceClntFreeInstance(hostClnt); } diff --git a/uhdf2/manager/src/devmgr_service_stub.c b/uhdf2/manager/src/devmgr_service_stub.c index 2577d88..962f37d 100644 --- a/uhdf2/manager/src/devmgr_service_stub.c +++ b/uhdf2/manager/src/devmgr_service_stub.c @@ -17,7 +17,6 @@ #include "devhost_service_clnt.h" #include "devhost_service_proxy.h" #include "device_token_proxy.h" -#include "devmgr_pnp_service.h" #include "devmgr_query_device.h" #include "devmgr_virtual_service.h" #include "devsvc_manager.h" @@ -26,7 +25,6 @@ #include "hdf_sbuf.h" #include "osal_mem.h" #include "osal_sysevent.h" -#include "usb_pnp_manager.h" #define HDF_LOG_TAG devmgr_service_stub @@ -58,27 +56,26 @@ static int32_t DevmgrServiceStubDispatchDetachDevice(struct IDevmgrService *devm return devmgrSvc->DetachDevice(devmgrSvc, deviceId); } - -static int32_t DevmgrServiceStubDispatchPnpDevice( - struct IDevmgrService *devmgrSvc, struct HdfSBuf *data, bool isReg) +static int32_t DevmgrServiceStubDispatchLoadDevice(struct IDevmgrService *devmgrSvc, struct HdfSBuf *data) { - int32_t ret = HDF_FAILURE; - - const char *moduleName = HdfSbufReadString(data); - if (moduleName == NULL) { - return ret; - } const char *serviceName = HdfSbufReadString(data); if (serviceName == NULL) { - return ret; + HDF_LOGE("%{public}s:service name is null", __func__); + return HDF_ERR_INVALID_PARAM; } - if (isReg) { - ret = DevmgrServiceRegPnpDevice(devmgrSvc, moduleName, serviceName, NULL, NULL); - } else { - ret = DevmgrServiceUnRegPnpDevice(devmgrSvc, moduleName, serviceName); + return devmgrSvc->LoadDevice(devmgrSvc, serviceName); +} + +static int32_t DevmgrServiceStubDispatchUnloadDevice(struct IDevmgrService *devmgrSvc, struct HdfSBuf *data) +{ + const char *serviceName = HdfSbufReadString(data); + if (serviceName == NULL) { + HDF_LOGE("%{public}s:service name is null", __func__); + return HDF_ERR_INVALID_PARAM; } - return ret; + + return devmgrSvc->UnloadDevice(devmgrSvc, serviceName); } int32_t DevmgrServiceStubDispatch( @@ -111,26 +108,18 @@ int32_t DevmgrServiceStubDispatch( ret = DevmgrServiceStubDispatchDetachDevice(super, data); break; } - case DEVMGR_SERVICE_REGIST_PNP_DEVICE: { - ret = DevmgrServiceStubDispatchPnpDevice(super, data, true); + case DEVMGR_SERVICE_LOAD_DEVICE: { + ret = DevmgrServiceStubDispatchLoadDevice(super, data); break; } - case DEVMGR_SERVICE_UNREGIST_PNP_DEVICE: { - ret = DevmgrServiceStubDispatchPnpDevice(super, data, false); + case DEVMGR_SERVICE_UNLOAD_DEVICE: { + ret = DevmgrServiceStubDispatchUnloadDevice(super, data); break; } case DEVMGR_SERVICE_QUERY_DEVICE: { ret = DevFillQueryDeviceInfo(super, data, reply); break; } - case DEVMGR_SERVICE_REGISTER_VIRTUAL_DEVICE: { - ret = DevmgrServiceVirtualDevice(super, data, reply, true); - break; - } - case DEVMGR_SERVICE_UNREGISTER_VIRTUAL_DEVICE: { - ret = DevmgrServiceVirtualDevice(super, data, reply, false); - break; - } default: break; } @@ -176,14 +165,7 @@ int DevmgrServiceStubStartService(struct IDevmgrService *inst) } fullService->remote = remoteService; - status = DevmgrServiceStartService((struct IDevmgrService *)&fullService->super); - if (status == HDF_SUCCESS) { - if (DevmgrUsbPnpManageEventHandle(inst) != HDF_SUCCESS) { - HDF_LOGE("%s:%d DevmgrUsbPnpManageEventHandle error", __func__, __LINE__); - } - } - - return status; + return DevmgrServiceStartService((struct IDevmgrService *)&fullService->super); } static void DevmgrServiceStubConstruct(struct DevmgrServiceStub *inst) diff --git a/uhdf2/manager/src/devmgr_virtual_service.c b/uhdf2/manager/src/devmgr_virtual_service.c deleted file mode 100755 index d63af0c..0000000 --- a/uhdf2/manager/src/devmgr_virtual_service.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device 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 "devhost_service_clnt.h" -#include "devmgr_pnp_service.h" -#include "devmgr_service.h" -#include "devsvc_manager.h" -#include "hdf_base.h" -#include "hdf_cstring.h" -#include "hdf_log.h" -#include "hdf_sbuf.h" - -#define HDF_LOG_TAG devmgr_reg_virtual_device - -static void DevmgrUpdateDeviceType(struct HdfSList *list, const char *moduleName, const char *serviceName) -{ - struct HdfSListIterator it; - struct HdfDeviceInfo *deviceInfo = NULL; - - HdfSListIteratorInit(&it, list); - while (HdfSListIteratorHasNext(&it)) { - deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&it); - if ((deviceInfo != NULL) && - (strcmp(deviceInfo->moduleName, moduleName) == 0) && (strcmp(deviceInfo->svcName, serviceName) == 0)) { - deviceInfo->deviceType = HDF_DEV_REMOTE_SERVICE; - HDF_LOGD("%{public}s: set remote service %{public}s %{public}s %{public}d", - __func__, moduleName, serviceName, deviceInfo->deviceType); - return; - } - } - HDF_LOGE("%{public}s: remote service %{public}s %{public}s not found", __func__, moduleName, serviceName); -} - -int DevmgrServiceVirtualDevice( - struct IDevmgrService *inst, struct HdfSBuf *data, struct HdfSBuf *reply, bool flag) -{ - int32_t ret; - struct HdfSList *list = NULL; - - (void)reply; - if (inst == NULL || data == NULL) { - HDF_LOGE("%{public}s para invalid", __func__); - return HDF_FAILURE; - } - - const char *moduleName = HdfSbufReadString(data); - const char *serviceName = HdfSbufReadString(data); - if (moduleName == NULL || serviceName == NULL) { - HDF_LOGE("%{public}s: reading string failed", __func__); - return HDF_FAILURE; - } - - if (flag) { - ret = DevmgrServiceRegPnpDevice(inst, moduleName, serviceName, NULL, NULL); - if (ret == HDF_SUCCESS) { - list = DevmgrServiceGetPnpDeviceInfo(); - DevmgrUpdateDeviceType(list, moduleName, serviceName); - } - } else { - ret = DevmgrServiceUnRegPnpDevice(inst, moduleName, serviceName); - } - - return ret; -} - diff --git a/uhdf2/manager/src/hdf_get_attribute.c b/uhdf2/manager/src/hdf_get_attribute.c deleted file mode 100644 index 9ae8abe..0000000 --- a/uhdf2/manager/src/hdf_get_attribute.c +++ /dev/null @@ -1,272 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device 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 -#include -#include "devmgr_pnp_service.h" -#include "hcs_parser.h" -#include "hcs_dm_parser.h" -#include "hcs_tree_if.h" -#include "hdf_attribute_manager.h" -#include "hdf_device_info_full.h" -#include "hdf_host_info.h" -#include "hdf_log.h" -#include "osal_mem.h" -#include "securec.h" - -#define HDF_LOG_TAG attribute_manager - -#define ATTR_HOST_NAME "hostName" -#define ATTR_DEV_POLICY "policy" -#define ATTR_DEV_PRIORITY "priority" -#define ATTR_DEV_PRELOAD "preload" -#define ATTR_DEV_PERMISSION "permission" -#define ATTR_DEV_MODULENAME "moduleName" -#define ATTR_DEV_SVCNAME "serviceName" -#define ATTR_DEV_MATCHATTR "deviceMatchAttr" -#define MANAGER_NODE_MATCH_ATTR "hdf_manager" - -static bool HdfHostListCompare(struct HdfSListNode *listEntryFirst, struct HdfSListNode *listEntrySecond) -{ - if (listEntryFirst == NULL || listEntrySecond == NULL) { - return false; - } - struct HdfHostInfo *attrFirst = (struct HdfHostInfo *)listEntryFirst; - struct HdfHostInfo *attrSecond = (struct HdfHostInfo *)listEntrySecond; - return attrFirst->priority <= attrSecond->priority; -} - -static const struct DeviceResourceNode *GetHdfManagerNode(const struct DeviceResourceNode *node) -{ - return HcsGetNodeByMatchAttr(node, MANAGER_NODE_MATCH_ATTR); -} - -static bool GetHostInfo(const struct DeviceResourceNode *hostNode, struct HdfHostInfo *hostInfo) -{ - uint16_t readNum = 0; - if ((HcsGetString(hostNode, ATTR_HOST_NAME, &hostInfo->hostName, NULL) != HDF_SUCCESS) || - (strcmp(hostInfo->hostName, "") == 0)) { - HDF_LOGW("%{public}s get host name failed", __func__); - return false; - } - if ((HcsGetUint16(hostNode, ATTR_DEV_PRIORITY, &readNum, 0) != HDF_SUCCESS) || - (readNum > MAX_PRIORITY_NUM)) { - HDF_LOGW("%{public}s get host priority failed, priority is: %{public}d", __func__, readNum); - return false; - } - hostInfo->priority = readNum; - return true; -} - -bool HdfAttributeManagerGetHostList(struct HdfSList *hostList) -{ - const struct DeviceResourceNode *hdfManagerNode = NULL; - const struct DeviceResourceNode *hostNode = NULL; - uint16_t hostId = 0; - if (hostList == NULL) { - return false; - } - - hdfManagerNode = GetHdfManagerNode(HdfGetRootNode()); - if (hdfManagerNode == NULL) { - HDF_LOGE("%{public}s get hdf manager node is null", __func__); - return false; - } - - hostNode = hdfManagerNode->child; - while (hostNode != NULL) { - struct HdfHostInfo *hostInfo = HdfHostInfoNewInstance(); - if (hostInfo == NULL) { - HdfSListFlush(hostList, HdfHostInfoDelete); - HDF_LOGE("%{public}s new hostInfo is null", __func__); - return false; - } - if (!GetHostInfo(hostNode, hostInfo)) { - HdfHostInfoFreeInstance(hostInfo); - hostNode = hostNode->sibling; - continue; - } - hostInfo->hostId = hostId; - if (!HdfSListAddOrder(hostList, &hostInfo->node, HdfHostListCompare)) { - HdfHostInfoFreeInstance(hostInfo); - hostNode = hostNode->sibling; - continue; - } - hostId++; - hostNode = hostNode->sibling; - } - return true; -} - -static bool HdfDeviceListCompare(struct HdfSListNode *listEntryFirst, struct HdfSListNode *listEntrySecond) -{ - if (listEntryFirst == NULL || listEntrySecond == NULL) { - return false; - } - struct HdfDeviceInfo *attrFirst = (struct HdfDeviceInfo *)listEntryFirst; - struct HdfDeviceInfo *attrSecond = (struct HdfDeviceInfo *)listEntrySecond; - return attrFirst->priority <= attrSecond->priority; -} - -static const struct DeviceResourceNode *GetHostNode(const char *inHostName) -{ - const struct DeviceResourceNode *hdfManagerNode = NULL; - const struct DeviceResourceNode *hostNode = NULL; - const char *hostName = NULL; - - hdfManagerNode = GetHdfManagerNode(HdfGetRootNode()); - if (hdfManagerNode == NULL) { - return NULL; - } - hostNode = hdfManagerNode->child; - while (hostNode != NULL) { - if (HcsGetString(hostNode, ATTR_HOST_NAME, &hostName, NULL) != HDF_SUCCESS) { - hostNode = hostNode->sibling; - continue; - } - if (strcmp(hostName, inHostName) == 0) { - return hostNode; - } - hostNode = hostNode->sibling; - } - return NULL; -} - -static bool CheckDeviceInfo(struct HdfDeviceInfo *deviceNodeInfo) -{ - if (deviceNodeInfo->policy > SERVICE_POLICY_PRIVATE) { - HDF_LOGE("%{public}s policy is invalid", __func__); - return false; - } - - if (deviceNodeInfo->priority > MAX_PRIORITY_NUM) { - HDF_LOGE("%{public}s priority is invalid", __func__); - return false; - } - - if (deviceNodeInfo->preload > DEVICE_PRELOAD_DISABLE) { - HDF_LOGE("%{public}s preload is invalid", __func__); - return false; - } - return true; -} - -static bool GetDeviceNodeInfo(const struct DeviceResourceNode *deviceNode, struct HdfDeviceInfo *deviceNodeInfo) -{ - uint16_t readNum = 0; - const char *readString = NULL; - if (HcsGetUint16(deviceNode, ATTR_DEV_POLICY, &readNum, 0) != HDF_SUCCESS) { - HDF_LOGE("%{public}s get policy failed", __func__); - return false; - } - deviceNodeInfo->policy = readNum; - - if (HcsGetUint16(deviceNode, ATTR_DEV_PRIORITY, &readNum, 0) != HDF_SUCCESS) { - HDF_LOGE("%{public}s get priority failed", __func__); - return false; - } - deviceNodeInfo->priority = readNum; - - if (HcsGetUint16(deviceNode, ATTR_DEV_PRELOAD, &readNum, 0) != HDF_SUCCESS) { - HDF_LOGE("%{public}s get preload failed", __func__); - return false; - } - deviceNodeInfo->preload = readNum; - - if (HcsGetString(deviceNode, ATTR_DEV_MODULENAME, &readString, NULL) != HDF_SUCCESS) { - HDF_LOGE("%{public}s get module name failed", __func__); - return false; - } - deviceNodeInfo->moduleName = strdup(readString); - if (deviceNodeInfo->moduleName == NULL) { - return false; - } - - if (HcsGetString(deviceNode, ATTR_DEV_SVCNAME, &readString, NULL) != HDF_SUCCESS) { - HDF_LOGE("%{public}s get service name failed", __func__); - return false; - } - deviceNodeInfo->svcName = strdup(readString); - if (deviceNodeInfo->svcName == NULL) { - return false; - } - - if (HcsGetString(deviceNode, ATTR_DEV_MATCHATTR, &readString, NULL) != HDF_SUCCESS) { - HDF_LOGE("%{public}s get service name failed", __func__); - return false; - } - deviceNodeInfo->deviceMatchAttr = readString; - return CheckDeviceInfo(deviceNodeInfo); -} - -struct HdfSList *HdfAttributeManagerGetDeviceList(uint16_t hostId, const char *hostName) -{ - uint16_t deviceIdx = 0; - if (hostName == NULL) { - return NULL; - } - if (strcmp(hostName, PNP_HOST_NAME) == 0) { - return DevmgrServiceGetPnpDeviceInfo(); - } - - const struct DeviceResourceNode *hostNode = GetHostNode(hostName); - if (hostNode == NULL) { - return NULL; - } - - struct HdfSList *deviceList = (struct HdfSList *)OsalMemCalloc(sizeof(struct HdfSList)); - if (deviceList == NULL) { - return NULL; - } - const struct DeviceResourceNode *device = hostNode->child; - while (device != NULL) { - const struct DeviceResourceNode *deviceNode = device->child; - while (deviceNode != NULL) { - uint8_t deviceNnodeIdx = 0; - struct HdfDeviceInfoFull *deviceNodeInfo = HdfDeviceInfoFullNewInstance(); - if (deviceNodeInfo == NULL) { - HdfSListFlush(deviceList, HdfDeviceInfoDelete); - OsalMemFree(deviceList); - return NULL; - } - deviceNodeInfo->super.hostId = hostId; - if (!GetDeviceNodeInfo(deviceNode, &deviceNodeInfo->super)) { - HdfDeviceInfoFullFreeInstance(deviceNodeInfo); - HDF_LOGE("%{public}s get device failed", __func__); - deviceNodeInfo = NULL; - deviceNode = deviceNode->sibling; - continue; - } - if (!HdfSListAddOrder(deviceList, &deviceNodeInfo->super.node, HdfDeviceListCompare)) { - HDF_LOGE("%{public}s add device %{public}s failed", __func__, deviceNodeInfo->super.svcName); - HdfDeviceInfoFullFreeInstance(deviceNodeInfo); - deviceNodeInfo = NULL; - deviceNode = deviceNode->sibling; - continue; - } - deviceNodeInfo->super.deviceId = MK_DEVID(hostId, deviceIdx, deviceNnodeIdx); - deviceNnodeIdx++; - deviceNode = deviceNode->sibling; - } - device = device->sibling; - deviceIdx++; - } - if (HdfSListCount(deviceList) == 0) { - OsalMemFree(deviceList); - return NULL; - } - return deviceList; -} - diff --git a/uhdf2/manager/src/usb_pnp_manager.c b/uhdf2/manager/src/usb_pnp_manager.c deleted file mode 100755 index 90171d3..0000000 --- a/uhdf2/manager/src/usb_pnp_manager.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device 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 "usb_pnp_manager.h" -#include "devhost_service_clnt.h" -#include "devmgr_pnp_service.h" -#include "hdf_base.h" -#include "hdf_log.h" -#include "osal_mem.h" -#include "osal_time.h" -#include "securec.h" -#include "usb_ddk_pnp_loader.h" - -#define HDF_LOG_TAG usb_pnp_manager - -#define WAIT_PNP_SLEEP_TIME 10 // ms -#define WAIT_PNP_SLEEP_CNT 100 - -static int32_t UsbPnpManageStartPnpHost(const struct IDevmgrService *devmgrSvc) -{ - int32_t ret; - int32_t i = 0; - struct DevmgrService *inst = (struct DevmgrService *)devmgrSvc; - if (inst == NULL) { - return HDF_ERR_INVALID_PARAM; - } - struct DevHostServiceClnt *hostClnt = DevmgrServiceGetPnpHostClnt(inst); - if (hostClnt == NULL) { - ret = DevmgrServiceStartPnpHost(inst); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s:%d add pnp device failed!", __func__, __LINE__); - return ret; - } - OsalMSleep(WAIT_PNP_SLEEP_TIME); - hostClnt = DevmgrServiceGetPnpHostClnt(inst); - } - - while (hostClnt == NULL || hostClnt->hostService == NULL) { - OsalMSleep(WAIT_PNP_SLEEP_TIME); - i++; - if (i > WAIT_PNP_SLEEP_CNT) { - HDF_LOGE("%s:%d!", __func__, __LINE__); - break; - } - } - - return HDF_SUCCESS; -} - -bool UsbPnpManagerWriteModuleName(struct HdfSBuf *sbuf, const char *moduleName) -{ - char modName[128] = {0}; - - if (sprintf_s(modName, sizeof(modName) - 1, "lib%s.z.so", moduleName) < 0) { - HDF_LOGE("%s: sprintf_s modName fail", __func__); - return false; - } - - return HdfSbufWriteString(sbuf, modName); -} - -int32_t UsbPnpManagerRegisterOrUnregisterDevice(struct UsbPnpManagerDeviceInfo managerInfo) -{ - int32_t ret; - - ret = UsbPnpManageStartPnpHost(managerInfo.devmgrSvc); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s:%d privateData is NULL!", __func__, __LINE__); - return ret; - } - - if (managerInfo.isReg) { - ret = DevmgrServiceRegPnpDevice(managerInfo.devmgrSvc, managerInfo.moduleName, managerInfo.serviceName, - managerInfo.deviceMatchAttr, (const void *)managerInfo.privateData); - } else { - ret = DevmgrServiceUnRegPnpDevice(managerInfo.devmgrSvc, managerInfo.moduleName, managerInfo.serviceName); - } - - return ret; -} - -int DevmgrUsbPnpManageEventHandle(struct IDevmgrService *inst) -{ - int status; - struct HdfIoService *usbPnpServ = HdfIoServiceBind(USB_PNP_NOTIFY_SERVICE_NAME); - static struct HdfDevEventlistener usbPnpListener = { - .callBack = UsbDdkPnpLoaderEventReceived, - }; - usbPnpListener.priv = (void *)(inst); - - if (usbPnpServ == NULL) { - HDF_LOGE("%s: HdfIoServiceBind faile.", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - status = HdfDeviceRegisterEventListener(usbPnpServ, &usbPnpListener); - if (status != HDF_SUCCESS) { - HDF_LOGE("HdfDeviceRegisterEventListener faile status=%d", status); - return status; - } - - return UsbDdkPnpLoaderEventHandle(); -} - -bool DevmgrUsbPnpManageAddPrivateData(struct HdfDeviceInfoFull *deviceInfo, const void *privateData) -{ - int ret; - - if (privateData != NULL) { - uint32_t length = ((struct HdfPrivateInfo *)(privateData))->length; - deviceInfo->super.private = (const void *)OsalMemCalloc(length); - if (deviceInfo->super.private != NULL) { - ret = memcpy_s((void *)(deviceInfo->super.private), length, privateData, length); - if ((ret != EOK) || (deviceInfo->super.private == NULL)) { - HDF_LOGE("%s: memcpy_s private error", __func__); - return false; - } - } else { - HDF_LOGE("%s: OsalMemCalloc private error", __func__); - return false; - } - } - - return true; -} diff --git a/uhdf2/shared/include/dev_attribute_parcel.h b/uhdf2/shared/include/dev_attribute_serialize.h similarity index 63% rename from uhdf2/shared/include/dev_attribute_parcel.h rename to uhdf2/shared/include/dev_attribute_serialize.h index cd0892c..e358cb9 100644 --- a/uhdf2/shared/include/dev_attribute_parcel.h +++ b/uhdf2/shared/include/dev_attribute_serialize.h @@ -13,13 +13,14 @@ * limitations under the License. */ -#ifndef HDF_ATTRIBUTE_PARCEL_H -#define HDF_ATTRIBUTE_PARCEL_H +#ifndef HDF_ATTRIBUTE_SERIALIZE_H +#define HDF_ATTRIBUTE_SERIALIZE_H -#include "hdf_device_info_full.h" +#include "hdf_device_info.h" #include "hdf_sbuf.h" -bool DeviceAttributeFullWrite(const struct HdfDeviceInfoFull *attribute, struct HdfSBuf *sbuf); -struct HdfDeviceInfoFull *DeviceAttributeFullRead(struct HdfSBuf *sbuf); +bool DeviceAttributeSerialize(const struct HdfDeviceInfo *attribute, struct HdfSBuf *sbuf); +struct HdfDeviceInfo *DeviceAttributeDeserialize(struct HdfSBuf *sbuf); +void DeviceSerializedAttributeRelease(struct HdfDeviceInfo *attribute); -#endif /* HDF_ATTRIBUTE_PARCEL_H */ \ No newline at end of file +#endif /* HDF_ATTRIBUTE_SERIALIZE_H */ \ No newline at end of file diff --git a/uhdf2/shared/include/hdf_device_info_full.h b/uhdf2/shared/include/hdf_device_info_full.h deleted file mode 100755 index e26be29..0000000 --- a/uhdf2/shared/include/hdf_device_info_full.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device 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 DEVICE_ATTRIBUTE_FULL_H -#define DEVICE_ATTRIBUTE_FULL_H - -#include "hdf_device_info.h" - -struct HdfDeviceInfoFull { - struct HdfDeviceInfo super; - void *deviceHandle; -}; - -struct HdfDeviceInfoFull *HdfDeviceInfoFullReinterpretCast(const struct HdfDeviceInfo *attribute); -struct HdfDeviceInfoFull *HdfDeviceInfoFullNewInstance(void); -void HdfDeviceInfoFullFreeInstance(struct HdfDeviceInfoFull *attribute); -void HdfDeviceInfoFullDelete(struct HdfSListNode *listEntry); - -#endif /* DEVICE_ATTRIBUTE_FULL_H */ diff --git a/uhdf2/shared/src/dev_attribute_parcel.c b/uhdf2/shared/src/dev_attribute_serialize.c old mode 100755 new mode 100644 similarity index 40% rename from uhdf2/shared/src/dev_attribute_parcel.c rename to uhdf2/shared/src/dev_attribute_serialize.c index be1a629..558e42a --- a/uhdf2/shared/src/dev_attribute_parcel.c +++ b/uhdf2/shared/src/dev_attribute_serialize.c @@ -13,100 +13,66 @@ * limitations under the License. */ -#include "dev_attribute_parcel.h" +#include "dev_attribute_serialize.h" #include "hdf_base.h" #include "hdf_log.h" #include "osal_mem.h" #include "securec.h" -#define HDF_LOG_TAG dev_attribute_parcel +#define HDF_LOG_TAG dev_attribute_serialze #define ATTRIBUTE_PRIVATE_DATA_LENGTH_NULL 0 #define ATTRIBUTE_PRIVATE_DATA_LENGTH_NORMAL 1 -bool DeviceAttributeReadPrivateData(struct HdfDeviceInfoFull *attribute, const void *privateData) +bool DeviceAttributeSerialize(const struct HdfDeviceInfo *attribute, struct HdfSBuf *sbuf) { - if (privateData != NULL) { - uint32_t length = ((struct HdfPrivateInfo *)(privateData))->length; - attribute->super.private = (const void *)OsalMemCalloc(length); - if (attribute->super.private != NULL) { - memcpy_s((void *)(attribute->super.private), length, privateData, length); - if (attribute->super.private == NULL) { - HDF_LOGE("%s: memcpy_s private error", __func__); - return false; - } - } else { - HDF_LOGE("%s: OsalMemCalloc private error", __func__); - return false; - } - } - - return true; -} - -bool DeviceAttributeFullWrite(const struct HdfDeviceInfoFull *attribute, struct HdfSBuf *sbuf) -{ - uint32_t length; - if (attribute == NULL || sbuf == NULL) { return false; } uint8_t ret = 1; - ret &= HdfSbufWriteInt32(sbuf, attribute->super.deviceId); - ret &= HdfSbufWriteInt32(sbuf, attribute->super.hostId); - ret &= HdfSbufWriteInt32(sbuf, attribute->super.policy); - ret &= HdfSbufWriteString(sbuf, attribute->super.svcName); - ret &= HdfSbufWriteString(sbuf, attribute->super.moduleName); - - if (attribute->super.deviceMatchAttr != NULL) { - length = ATTRIBUTE_PRIVATE_DATA_LENGTH_NORMAL; - ret &= HdfSbufWriteUint32(sbuf, length); - ret &= HdfSbufWriteString(sbuf, attribute->super.deviceMatchAttr); - } else { - length = ATTRIBUTE_PRIVATE_DATA_LENGTH_NULL; - ret &= HdfSbufWriteUint32(sbuf, length); - } - - if (attribute->super.private != NULL) { - length = ATTRIBUTE_PRIVATE_DATA_LENGTH_NORMAL; - ret &= HdfSbufWriteUint32(sbuf, length); - length = ((struct HdfPrivateInfo *)(attribute->super.private))->length; - ret &= HdfSbufWriteBuffer(sbuf, attribute->super.private, length); + ret &= HdfSbufWriteInt32(sbuf, attribute->deviceId); + ret &= HdfSbufWriteInt32(sbuf, attribute->hostId); + ret &= HdfSbufWriteInt32(sbuf, attribute->policy); + ret &= HdfSbufWriteString(sbuf, attribute->svcName); + ret &= HdfSbufWriteString(sbuf, attribute->moduleName); + + if (attribute->deviceMatchAttr != NULL) { + ret &= HdfSbufWriteUint32(sbuf, ATTRIBUTE_PRIVATE_DATA_LENGTH_NORMAL); + ret &= HdfSbufWriteString(sbuf, attribute->deviceMatchAttr); } else { - length = ATTRIBUTE_PRIVATE_DATA_LENGTH_NULL; - ret &= HdfSbufWriteUint32(sbuf, length); + ret &= HdfSbufWriteUint32(sbuf, ATTRIBUTE_PRIVATE_DATA_LENGTH_NULL); } if (ret == 0) { - HDF_LOGE("Device attribute write parcel failed"); + HDF_LOGE("failed to serialize device attribute"); return false; } return true; } -struct HdfDeviceInfoFull *DeviceAttributeFullRead(struct HdfSBuf *sbuf) +struct HdfDeviceInfo *DeviceAttributeDeserialize(struct HdfSBuf *sbuf) { if (sbuf == NULL) { return NULL; } - struct HdfDeviceInfoFull *attribute = HdfDeviceInfoFullNewInstance(); + struct HdfDeviceInfo *attribute = HdfDeviceInfoNewInstance(); if (attribute == NULL) { HDF_LOGE("OsalMemCalloc failed, attribute is null"); return NULL; } - HdfSbufReadUint16(sbuf, &attribute->super.deviceId); - HdfSbufReadUint16(sbuf, &attribute->super.hostId); - HdfSbufReadUint16(sbuf, &attribute->super.policy); + HdfSbufReadUint16(sbuf, &attribute->deviceId); + HdfSbufReadUint16(sbuf, &attribute->hostId); + HdfSbufReadUint16(sbuf, &attribute->policy); do { const char *svcName = HdfSbufReadString(sbuf); if (svcName == NULL) { HDF_LOGE("Read from parcel failed, svcName is null"); break; } - attribute->super.svcName = strdup(svcName); - if (attribute->super.svcName == NULL) { + attribute->svcName = strdup(svcName); + if (attribute->svcName == NULL) { HDF_LOGE("Read from parcel failed, strdup svcName fail"); break; } @@ -115,8 +81,8 @@ struct HdfDeviceInfoFull *DeviceAttributeFullRead(struct HdfSBuf *sbuf) HDF_LOGE("Read from parcel failed, driverPath is null"); break; } - attribute->super.moduleName = strdup(moduleName); - if (attribute->super.moduleName == NULL) { + attribute->moduleName = strdup(moduleName); + if (attribute->moduleName == NULL) { HDF_LOGE("Read from parcel failed, strdup moduleName fail"); break; } @@ -132,29 +98,29 @@ struct HdfDeviceInfoFull *DeviceAttributeFullRead(struct HdfSBuf *sbuf) HDF_LOGE("%s: Read from parcel failed, deviceMatchAttr is null", __func__); break; } - attribute->super.deviceMatchAttr = strdup(deviceMatchAttr); + attribute->deviceMatchAttr = strdup(deviceMatchAttr); } - - if (!HdfSbufReadUint32(sbuf, &length)) { - HDF_LOGE("Device attribute readPrivate length failed"); - break; - } - if (length == ATTRIBUTE_PRIVATE_DATA_LENGTH_NORMAL) { - uint32_t privateLength; - void *privateData = NULL; - if (!HdfSbufReadBuffer(sbuf, (const void **)(&privateData), &privateLength)) { - HDF_LOGW("%s: HdfSbufReadBuffer privateData error!", __func__); - privateData = NULL; - } - if (!DeviceAttributeReadPrivateData(attribute, privateData)) { - HDF_LOGE("%s: Read from parcel failed, private is null", __func__); - break; - } - } - return attribute; } while (0); - HdfDeviceInfoFullFreeInstance(attribute); + DeviceSerializedAttributeRelease(attribute); return NULL; } + +void DeviceSerializedAttributeRelease(struct HdfDeviceInfo *attribute) +{ + if (attribute == NULL) { + return; + } + + if (attribute->moduleName != NULL) { + OsalMemFree((void *)attribute->moduleName); + } + if (attribute->svcName != NULL) { + OsalMemFree((void *)attribute->svcName); + } + if (attribute->deviceMatchAttr != NULL) { + OsalMemFree((void *)attribute->deviceMatchAttr); + } + OsalMemFree(attribute); +} \ No newline at end of file diff --git a/uhdf2/shared/src/hdf_attribute_full.c b/uhdf2/shared/src/hcb_config_entry.c similarity index 77% rename from uhdf2/shared/src/hdf_attribute_full.c rename to uhdf2/shared/src/hcb_config_entry.c index 007bccb..dfe6545 100644 --- a/uhdf2/shared/src/hdf_attribute_full.c +++ b/uhdf2/shared/src/hcb_config_entry.c @@ -34,20 +34,12 @@ #define PRODUCT_PROPERTY "ro.build.product" #define PRODUCT_NAME_MAX 128 -static void StringLower(char *str, int strLen) -{ - for (int i = 0; i < strLen; ++i) { - str[i] = tolower(str[i]); - } -} - static int GetProductName(char *name, int maxLen) { - (void)StringLower; return strcpy_s(name, maxLen, "default"); } -const struct DeviceResourceNode *HdfGetRootNode(void) +const struct DeviceResourceNode *HdfGetHcsRootNode(void) { char productName[PRODUCT_NAME_MAX] = { 0 }; char configPath[PATH_MAX] = { 0 }; @@ -68,17 +60,3 @@ const struct DeviceResourceNode *HdfGetRootNode(void) const struct DeviceResourceNode *mgrRoot = HcsGetRootNode(); return mgrRoot; } - -bool HdfDeviceListAdd(const char *moduleName, const char *serviceName, const void *privateData) -{ - (void)moduleName; - (void)serviceName; - (void)privateData; - return true; -} - -void HdfDeviceListDel(const char *moduleName, const char *serviceName) -{ - (void)moduleName; - (void)serviceName; -} \ No newline at end of file diff --git a/uhdf2/shared/src/hdf_device_info_full.c b/uhdf2/shared/src/hdf_device_info_full.c deleted file mode 100644 index 60413f1..0000000 --- a/uhdf2/shared/src/hdf_device_info_full.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device 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_device_info_full.h" -#include -#include "osal_mem.h" - -struct HdfDeviceInfoFull *HdfDeviceInfoFullReinterpretCast(const struct HdfDeviceInfo *attribute) -{ - return (struct HdfDeviceInfoFull *)attribute; -} - -void HdfDeviceInfoFullConstruct(struct HdfDeviceInfoFull *attribute) -{ - HdfDeviceInfoConstruct(&attribute->super); - attribute->deviceHandle = NULL; -} - -struct HdfDeviceInfoFull* HdfDeviceInfoFullNewInstance(void) -{ - struct HdfDeviceInfoFull *fullAttribute = - (struct HdfDeviceInfoFull *)OsalMemCalloc(sizeof(struct HdfDeviceInfoFull)); - if (fullAttribute != NULL) { - HdfDeviceInfoFullConstruct(fullAttribute); - } - return fullAttribute; -} - -void HdfDeviceInfoFullFreeInstance(struct HdfDeviceInfoFull *attribute) -{ - if (attribute != NULL) { - if (attribute->super.moduleName != NULL) { - OsalMemFree((void *)attribute->super.moduleName); - } - if (attribute->super.svcName != NULL) { - OsalMemFree((void *)attribute->super.svcName); - } - if (attribute->super.deviceMatchAttr != NULL) { - OsalMemFree((void *)attribute->super.deviceMatchAttr); - } - if (attribute->super.private != NULL) { - OsalMemFree((void *)attribute->super.private); - } - OsalMemFree(attribute); - } -} - -void HdfDeviceInfoFullDelete(struct HdfSListNode *listEntry) -{ - struct HdfDeviceInfoFull *fullAttribute = (struct HdfDeviceInfoFull *)listEntry; - if (fullAttribute != NULL) { - HdfDeviceInfoFullFreeInstance(fullAttribute); - } -} - -- Gitee