diff --git a/.gitee/ISSUE_TEMPLATE.zh-CN.md b/.gitee/ISSUE_TEMPLATE.zh-CN.md
deleted file mode 100755
index f09d98dd..00000000
--- a/.gitee/ISSUE_TEMPLATE.zh-CN.md
+++ /dev/null
@@ -1,13 +0,0 @@
-### 该问题是怎么引起的?
-
-
-
-### 重现步骤
-
-
-
-### 报错信息
-
-
-
-
diff --git a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md
deleted file mode 100755
index 33948fdc..00000000
--- a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md
+++ /dev/null
@@ -1,15 +0,0 @@
-### 相关的Issue
-
-
-### 原因(目的、解决的问题等)
-
-
-### 描述(做了什么,变更了什么)
-
-
-### 测试用例(新增、改动、可能影响的功能)
-
-
-
-
-
diff --git a/LICENSE b/LICENSE
index 61fa69e3..f60fb811 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,28 +1,51 @@
-Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
-Copyright (c) 2020, 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.
\ No newline at end of file
+HDF - Hardware Driver Foundation
+Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+
+HDF is dual licensed: you can use it either under the terms of
+the GPL V2, or the BSD3 license, at your option.
+a) GNU General Public License version 2, (https://opensource.org/licenses/GPL-2.0)
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with this library; if not, write to the Free
+Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+MA 02110-1301 USA
+
+Alternatively,
+b) The BSD3 License, (https://opensource.org/licenses/BSD-3-Clause)
+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 OWNER 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.
diff --git a/README.md b/README.md
new file mode 100644
index 00000000..b18541f3
--- /dev/null
+++ b/README.md
@@ -0,0 +1,164 @@
+# HDF
+
+- [Introduction](#section11660541593)
+- [Directory Structure](#section161941989596)
+- [Usage](#section1312121216216)
+ - [HDF](#section129654513264)
+ - [Sensor](#section188637474417)
+ - [Display](#section161502341317)
+ - [Input](#section12629164020115)
+ - [WLAN](#section11408103183114)
+
+- [Repositories Involved](#section1371113476307)
+
+## Introduction
+
+This repository stores the core source code information of the OpenHarmony driver subsystem, including the driver framework, configuration management, configuration parsing, universal framework model, and unified hardware driver interfaces. It is designed to provide a more precise and efficient development environment, where you can perform one-time development for multi-system deployment.
+
+**Figure 1** Architecture of the HDF
+
+
+## Directory Structure
+
+```
+/drivers/framework
+├── ability # Capabilities for the driver development, such as the message model libraries
+│ ├── config # Parsing code of the configuration
+│ └── sbuf # Data serialization code
+├── core # Core code for implementing the HDF
+│ ├── adapter # Kernel adaptation layer
+│ ├── common # Common basic code
+│ ├── host # Driver host environment module
+│ ├── manager # Management module
+│ └── shared # Code shared by the host and manager modules
+├── include # Header files for the HDF to provide capabilities externally
+│ ├── config # Header files declaring capabilities for parsing configuration
+│ ├── core # Header files exposed externally
+│ ├── net # Header files related to network operations
+│ ├── osal # Header files of the OS adaptation layer
+│ ├── platform # Header files declaring platform APIs
+│ ├── utils # Header files declaring common capabilities
+│ └── wifi # Header files for the WLAN module to provide capabilities externally
+├── model # Universal framework module for drivers
+│ ├── display # Display framework module
+│ ├── input # Input framework module
+│ ├── network # WLAN framework module
+│ └── sensor # Sensor driver module
+├── support # Basic capabilities
+│ └── platform # Platform driver framework and APIs, including GPIO, I2C, and SPI
+├── tools # Source code related to the tools of the HDF
+│ └── hc-gen # Source code of the configuration management tool
+└── utils # Basic data structures and algorithms
+```
+
+## Usage
+
+### HDF
+
+To develop a driver based on the HDF, you only need to register and configure required APIs. The driver framework will load and initialize the driver based on the parsing content.
+
+Driver development based on the HDF consists of the following three parts:
+
+- Driver: Develop the functions.
+
+- Information configuration: Present the loading information of the driver.
+
+- Resource configuration: Configure the hardware information of the driver.
+
+You need to complete the logic code for the functions of a driver by the following APIs.
+
+The first part that catches your eyes is the driver entry, which is described through **DriverEntry**.
+
+Three APIs are available, namely **Bind**, **Init**, and **Release**.
+
+```
+struct HdfDriverEntry g_deviceSample = {
+ .moduleVersion = 1,
+ .moduleName = "sample_driver",
+ .Bind = SampleDriverBind,
+ .Init = SampleDriverInit,
+ .Release = SampleDriverRelease,
+};
+```
+
+**Bind**: This API is used to bind driver devices and its functions.
+
+```
+int32_t SampleDriverBind(struct HdfDeviceObject *deviceObject)
+{
+ // TODO: Bind device service to device object.
+ // And you can also initialize device resources here.
+ return HDF_SUCCESS;
+}
+```
+
+**Init**: When devices are successfully bound, the HDF calls **Init** to initialize the driver. After initialization is complete, the HDF will determine whether to create external service interfaces based on the configuration file. If the driver fails to be initialized, the driver framework will automatically release the created device interface.
+
+```
+int32_t SampleDriverInit(struct HdfDeviceObject *deviceObject)
+{
+ // TODO: Init hardware or other resources here.
+ return HDF_S UCCESS;
+}
+```
+
+**Release**: When you need to uninstall a driver, the HDF calls this function to release the driver resources. Then, other internal resources will be released.
+
+```
+void SampleDriverRelease(struct HdfDeviceObject *deviceObject)
+{
+ // Release all resources.
+ return;
+}
+```
+
+For details, see [HDF Overview](en-us_topic_0000001051611604.md).
+
+### Sensor
+
+The sensor driver module is developed based on the HDF and supports functions such as cross-OS migration and differentiated device configuration.
+
+- APIs for implementing sensor driver module capabilities: Implement the capabilities of registering, loading, and deregistering sensor drivers as well as detecting sensor device depending on the HDF, normalize APIs for sensor devices of the same type, and offer APIs for parsing register configurations, abstract APIs for bus access, and abstract platform APIs.
+- APIs to be implemented by developers: Based on the HDF Configuration Source \(HCS\), implement differentiated configuration for sensors of the same type and serialized configuration of sensor device parameters, and offer APIs for some sensor device operations to simplify the sensor driver development.
+
+For details, see [Sensor Driver Overview](en-us_topic_0000001078401780.md).
+
+### Display
+
+The display driver model that is developed based on the HDF shields the differences among chip platforms, achieving cross-platform migration of the OS. It also abstracts the common service logic of peripherals and configures differentiated adaptation APIs so that a driver model can be compatible with different peripheral. In this way, third-party vendors can efficiently access the OpenHarmony driver ecosystem.
+
+- APIs for implementing display driver module capabilities: Implement the Hardware Driver Interfaces \(HDIs\) and their adaptation with the chip platform. In addition, the kernel-mode driver abstracts the common services of the panel driver and provides capabilities of initializing the panel, obtaining the panel configuration, powering on/off the panel, and implementing the backlight control.
+- APIs to be implemented by developers: Complete the board-level HCS configuration and private data configuration of the panel, or offer differentiated APIs for some components to ensure efficient development of the display driver.
+
+For details, see [LCD Overview](en-us_topic_0000001052857284.md).
+
+### Input
+
+The input driver model is developed based on the HDF, provides unified driver APIs for upper-layer input services, and is decoupled from the chip platform. In addition, it abstracts several types of common platform drivers based on different input devices and is compatible with those input devices through configuration and differentiated peripheral APIs.
+
+- APIs for implementing input driver module capabilities: Implement the HDIs and provide capabilities of managing devices, controlling services, and reporting data. Besides, the input driver model provides a unified driver for different input devices and the capabilities of registering/unregistering an input device, reporting event data, parsing configuration, and loading a common driver.
+- APIs to be implemented by developers: Based on the provided platform driver, add the device descriptions as well as private configuration of the input device and implement differentiated APIs to greatly shorten the time required for developing input drivers.
+
+For details, see [Touchscreen Overview](en-us_topic_0000001052857350.md).
+
+### WLAN
+
+The WLAN module is developed based on the HDF and supports cross-OS migration, component adaptation, and modular assembly and compilation. Based on the unified APIs provided by the WLAN module, driver developers of WLAN vendors can adapt their driver code and developers of the HarmonyOS Driver Interfaces \(HDIs\) are capable of creating, disabling, scanning, and connecting to WLAN hotspots.
+
+- APIs for implementing WLAN driver module capabilities: Implement the APIs of the WLAN HDI layer and provide capabilities of setting/obtaining the MAC address, obtaining the feature type, and setting the transmit power for upper-layer input services, as well as the capabilities of creating/releasing a **WifiModule**, connecting to/disconnecting from a WLAN hotspot, and applying for/releasing a **NetBuf** for developers.
+- APIs to be implemented by developers: Based on the provided platform driver, complete the board-level HCS configuration as well as the differentiated WLAN configuration, and offer APIs for initializing, deregistering, enabling, and disabling a network device.
+
+For details, see [WLAN Overview](en-us_topic_0000001051643558.md).
+
+## Repositories Involved
+
+Driver subsystem
+
+hmf/drivers/framework
+
+hmf/drivers/adapter\_uhdf
+
+hmf/drivers/adapter\_khdf\_linux
+
+hmf/drivers/adapter\_khdf\_liteos
+
diff --git a/README_zh.md b/README_zh.md
new file mode 100644
index 00000000..901f5eca
--- /dev/null
+++ b/README_zh.md
@@ -0,0 +1,168 @@
+# Hdf Framework
+
+- [简介](#section11660541593)
+- [目录](#section161941989596)
+- [说明](#section1312121216216)
+ - [驱动框架使用说明](#section129654513264)
+ - [Sensor框架模型说明](#section188637474417)
+ - [Display框架模型说明](#section161502341317)
+ - [Input框架模型说明](#section12629164020115)
+ - [WLAN框架模型说明](#section11408103183114)
+
+- [相关仓](#section1371113476307)
+
+## 简介
+
+该仓主要存放OpenHarmony驱动子系统核心源码信息(包括驱动框架、配置管理、配置解析、驱动通用框架模型、硬件通用平台能力接口等),旨在为开发者提供更精准、更高效的开发环境,力求做到一次开发,多系统部署。
+
+**图 1** 驱动框架的架构图
+
+
+## 目录
+
+```
+/drivers/framework
+├── ability #提供驱动开发的能力支持,如消息模型库等
+│ ├── config #配置解析代码
+│ └── sbuf #数据序列化代码
+├── core #实现驱动框架的核心代码
+│ ├── adapter #实现对内核操作接口适配,提供抽象化的接口供开发者使用
+│ ├── common #驱动框架公共基础代码
+│ ├── host #驱动宿主环境模块
+│ ├── manager #驱动框架管理模块
+│ └── shared #host和manager共享模块代码
+├── include #驱动框架对外提供能力的头文件
+│ ├── config #提供配置解析能力的头文件
+│ ├── core #驱动框架对外提供的头文件
+│ ├── net #网络数据操作相关的头文件
+│ ├── osal #系统适配相关接口的头文件
+│ ├── platform #平台设备相关接口的头文件
+│ ├── utils #驱动框架公共能力的头文件
+│ └── wifi #WLAN对外提供能力的头文件
+├── model #提供驱动通用框架模型
+│ ├── display #显示框架模型
+│ ├── input #输入框架模型
+│ ├── network #WLAN框架模型
+│ └── sensor #Sensor驱动模型
+├── support #提系统的基础能力
+│ └── platform #平台设备驱动框架及访问接口,范围包括GPIO、I2C、SPI等
+├── tools #hdf框架工具相关的源码
+│ └── hc-gen #配置管理工具源码
+└── utils #提供基础数据结构和算法等
+```
+
+## 说明
+
+### 驱动框架使用说明
+
+基于HDF(驱动框架)开发驱动,用户只需注册自己所需的接口和配置,然后驱动框架就会解析配置的内容,完成驱动加载和初始化动作。
+
+开发者基于HDF驱动框架开发的驱动主要包含三大部分:
+
+1、驱动程序部分----完成驱动的功能逻辑。
+
+2、驱动配置信息----指示驱动的加载信息内容。
+
+3、驱动资源配置----配置驱动的硬件配置信息。
+
+驱动程序主要是完成驱动功能的逻辑代码:
+
+对于开发者首先看到的是驱动入口部分,驱动入口部分通过DriverEntry进行描述。
+
+其中主要包含Bind, Init 和Release三个接口。
+
+```
+struct HdfDriverEntry g_deviceSample = {
+ .moduleVersion = 1,
+ .moduleName = "sample_driver",
+ .Bind = SampleDriverBind,
+ .Init = SampleDriverInit,
+ .Release = SampleDriverRelease,
+};
+```
+
+Bind接口描述:该接口的作用主要是完成驱动设备和设备服务接口的bind动作。
+
+```
+int32_t SampleDriverBind(struct HdfDeviceObject *deviceObject)
+{
+ // TODO: Bind device service to device object.
+ // And you can also initialize device resources here.
+ return HDF_SUCCESS;
+}
+```
+
+Init接口描述:当框架完成设备绑定动作后,就开始调用驱动初始化接口,当初始化成功后,驱动框架根据配置文件决定是否对外创建设备服务接口,还是只是对当前服务接口可见。如果Init初始化失败的话,驱动框架就会主动释放创建的设备接口等信息。
+
+```
+int32_t SampleDriverInit(struct HdfDeviceObject *deviceObject)
+{
+ // TODO: Init hardware or other resources here.
+ return HDF_S UCCESS;
+}
+```
+
+Release接口描述:当用户需要卸载驱动时,驱动框架先通过该接口通知驱动程序释放资源。然后在执行其他内部资源释放。
+
+```
+void SampleDriverRelease(struct HdfDeviceObject *deviceObject)
+{
+ // Release all resources.
+ return;
+}
+```
+
+HDF驱动框架详细开发请参考[驱动开发指南](zh-cn_topic_0000001051611604.md)。
+
+### Sensor框架模型说明
+
+基于HDF(**H**ardware **D**river **F**oundation)驱动框架开发的Sensor驱动模型,实现跨操作系统迁移,器件差异配置等功能,具体包括下面两部分:
+
+- Sensor驱动模型基础能力部分:依赖HDF驱动框架实现Sensor器件驱动的注册,加载,去注册,器件探测等能力,提供同一类型Sensor器件驱动归一接口, 寄存器配置解析操作接口,总线访问抽象接口,平台抽象接口。
+- 开发者实现的部分:依赖HDF驱动框架的HCS\(**H**DF **C**onfiguration **S**ource\)配置管理,根据同类型Sensor差异化配置,实现Sensor器件参数序列化配置和器件部分操作接口,简化Sensor器件驱动开发。
+
+基于Sensor驱动模型开发Sensor器件驱动请参考[Sensor驱动开发指南](zh-cn_topic_0000001078401780.md)。
+
+### Display框架模型说明
+
+基于OpenHarmony驱动框架的Display驱动模型,对上屏蔽了芯片平台差异,方便操作系统跨平台迁移;向下抽象外设驱动公共业务逻辑,通过配置或差异化适配接口,实现一套驱动模型可兼容不同的外设器件,使得三方厂商可以高效、便捷的切入鸿蒙驱动生态。
+
+- Display驱动模型基础能力部分:包括HDI(**H**ardware **D**river **I**nterfaces)接口的定义及其实现框架,以及芯片平台对HDI接口的适配实现;内核驱动部分抽象了Panel驱动的公共业务,提供基础的Panel初始化、器件配置信息获取、上下电、背光设置等公共流程。
+- 驱动开发者实现的部分:需要完成板级的HCS配置及Panel私有数据配置,或者实现部分器件差异化接口,保证显示屏驱动开发高效便捷。
+
+基于Display驱动模型开发LCD器件驱动请参考[LCD驱动开发指南](zh-cn_topic_0000001052857284.md)。
+
+### Input框架模型说明
+
+基于OpenHarmony驱动框架的Input驱动模型,不依赖于芯片平台,对上层输入服务提供统一的驱动接口;在具体的驱动模型实现中,针对不同类别的输入设备,抽象出几类公共的平台驱动,通过配置及差异化的适配接口,使得驱动模型可兼容不同的输入设备。
+
+- Input驱动模型基础能力部分:包括Input HDI层的接口定义及公共实现,对上层输入服务提供设备管理、业务控制、数据上报等驱动能力接口;而Input驱动模型提供不同类型Input设备的归一化驱动, 包括输入设备的注册和注销、event数据的上报通道、配置信息的解析、公共驱动的加载等能力。
+- 开发者实现的部分:根据驱动模型提供的平台驱动,需要完成设备描述配置及器件私有配置,以及实现预留的器件差异化接口,借由此驱动模型,可大幅缩减Input设备驱动的开发周期。
+
+基于Input驱动模型开发Touchscreen器件驱动请参考[Touchscreen驱动开发指南](zh-cn_topic_0000001052857350.md)。
+
+### WLAN框架模型说明
+
+基于OpenHarmony驱动框架的WLAN驱动模型,可实现跨操作系统迁移,自适应器件差异,模块化拼装编译等功能。各WLAN厂商驱动开发人员可根据WLAN模块提供的向下统一接口适配各自的驱动代码,HDI层开发人员可根据WLAN模块提供的向上统一接口获取如下能力:建立/关闭WLAN热点、扫描、关联WLAN热点等。
+
+- WLAN驱动模型基础能力部分:包括WLAN HDI层的接口定义及公共实现,对上层输入服务提供如设置MAC地址,获取设备的MAC地址,获取特性的类型,设置发射功率等能力;对驱动开发者提供创建/释放WifiModule,关联/取消关联,申请/释放NetBuf等能力。
+- 驱动开发者实现的部分:根据驱动模型提供的平台驱动,需要完成板级的HCS配置及WLAN芯片的私有配置,以及实现预留的初始化/注销网络设备、打开/关闭网络设备等相关接口。
+
+基于WLAN驱动模型开发WLAN器件驱动请参考[WLAN驱动开发指南](zh-cn_topic_0000001051643558.md)。
+
+## 相关仓
+
+驱动子系统
+
+hmf/drivers/framework
+
+hmf/drivers/adapter\_uhdf
+
+hmf/drivers/adapter\_khdf\_linux
+
+hmf/drivers/adapter\_khdf\_liteos
+
+
+
+
diff --git a/ability/config/device_resource_if.c b/ability/config/device_resource_if.c
old mode 100755
new mode 100644
index 16863d67..6bea6afd
--- a/ability/config/device_resource_if.c
+++ b/ability/config/device_resource_if.c
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#include "device_resource_if.h"
diff --git a/ability/config/hcs_parser/include/hcs_blob_if.h b/ability/config/hcs_parser/include/hcs_blob_if.h
old mode 100755
new mode 100644
index c1f8547b..b50c8f35
--- a/ability/config/hcs_parser/include/hcs_blob_if.h
+++ b/ability/config/hcs_parser/include/hcs_blob_if.h
@@ -1,38 +1,14 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#ifndef HCS_BLOB_IF_H
#define HCS_BLOB_IF_H
-#include
#include "hdf_base.h"
#define CONFIG_NODE 0x1
diff --git a/ability/config/hcs_parser/include/hcs_generate_tree.h b/ability/config/hcs_parser/include/hcs_generate_tree.h
old mode 100755
new mode 100644
index 59bfc3d8..2aa2c63e
--- a/ability/config/hcs_parser/include/hcs_generate_tree.h
+++ b/ability/config/hcs_parser/include/hcs_generate_tree.h
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#ifndef HCS_GENERATE_TREE_H
diff --git a/ability/config/hcs_parser/include/hcs_parser.h b/ability/config/hcs_parser/include/hcs_parser.h
old mode 100755
new mode 100644
index a58c60bc..216eecc3
--- a/ability/config/hcs_parser/include/hcs_parser.h
+++ b/ability/config/hcs_parser/include/hcs_parser.h
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#ifndef HCS_PARSER_H
diff --git a/ability/config/hcs_parser/include/hcs_tree_if.h b/ability/config/hcs_parser/include/hcs_tree_if.h
old mode 100755
new mode 100644
index f4d9e096..b02bc332
--- a/ability/config/hcs_parser/include/hcs_tree_if.h
+++ b/ability/config/hcs_parser/include/hcs_tree_if.h
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#ifndef HCS_TREE_IF_H
diff --git a/ability/config/hcs_parser/src/hcs_blob_if.c b/ability/config/hcs_parser/src/hcs_blob_if.c
old mode 100755
new mode 100644
index 22db6fca..1f007c6f
--- a/ability/config/hcs_parser/src/hcs_blob_if.c
+++ b/ability/config/hcs_parser/src/hcs_blob_if.c
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#include "hcs_blob_if.h"
@@ -72,8 +49,12 @@ static int32_t HcsGetArrayLength(const char *start)
{
int32_t arrayLen = HCS_PREFIX_LENGTH + HCS_WORD_LENGTH;
uint16_t count;
- (void)HcsSwapToUint16(&count, start + HCS_PREFIX_LENGTH, CONFIG_WORD);
- for (uint16_t i = 0; i < count; i++) {
+ uint16_t i;
+ if (!HcsSwapToUint16(&count, start + HCS_PREFIX_LENGTH, CONFIG_WORD)) {
+ HDF_LOGE("%s failed", __func__);
+ return HDF_FAILURE;
+ }
+ for (i = 0; i < count; i++) {
int32_t lenData = HcsGetDataTypeOffset(start + arrayLen);
if (lenData < 0) {
return HDF_FAILURE;
@@ -189,7 +170,7 @@ bool HcsSwapToUint64(uint64_t *value, const char *realValue, uint32_t type)
return false;
}
-static bool CheckHcsBlobLength(const char *start, uint32_t length, struct HbcHeader *header)
+static bool CheckHcsBlobLength(uint32_t length, struct HbcHeader *header)
{
uint32_t rootNodeLen = HCS_STRING_LENGTH(HBC_ROOT_NAME) + HCS_PREFIX_LENGTH + HCS_DWORD_LENGTH;
uint32_t minLength = rootNodeLen + HBC_HEADER_LENGTH;
@@ -223,7 +204,7 @@ bool HcsCheckBlobFormat(const char *start, uint32_t length)
HDF_LOGE("%s failed, the magic of HBC is %x", __func__, header->magicNumber);
return false;
}
- if (!CheckHcsBlobLength(start, length, header)) {
+ if (!CheckHcsBlobLength(length, header)) {
return false;
}
return true;
diff --git a/ability/config/hcs_parser/src/hcs_generate_tree.c b/ability/config/hcs_parser/src/hcs_generate_tree.c
old mode 100755
new mode 100644
index 94083057..cd638683
--- a/ability/config/hcs_parser/src/hcs_generate_tree.c
+++ b/ability/config/hcs_parser/src/hcs_generate_tree.c
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#include "hcs_generate_tree.h"
diff --git a/ability/config/hcs_parser/src/hcs_parser.c b/ability/config/hcs_parser/src/hcs_parser.c
old mode 100755
new mode 100644
index 65cbe951..50ef7643
--- a/ability/config/hcs_parser/src/hcs_parser.c
+++ b/ability/config/hcs_parser/src/hcs_parser.c
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#include "hcs_parser.h"
diff --git a/ability/config/hcs_parser/src/hcs_tree_if.c b/ability/config/hcs_parser/src/hcs_tree_if.c
old mode 100755
new mode 100644
index dd0079f8..d4aba7c6
--- a/ability/config/hcs_parser/src/hcs_tree_if.c
+++ b/ability/config/hcs_parser/src/hcs_tree_if.c
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#include "hcs_tree_if.h"
@@ -51,13 +28,13 @@ static struct DeviceResourceAttr *GetAttrInNode(const struct DeviceResourceNode
bool HcsGetBool(const struct DeviceResourceNode *node, const char *attrName)
{
+ uint8_t value;
struct DeviceResourceAttr *attr = GetAttrInNode(node, attrName);
if ((attr == NULL) || (attr->value == NULL)) {
HDF_LOGE("%s failed, the node or attrName is NULL", __func__);
return false;
}
- uint8_t value;
if (!HcsSwapToUint8(&value, attr->value + HCS_PREFIX_LENGTH, HcsGetPrefix(attr->value))) {
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
return false;
@@ -132,6 +109,7 @@ static const char *GetArrayElem(const struct DeviceResourceAttr *attr, uint32_t
{
int32_t offset = HCS_WORD_LENGTH + HCS_PREFIX_LENGTH;
uint16_t count;
+ uint32_t i;
if ((HcsGetPrefix(attr->value) != CONFIG_ARRAY) ||
!HcsSwapToUint16(&count, attr->value + HCS_PREFIX_LENGTH, CONFIG_WORD)) {
HDF_LOGE("%s failed, the attr of %s is not array", __func__, attr->name);
@@ -141,7 +119,7 @@ static const char *GetArrayElem(const struct DeviceResourceAttr *attr, uint32_t
HDF_LOGE("%s failed, the index: %u >= count: %u", __func__, index, count);
return NULL;
}
- for (uint32_t i = 0; i < index; i++) {
+ for (i = 0; i < index; i++) {
int32_t result = HcsGetDataTypeOffset(attr->value + offset);
if (result < 0) {
return NULL;
@@ -245,13 +223,14 @@ int32_t HcsGetUint64ArrayElem(const struct DeviceResourceNode *node, const char
int32_t HcsGetUint8Array(const struct DeviceResourceNode *node, const char *attrName, uint8_t *value, uint32_t len,
uint8_t def)
{
+ int32_t ret = HDF_SUCCESS;
+ uint32_t i;
if ((value == NULL) || (len == 0)) {
HDF_LOGE("%s failed, parameter error, len: %u", __func__, len);
return HDF_FAILURE;
}
- int32_t ret = HDF_SUCCESS;
- for (uint32_t i = 0; i < len; i++) {
+ for (i = 0; i < len; i++) {
int32_t result = HcsGetUint8ArrayElem(node, attrName, i, value + i, def);
// If the error type is HDF_ERR_INVALID_OBJECT, the error is recorded and returned after the loop exits.
CONTINUE_RETURN_DIFFERENT_ERRNO(ret, result);
@@ -262,13 +241,14 @@ int32_t HcsGetUint8Array(const struct DeviceResourceNode *node, const char *attr
int32_t HcsGetUint16Array(const struct DeviceResourceNode *node, const char *attrName, uint16_t *value, uint32_t len,
uint16_t def)
{
+ int32_t ret = HDF_SUCCESS;
+ uint32_t i;
if ((value == NULL) || (len == 0)) {
HDF_LOGE("%s failed, parameter error, len: %u", __func__, len);
return HDF_FAILURE;
}
- int32_t ret = HDF_SUCCESS;
- for (uint32_t i = 0; i < len; i++) {
+ for (i = 0; i < len; i++) {
int32_t result = HcsGetUint16ArrayElem(node, attrName, i, value + i, def);
// If the error type is HDF_ERR_INVALID_OBJECT, the error is recorded and returned after the loop exits.
CONTINUE_RETURN_DIFFERENT_ERRNO(ret, result);
@@ -279,13 +259,14 @@ int32_t HcsGetUint16Array(const struct DeviceResourceNode *node, const char *att
int32_t HcsGetUint32Array(const struct DeviceResourceNode *node, const char *attrName, uint32_t *value, uint32_t len,
uint32_t def)
{
+ int32_t ret = HDF_SUCCESS;
+ uint32_t i;
if ((value == NULL) || (len == 0)) {
HDF_LOGE("%s failed, parameter error, len: %u", __func__, len);
return HDF_FAILURE;
}
- int32_t ret = HDF_SUCCESS;
- for (uint32_t i = 0; i < len; i++) {
+ for (i = 0; i < len; i++) {
int32_t result = HcsGetUint32ArrayElem(node, attrName, i, value + i, def);
// If the error type is HDF_ERR_INVALID_OBJECT, the error is recorded and returned after the loop exits.
CONTINUE_RETURN_DIFFERENT_ERRNO(ret, result);
@@ -296,12 +277,13 @@ int32_t HcsGetUint32Array(const struct DeviceResourceNode *node, const char *att
int32_t HcsGetUint64Array(const struct DeviceResourceNode *node, const char *attrName, uint64_t *value, uint32_t len,
uint64_t def)
{
+ uint32_t i;
if ((value == NULL) || (len == 0)) {
HDF_LOGE("%s failed, parameter error, len: %u", __func__, len);
return HDF_FAILURE;
}
- for (uint32_t i = 0; i < len; i++) {
+ for (i = 0; i < len; i++) {
int32_t result = HcsGetUint64ArrayElem(node, attrName, i, value + i, def);
if (result != HDF_SUCCESS) {
HDF_LOGE("%s failed, the ret is %d", __func__, result);
@@ -314,10 +296,11 @@ int32_t HcsGetUint64Array(const struct DeviceResourceNode *node, const char *att
int32_t HcsGetStringArrayElem(const struct DeviceResourceNode *node, const char *attrName, uint32_t index,
const char **value, const char *def)
{
+ const char *realValue = NULL;
struct DeviceResourceAttr *attr = GetAttrInNode(node, attrName);
RETURN_DEFAULT_VALUE(attr, attrName, value, def);
- const char *realValue = GetArrayElem(attr, index);
+ realValue = GetArrayElem(attr, index);
if ((realValue == NULL) || (HcsGetPrefix(realValue) != CONFIG_STRING)) {
*value = def;
HDF_LOGE("%s failed, %s attr is default value", __func__, attrName);
@@ -342,13 +325,13 @@ int32_t HcsGetString(const struct DeviceResourceNode *node, const char *attrName
int32_t HcsGetElemNum(const struct DeviceResourceNode *node, const char *attrName)
{
+ uint16_t num;
struct DeviceResourceAttr *attr = GetAttrInNode(node, attrName);
if ((attr == NULL) || (attr->value == NULL) || (HcsGetPrefix(attr->value) != CONFIG_ARRAY)) {
HDF_LOGE("%s failed, %s attr error", __func__, (attrName == NULL) ? "error attrName" : attrName);
return HDF_FAILURE;
}
- uint16_t num;
(void)HcsSwapToUint16(&num, attr->value + HCS_PREFIX_LENGTH, CONFIG_WORD);
return num;
}
@@ -380,12 +363,13 @@ static const struct DeviceResourceNode *TraverseTreeNode(const struct DeviceReso
const struct DeviceResourceNode *HcsGetNodeByMatchAttr(const struct DeviceResourceNode *node, const char *attrValue)
{
+ const struct DeviceResourceNode *curNode = NULL;
struct DeviceResourceIface *instance = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
if ((attrValue == NULL) || (instance == NULL) || (instance->GetRootNode == NULL)) {
HDF_LOGE("%s failed, attrValue is NULL or DeviceResourceGetIfaceInstance error", __func__);
return NULL;
}
- const struct DeviceResourceNode *curNode = (node != NULL) ? node : instance->GetRootNode();
+ curNode = (node != NULL) ? node : instance->GetRootNode();
while (curNode != NULL) {
if (GetAttrValueInNode(curNode, attrValue) != NULL) {
break;
@@ -397,12 +381,12 @@ const struct DeviceResourceNode *HcsGetNodeByMatchAttr(const struct DeviceResour
const struct DeviceResourceNode *HcsGetChildNode(const struct DeviceResourceNode *node, const char *nodeName)
{
+ struct DeviceResourceNode *child = NULL;
if ((node == NULL) || (nodeName == NULL)) {
HDF_LOGE("%s failed, the node or nodeName is NULL", __func__);
return NULL;
}
- struct DeviceResourceNode *child = NULL;
for (child = node->child; child != NULL; child = child->sibling) {
if ((child->name != NULL) && (strcmp(nodeName, child->name) == 0)) {
break;
@@ -413,20 +397,22 @@ const struct DeviceResourceNode *HcsGetChildNode(const struct DeviceResourceNode
const struct DeviceResourceNode *HcsGetNodeByRefAttr(const struct DeviceResourceNode *node, const char *attrName)
{
+ uint32_t attrValue;
+ struct DeviceResourceIface *instance = NULL;
+ const struct DeviceResourceNode *curNode = NULL;
struct DeviceResourceAttr *attr = GetAttrInNode(node, attrName);
if ((attr == NULL) || (attr->value == NULL) || (HcsGetPrefix(attr->value) != CONFIG_REFERENCE)) {
HDF_LOGE("%s failed, %s attr error", __func__, (attrName == NULL) ? "error attrName" : attrName);
return NULL;
}
- uint32_t attrValue;
(void)HcsSwapToUint32(&attrValue, attr->value + HCS_PREFIX_LENGTH, CONFIG_DWORD);
- struct DeviceResourceIface *instance = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
+ instance = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
if ((instance == NULL) || (instance->GetRootNode == NULL)) {
HDF_LOGE("%s failed, DeviceResourceGetIfaceInstance error", __func__);
return NULL;
}
- const struct DeviceResourceNode *curNode = instance->GetRootNode();
+ curNode = instance->GetRootNode();
while (curNode != NULL) {
if (curNode->hashValue == attrValue) {
break;
diff --git a/ability/config/test/unittest/common/hdf_config_test.cpp b/ability/config/test/unittest/common/hdf_config_test.cpp
new file mode 100644
index 00000000..2f4f9c32
--- /dev/null
+++ b/ability/config/test/unittest/common/hdf_config_test.cpp
@@ -0,0 +1,592 @@
+/*
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "hdf_uhdf_test.h"
+#include "hdf_io_service_if.h"
+
+using namespace testing::ext;
+
+namespace ConfigTest {
+const int8_t HDF_MSG_RESUL_DEFALUT = 3;
+
+// hcs config test case number
+enum HdfTestCaseCmd {
+ HDF_CREATE_DM_HSL_TO_TREE_001,
+ HDF_GET_NODE_BY_ATTR_VALUE_001,
+ HDF_GET_NODE_BY_ATTR_VALUE_002,
+ HDF_GET_BOOL_ATTR_VALUE_001,
+ HDF_GET_BOOL_ATTR_VALUE_002,
+ HDF_GET_UINT8_ATTR_VALUE_001,
+ HDF_GET_UINT8_ATTR_VALUE_002,
+ HDF_GET_UINT8_ARRAY_ELEM_ATTR_VALUE_001,
+ HDF_GET_UINT8_ARRAY_ELEM_ATTR_VALUE_002,
+ HDF_GET_UINT8_ARRAY_ATTR_VALUE_001,
+ HDF_GET_UINT8_ARRAY_ATTR_VALUE_002,
+ HDF_GET_UINT16_ATTR_VALUE_001,
+ HDF_GET_UINT16_ATTR_VALUE_002,
+ HDF_GET_UINT16_ARRAY_ELEM_ATTR_VALUE_001,
+ HDF_GET_UINT16_ARRAY_ELEM_ATTR_VALUE_002,
+ HDF_GET_UINT16_ARRAY_ATTR_VALUE_001,
+ HDF_GET_UINT16_ARRAY_ATTR_VALUE_002,
+ HDF_GET_UINT32_ATTR_VALUE_001,
+ HDF_GET_UINT32_ATTR_VALUE_002,
+ HDF_GET_UINT32_ARRAY_ELEM_ATTR_VALUE_001,
+ HDF_GET_UINT32_ARRAY_ELEM_ATTR_VALUE_002,
+ HDF_GET_UINT32_ARRAY_ATTR_VALUE_001,
+ HDF_GET_UINT32_ARRAY_ATTR_VALUE_002,
+ HDF_GET_UINT64_ATTR_VALUE_001,
+ HDF_GET_UINT64_ATTR_VALUE_002,
+ HDF_GET_UINT64_ARRAY_ELEM_ATTR_VALUE_001,
+ HDF_GET_UINT64_ARRAY_ELEM_ATTR_VALUE_002,
+ HDF_GET_UINT64_ARRAY_ATTR_VALUE_001,
+ HDF_GET_UINT64_ARRAY_ATTR_VALUE_002,
+ HDF_GET_ELEM_NUM_VALUE_001,
+ HDF_GET_ELEM_NUM_VALUE_002,
+ HDF_GET_CHILD_NODE_001,
+ HDF_GET_CHILD_NODE_002,
+ HDF_TRAVERSE_ATTR_IN_NODE_001,
+ HDF_TRAVERSE_ATTR_IN_NODE_002,
+ HDF_GET_STRING_ATTR_VALUE_001,
+ HDF_GET_STRING_ATTR_VALUE_002,
+ HDF_GET_STRING_ARRAY_ELEM_ATTR_VALUE_001,
+ HDF_GET_STRING_ARRAY_ELEM_ATTR_VALUE_002,
+ HDF_GET_NODE_BY_ATTR_REF_001,
+ HDF_GET_NODE_BY_ATTR_REF_002,
+};
+
+class HdfConfigTest : public testing::Test {
+public:
+ static void SetUpTestCase();
+ static void TearDownTestCase();
+ void SetUp();
+ void TearDown();
+};
+
+void HdfConfigTest::SetUpTestCase()
+{
+ HdfTestOpenService();
+}
+
+void HdfConfigTest::TearDownTestCase()
+{
+ HdfTestCloseService();
+}
+
+void HdfConfigTest::SetUp()
+{
+}
+
+void HdfConfigTest::TearDown()
+{
+}
+
+/**
+ * @tc.name: HslTestCreateDMHslToTree001
+ * @tc.desc: Create a config tree, enter config test
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestCreateDMHslToTree001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_CREATE_DM_HSL_TO_TREE_001, HDF_MSG_RESUL_DEFALUT};
+ printf("HdfConfigTest enter\n\r");
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetNodeByMatchAttrSuccess001
+ * @tc.desc: Obtains the root node of the configuration tree
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrSuccess001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetNodeByMatchAttrFail001
+ * @tc.desc: Failed to obtain the root node of the configuration tree
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrFail001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetBoolAttrValueSuccess001
+ * @tc.desc: Obtains the value of a BOOL attribute of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueSuccess001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_BOOL_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetBoolAttrValueFail001
+ * @tc.desc: Failed to obtain the value of a BOOL attribute of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueFail001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_BOOL_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetUint8AttrValueSuccess001
+ * @tc.desc: Obtains the value of a Uint8 attribute of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueSuccess001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetUint8AttrValueFail001
+ * @tc.desc: Failed to obtain the value of a Uint8 attribute of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueFail001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetUint8ArrayElemSuccess001
+ * @tc.desc: Obtains the value of a Unit8 array attribute numbered of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemSuccess001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetUint8ArrayElemFail001
+ * @tc.desc: Failed to obtain the value of a Unit8 array attribute numbered of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemFail001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetUint8ArraySuccess001
+ * @tc.desc: Obtains the values of a Uint8 array attribute of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetUint8ArraySuccess001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetUint8ArrayFail001
+ * @tc.desc: Failed to obtain the values of a Uint8 array attribute of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayFail001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetUint16AttrValueSuccess001
+ * @tc.desc: Obtains the value of a Uint16 attribute of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueSuccess001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetUint16AttrValueFail001
+ * @tc.desc: Failed to obtain the value of a Uint16 attribute of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueFail001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetUint16ArrayElemSuccess001
+ * @tc.desc: Obtains the value of a Uint16 array attribute numbered index of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemSuccess001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetUint16ArrayElemFail001
+ * @tc.desc: Failed to obtain the value of a Uint16 array attribute numbered index of a
+ * configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemFail001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetUint16ArraySuccess001
+ * @tc.desc: Obtains the values of a Uint16 array attribute of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetUint16ArraySuccess001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetUint16ArrayFail001
+ * @tc.desc: Failed to obtain the values of a Uint16 array attribute of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayFail001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetUint32AttrValueSuccess001
+ * @tc.desc: Obtains the value of a Uint32 attribute of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueSuccess001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetUint32AttrValueFail001
+ * @tc.desc: Failed to obtain the value of a Uint32 attribute of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueFail001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetUint32ArrayElemSuccess001
+ * @tc.desc: Obtains the value of a Uint32 array attribute numbered index of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemSuccess001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetUint32ArrayElemFail001
+ * @tc.desc: Failed to obtain the value of a Uint32 array attribute numbered index of a
+ * configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemFail001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetUint32ArraySuccess001
+ * @tc.desc: Obtains the values of a Uint32 array attribute of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetUint32ArraySuccess001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetUint32ArrayFail001
+ * @tc.desc: Failed to obtain the values of a Uint32 array attribute of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayFail001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetUint64AttrValueSuccess001
+ * @tc.desc: Obtains the value of a Uint64 attribute of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueSuccess001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetUint64AttrValueFail001
+ * @tc.desc: Failed to obtain the value of a Uint64 attribute of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueFail001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetUint64ArrayElemSuccess001
+ * @tc.desc: Obtains the value of a Uint64 array attribute numbered index of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemSuccess001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetUint64ArrayElemFail001
+ * @tc.desc: Failed to obtain the value of a Uint64 array attribute numbered index of a
+ * configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemFail001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetUint64ArraySuccess001
+ * @tc.desc: Obtains the values of a Uint64 array attribute of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetUint64ArraySuccess001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetUint64ArrayFail001
+ * @tc.desc: Failed to obtain the values of a Uint64 array attribute of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayFail001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetElemNumSuccess001
+ * @tc.desc: Obtains the number of values for an array attribute of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetElemNumSuccess001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_ELEM_NUM_VALUE_001, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetElemNumFail001
+ * @tc.desc: Failed to obtain the number of values for an array attribute of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetElemNumFail001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_ELEM_NUM_VALUE_002, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetChildNodeSuccess001
+ * @tc.desc: Obtains the child node with a specified node name from a parent node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetChildNodeSuccess001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_CHILD_NODE_001, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetChildNodeFail001
+ * @tc.desc: Failed to obtain the child node with a specified node name from a parent node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetChildNodeFail001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_CHILD_NODE_002, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestTraverseAttrInNodeSuccess001
+ * @tc.desc: Traverses the attributes of the current configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeSuccess001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_TRAVERSE_ATTR_IN_NODE_001, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestTraverseAttrInNodeFail001
+ * @tc.desc: Failed to traverse the attributes of the current configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeFail001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_TRAVERSE_ATTR_IN_NODE_002, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetStringSuccess001
+ * @tc.desc: Obtains the value of a String attribute of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetStringSuccess001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetStringFail001
+ * @tc.desc: Failed to obtain the value of a String attribute of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetStringFail001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetStringArrayElemSuccess001
+ * @tc.desc: Obtains the value of a String array attribute numbered index of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemSuccess001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetStringArrayElemFail001
+ * @tc.desc: Failed to obtain the value of a String array attribute numbered index of a
+ * configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemFail001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetNodeAttrRefSuccess001
+ * @tc.desc: Obtains the node that is specified by a node-type attribute of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetNodeAttrRefSuccess001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_REF_001, HDF_MSG_RESUL_DEFALUT};
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+
+/**
+ * @tc.name: HslTestGetNodeAttrRefFail001
+ * @tc.desc: Failed to obtain the node that is specified by a node-type attribute of a configuration tree node
+ * @tc.type: FUNC
+ * @tc.require: AR000DQ0TB
+ */
+HWTEST_F(HdfConfigTest, HslTestGetNodeAttrRefFail001, TestSize.Level0)
+{
+ struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_REF_002, HDF_MSG_RESUL_DEFALUT};
+ printf("HdfConfigTest last enter\n\r");
+ EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
+}
+};
diff --git a/ability/sbuf/include/hdf_sbuf.h b/ability/sbuf/include/hdf_sbuf.h
old mode 100755
new mode 100644
index 80a56909..6fd3bd6c
--- a/ability/sbuf/include/hdf_sbuf.h
+++ b/ability/sbuf/include/hdf_sbuf.h
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
/**
* @addtogroup Core
@@ -52,9 +29,7 @@
#ifndef HDF_SBUF_H
#define HDF_SBUF_H
-#include
-#include
-#include "hdf_cstring.h"
+#include "hdf_base.h"
#ifdef __cplusplus
extern "C" {
diff --git a/ability/sbuf/src/hdf_sbuf.c b/ability/sbuf/src/hdf_sbuf.c
old mode 100755
new mode 100644
index 0c2e1c50..57b4944a
--- a/ability/sbuf/src/hdf_sbuf.c
+++ b/ability/sbuf/src/hdf_sbuf.c
@@ -1,35 +1,12 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
-#include
+#include "securec.h"
#include "osal_mem.h"
#include "hdf_log.h"
#include "hdf_sbuf.h"
@@ -38,6 +15,14 @@
#define HDF_SBUF_MAX_SIZE (512 * 1024) // 512kB
#define HDF_SBUF_ALIGN 4
+#ifndef INT16_MAX
+#ifdef S16_MAX
+#define INT16_MAX S16_MAX
+#else
+#define INT16_MAX 32767
+#endif // !S16_MAX
+#endif // INT16_MAX
+
static inline size_t HdfSbufGetAlignSize(size_t size)
{
return (size + HDF_SBUF_ALIGN - 1) & (~(HDF_SBUF_ALIGN - 1));
@@ -125,12 +110,14 @@ static bool HdfSbufGrow(struct HdfSBuf *sbuf, uint32_t growSize)
return false;
}
- if (memcpy_s(newData, newSize, sbuf->data, sbuf->writePos) != EOK) {
- OsalMemFree(newData);
- return false;
+ if (sbuf->data != NULL) {
+ if (memcpy_s(newData, newSize, sbuf->data, sbuf->writePos) != EOK) {
+ OsalMemFree(newData);
+ return false;
+ }
+ OsalMemFree(sbuf->data);
}
- OsalMemFree(sbuf->data);
sbuf->data = newData;
sbuf->capacity = newSize;
@@ -139,7 +126,7 @@ static bool HdfSbufGrow(struct HdfSBuf *sbuf, uint32_t growSize)
static bool HdfSbufWrite(struct HdfSBuf *sbuf, const uint8_t *data, uint32_t size)
{
- if (sbuf == NULL || data == NULL) {
+ if (sbuf == NULL || sbuf->data == NULL || data == NULL) {
return false;
}
@@ -174,7 +161,7 @@ static bool HdfSbufWrite(struct HdfSBuf *sbuf, const uint8_t *data, uint32_t siz
static bool HdfSbufRead(struct HdfSBuf *sbuf, uint8_t *data, uint32_t readSize)
{
- if (sbuf == NULL || data == NULL) {
+ if (sbuf == NULL || sbuf->data == NULL || data == NULL) {
return false;
}
@@ -216,10 +203,9 @@ bool HdfSbufWriteBuffer(struct HdfSBuf *sbuf, const void *data, uint32_t writeSi
return true;
}
-/* return actual read size */
bool HdfSbufReadBuffer(struct HdfSBuf *sbuf, const void **data, uint32_t *readSize)
{
- if (sbuf == NULL || data == NULL || readSize == NULL) {
+ if (sbuf == NULL || sbuf->data == NULL || data == NULL || readSize == NULL) {
HDF_LOGE("%s:input invalid", __func__);
return false;
}
@@ -339,7 +325,7 @@ bool HdfSbufReadInt8(struct HdfSBuf *sbuf, int8_t *value)
const char *HdfSbufReadString(struct HdfSBuf *sbuf)
{
- if (sbuf == NULL) {
+ if (sbuf == NULL || sbuf->data == NULL) {
HDF_LOGE("%s:input null", __func__);
return NULL;
}
@@ -393,6 +379,9 @@ struct HdfSBuf *HdfSBufObtain(size_t capacity)
struct HdfSBuf *HdfSBufBind(uintptr_t base, size_t size)
{
+ if (base == 0 || size == 0) {
+ return NULL;
+ }
/* require 4 byte alignment for base */
if ((base & 0x3) != 0) {
HDF_LOGE("Base is not align for 4-byte");
@@ -435,7 +424,7 @@ struct HdfSBuf *HdfSBufCopy(const struct HdfSBuf *sbuf)
struct HdfSBuf *HdfSBufMove(struct HdfSBuf *sbuf)
{
- if (sbuf == NULL) {
+ if (sbuf == NULL || sbuf->isBind) {
return NULL;
}
@@ -463,6 +452,7 @@ void HdfSbufTransDataOwnership(struct HdfSBuf *sbuf)
sbuf->isBind = false;
}
+
void HdfSBufRecycle(struct HdfSBuf *sbuf)
{
if (sbuf != NULL) {
diff --git a/core/adapter/syscall/include/hdf_syscall_adapter.h b/core/adapter/syscall/include/hdf_syscall_adapter.h
new file mode 100644
index 00000000..60de08bd
--- /dev/null
+++ b/core/adapter/syscall/include/hdf_syscall_adapter.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#ifndef HDF_SYSCALL_ADAPTER_H
+#define HDF_SYSCALL_ADAPTER_H
+
+#include
+#include
+#include
+#include
+#include
+#include "hdf_io_service.h"
+
+struct HdfSyscallAdapter;
+
+enum HdfDevListenerThreadStatus {
+ LISTENER_UNINITED = 0,
+ LISTENER_INITED,
+ LISTENER_EXITED,
+ LISTENER_RUNNING,
+ LISTENER_WAITING,
+};
+
+struct HdfDevListenerThread {
+ struct OsalMutex mutex;
+ struct OsalThread thread;
+ struct DListHead *adapterListPtr;
+ struct HdfSyscallAdapter *adapter;
+ struct pollfd *pfds;
+ uint16_t pfdSize;
+ bool pollChanged;
+ struct DListHead *listenerListPtr;
+ bool shouldStop;
+ uint8_t status;
+};
+
+struct HdfSyscallAdapter {
+ struct HdfIoService super;
+ struct OsalMutex mutex;
+ struct DListHead listenerList;
+ int fd;
+ struct DListHead listNode;
+ struct HdfDevListenerThread *thread;
+ struct HdfSyscallAdapterGroup *group;
+};
+
+struct HdfSyscallAdapterGroup {
+ struct HdfIoServiceGroup serviceGroup;
+ struct OsalMutex mutex;
+ struct DListHead adapterList;
+ struct HdfDevListenerThread *thread;
+ struct DListHead listenerList;
+};
+
+#endif /* HDF_SYSCALL_ADAPTER_H */
diff --git a/core/adapter/syscall/src/hdf_devmgr_adapter.c b/core/adapter/syscall/src/hdf_devmgr_adapter.c
new file mode 100644
index 00000000..1d9b37cf
--- /dev/null
+++ b/core/adapter/syscall/src/hdf_devmgr_adapter.c
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include "hdf_base.h"
+#include "hdf_io_service.h"
+#include "hdf_log.h"
+#include "hdf_sbuf.h"
+
+int32_t HdfLoadDriverByServiceName(const char *serviceName)
+{
+ int32_t ret = HDF_FAILURE;
+ struct HdfSBuf *data = NULL;
+ if (serviceName == NULL || strcmp(serviceName, DEV_MGR_NODE) == 0) {
+ return ret;
+ }
+ struct HdfIoService *ioService = HdfIoServiceBind(DEV_MGR_NODE);
+ if (ioService == NULL) {
+ HDF_LOGE("Fail to get %s service", DEV_MGR_NODE);
+ return ret;
+ }
+ data = HdfSBufObtainDefaultSize();
+ if (data == NULL) {
+ HDF_LOGE("fail to obtain sbuf data");
+ ret = HDF_DEV_ERR_NO_MEMORY;
+ goto out;
+ }
+ if (!HdfSbufWriteString(data, serviceName)) {
+ HDF_LOGE("fail to write sbuf");
+ ret = HDF_FAILURE;
+ goto out;
+ }
+ ret = ioService->dispatcher->Dispatch(&ioService->object, DEVMGR_LOAD_SERVICE, data, NULL);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("fail to send service call");
+ }
+out:
+ HdfIoServiceRecycle(ioService);
+ HdfSBufRecycle(data);
+ return ret;
+}
+
+int32_t HdfGetServiceNameByDeviceClass(DeviceClass deviceClass, struct HdfSBuf *reply)
+{
+ int32_t ret = HDF_FAILURE;
+ struct HdfSBuf *data = NULL;
+ if (reply == NULL) {
+ HDF_LOGE("%s input reply is null", __func__);
+ return ret;
+ }
+ struct HdfIoService *ioService = HdfIoServiceBind(DEV_MGR_NODE);
+ if (ioService == NULL) {
+ HDF_LOGE("Fail to get %s service", DEV_MGR_NODE);
+ return ret;
+ }
+ data = HdfSBufObtainDefaultSize();
+ if (data == NULL) {
+ HDF_LOGE("fail to obtain sbuf data");
+ ret = HDF_DEV_ERR_NO_MEMORY;
+ goto out;
+ }
+ if (!HdfSbufWriteInt32(data, deviceClass)) {
+ HDF_LOGE("fail to write sbuf");
+ ret = HDF_FAILURE;
+ goto out;
+ }
+ ret = ioService->dispatcher->Dispatch(&ioService->object, DEVMGR_GET_SERVICE, data, reply);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("fail to send service call");
+ }
+out:
+ HdfIoServiceRecycle(ioService);
+ HdfSBufRecycle(data);
+ return ret;
+}
+
diff --git a/core/adapter/syscall/src/hdf_syscall_adapter.c b/core/adapter/syscall/src/hdf_syscall_adapter.c
new file mode 100644
index 00000000..cefcaa3e
--- /dev/null
+++ b/core/adapter/syscall/src/hdf_syscall_adapter.c
@@ -0,0 +1,1102 @@
+/*
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include "hdf_syscall_adapter.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "hdf_base.h"
+#include "hdf_log.h"
+#include "hdf_sbuf.h"
+#include "osal_mem.h"
+
+#define HDF_LOG_TAG hdf_syscall_adapter
+#define EPOLL_MAX_EVENT_SIZE 4
+#define HDF_DEFAULT_BWR_READ_SIZE 1024
+#define EVENT_READ_BUFF_GROWTH_RATE 2
+#define EVENT_READ_BUFF_MAX (20 * 1024) // 20k
+#define SYSCALL_INVALID_FD (-1)
+#define HDF_PFD_GROW_SIZE 4
+
+static bool HaveOnlyOneElement(const struct DListHead *head)
+{
+ if (head->next != head && head->next->next == head) {
+ return true;
+ }
+
+ return false;
+}
+
+static int32_t HdfDevEventGrowReadBuffer(struct HdfWriteReadBuf *buffer)
+{
+ size_t newSize = buffer->readSize;
+
+ if (newSize > EVENT_READ_BUFF_MAX) {
+ HDF_LOGE("%s: report event size out of max limit", __func__);
+ return HDF_DEV_ERR_NORANGE;
+ }
+
+ void *newBuff = OsalMemAlloc(newSize);
+ if (newBuff == NULL) {
+ HDF_LOGE("%s:oom,%d", __func__, (int)newSize);
+ return HDF_DEV_ERR_NO_MEMORY;
+ }
+
+ OsalMemFree((void*)buffer->readBuffer);
+ buffer->readBuffer = (uintptr_t)newBuff;
+ return HDF_SUCCESS;
+}
+
+static struct HdfSyscallAdapter *HdfFdToAdapterLocked(const struct HdfDevListenerThread *thread, int32_t fd)
+{
+ if (thread->adapter != NULL && thread->adapter->fd == fd) {
+ return thread->adapter;
+ }
+
+ if (thread->adapterListPtr == NULL) {
+ return NULL;
+ }
+
+ struct HdfSyscallAdapter *adapter = NULL;
+ DLIST_FOR_EACH_ENTRY(adapter, thread->adapterListPtr, struct HdfSyscallAdapter, listNode) {
+ if (adapter->fd == fd) {
+ return adapter;
+ }
+ }
+
+ return NULL;
+}
+
+static int32_t HdfDevEventDispatchLocked(const struct HdfDevListenerThread *thread, struct HdfSyscallAdapter *adapter,
+ const struct HdfWriteReadBuf *bwr)
+{
+ struct HdfDevEventlistener *listener = NULL;
+ struct HdfSBuf *sbuf = NULL;
+
+ if (bwr->readConsumed > 0) {
+ sbuf = HdfSBufBind(bwr->readBuffer, bwr->readConsumed);
+ } else {
+ sbuf = HdfSBufObtain(sizeof(int));
+ }
+
+ if (sbuf == NULL) {
+ HDF_LOGE("%s:sbuf oom", __func__);
+ return HDF_DEV_ERR_NO_MEMORY;
+ }
+
+ /* dispatch event to SERVICE GROUP listener */
+ if (thread->listenerListPtr != NULL) {
+ DLIST_FOR_EACH_ENTRY(listener, thread->listenerListPtr, struct HdfDevEventlistener, listNode) {
+ if (listener->onReceive != NULL) {
+ (void)listener->onReceive(listener, &adapter->super, bwr->cmdCode, sbuf);
+ } else if (listener->callBack != NULL) {
+ (void)listener->callBack(listener->priv, bwr->cmdCode, sbuf);
+ }
+ HdfSbufFlush(sbuf);
+ sbuf->writePos = bwr->readConsumed;
+ }
+ }
+
+ OsalMutexLock(&adapter->mutex);
+ /* dispatch event to SERVICE(SyscallAdapter) listener */
+ DLIST_FOR_EACH_ENTRY(listener, &adapter->listenerList, struct HdfDevEventlistener, listNode) {
+ if (listener->onReceive != NULL) {
+ (void)listener->onReceive(listener, &adapter->super, bwr->cmdCode, sbuf);
+ } else if (listener->callBack != NULL) {
+ (void)listener->callBack(listener->priv, bwr->cmdCode, sbuf);
+ }
+ HdfSbufFlush(sbuf);
+ sbuf->writePos = bwr->readConsumed;
+ }
+ OsalMutexUnlock(&adapter->mutex);
+
+ HdfSBufRecycle(sbuf);
+ return HDF_SUCCESS;
+}
+
+static int32_t HdfDevEventReadAndDispatch(struct HdfDevListenerThread *thread, int32_t fd)
+{
+ struct HdfWriteReadBuf bwr = { 0 };
+ int32_t ret = HDF_SUCCESS;
+
+ bwr.readBuffer = (uintptr_t)OsalMemAlloc(HDF_DEFAULT_BWR_READ_SIZE);
+ bwr.cmdCode = -1;
+ bwr.readConsumed = 0;
+ bwr.readSize = HDF_DEFAULT_BWR_READ_SIZE;
+ if (bwr.readBuffer == (uintptr_t)NULL) {
+ HDF_LOGE("%s: oom", __func__);
+ return HDF_DEV_ERR_NO_MEMORY;
+ }
+
+ OsalMutexLock(&thread->mutex);
+
+ struct HdfSyscallAdapter *adapter = HdfFdToAdapterLocked(thread, fd);
+ if (adapter == NULL) {
+ HDF_LOGI("%s:adapter invalid\n", __func__);
+ OsalMSleep(1);
+ goto finish;
+ }
+
+ while (true) {
+ ret = ioctl(adapter->fd, HDF_READ_DEV_EVENT, &bwr);
+ if (ret == 0) {
+ break;
+ }
+ ret = errno;
+ if (ret == -HDF_DEV_ERR_NORANGE) {
+ if (HdfDevEventGrowReadBuffer(&bwr) == HDF_SUCCESS) {
+ continue; /* read buffer may not enough, grow read buffer and try again */
+ }
+ }
+ if (ret == -HDF_DEV_ERR_NODATA) {
+ ret = HDF_SUCCESS;
+ } else {
+ HDF_LOGE("%s:ioctl failed, errno=%d\n", __func__, ret);
+ }
+
+ goto finish;
+ }
+
+ ret = HdfDevEventDispatchLocked(thread, adapter, &bwr);
+
+finish:
+ OsalMemFree((void*)bwr.readBuffer);
+ OsalMutexUnlock(&thread->mutex);
+ return ret;
+}
+
+static int32_t AssignPfds(struct HdfDevListenerThread *thread, struct pollfd **pfds, uint16_t *pfdSize)
+{
+ struct pollfd *pfdPtr = *pfds;
+ uint16_t pfdCount = 0;
+
+ OsalMutexLock(&thread->mutex);
+ if (*pfdSize < thread->pfdSize) {
+ pfdPtr = OsalMemAlloc(sizeof(struct pollfd) * thread->pfdSize);
+ if (pfdPtr == NULL) {
+ HDF_LOGE("%s: oom", __func__);
+ OsalMutexUnlock(&thread->mutex);
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ *pfdSize = thread->pfdSize;
+ OsalMemFree(*pfds);
+ *pfds = pfdPtr;
+ }
+
+ for (uint32_t i = 0; i < thread->pfdSize; i++) {
+ if (thread->pfds[i].fd != SYSCALL_INVALID_FD) {
+ pfdPtr[pfdCount].fd = thread->pfds[i].fd;
+ pfdPtr[pfdCount].events = thread->pfds[i].events;
+ pfdPtr[pfdCount].revents = 0;
+ pfdCount++;
+ }
+ }
+
+ thread->pollChanged = false;
+ OsalMutexUnlock(&thread->mutex);
+ return pfdCount;
+}
+
+#define POLL_WAIT_TIME_MS 100
+static int32_t HdfDevEventListenTask(void *para)
+{
+ struct HdfDevListenerThread *thread = (struct HdfDevListenerThread *)para;
+ struct pollfd *pfds = NULL;
+ uint16_t pfdSize = 0;
+ int32_t pollCount = 0;
+
+ while (!thread->shouldStop) {
+ if (thread->pollChanged) {
+ pollCount = AssignPfds(thread, &pfds, &pfdSize);
+ }
+ if (pollCount <= 0) {
+ goto exit;
+ }
+ int32_t pollSize = poll(pfds, pollCount, -1);
+ if (pollSize <= 0) {
+ HDF_LOGE("%s: poll fail (%d)%s", __func__, errno, strerror(errno));
+ OsalMSleep(POLL_WAIT_TIME_MS);
+ continue;
+ }
+ for (uint32_t i = 0; i < (uint32_t)pollCount; i++) {
+ if (pfds[i].fd == SYSCALL_INVALID_FD) {
+ continue;
+ }
+ if ((((uint32_t)pfds[i].revents) & POLLIN) &&
+ HdfDevEventReadAndDispatch(thread, pfds[i].fd) != HDF_SUCCESS) {
+ goto exit;
+ } else if (((uint32_t)pfds[i].revents) & POLLHUP) {
+ HDF_LOGI("event listener task received exit event");
+ thread->shouldStop = true;
+ goto exit;
+ } else if (((uint32_t)pfds[i].revents) & POLLNVAL) {
+ OsalMSleep(1); // polled closed fd, yield to sync
+ }
+ }
+ }
+
+exit:
+ HDF_LOGI("event listener task exit");
+
+ thread->status = LISTENER_EXITED;
+ OsalMemFree(pfds);
+
+ if (thread->shouldStop) {
+ /* exit due to async exit call, should free thread struct */
+ OsalMutexDestroy(&thread->mutex);
+ OsalThreadDestroy(&thread->thread);
+ OsalMemFree(thread->pfds);
+ OsalMemFree(thread);
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t HdfAdapterStartListenIoctl(int fd)
+{
+ int32_t ret = ioctl(fd, HDF_LISTEN_EVENT_START, 0);
+ if (ret) {
+ HDF_LOGE("%s: fail to tell drv(%d) start %d %s", __func__, fd, errno, strerror(errno));
+ return HDF_ERR_IO;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t HdfAdapterStopListenIoctl(int fd)
+{
+ int32_t ret = ioctl(fd, HDF_LISTEN_EVENT_STOP, 0);
+ if (ret) {
+ HDF_LOGE("%s: fail to tell drv stop %d %s", __func__, errno, strerror(errno));
+ return HDF_ERR_IO;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t HdfAdapterExitListenIoctl(int fd)
+{
+ int32_t ret = ioctl(fd, HDF_LISTEN_EVENT_EXIT, 0);
+ if (ret) {
+ HDF_LOGE("%s: fail to tell drv report exit %d %s", __func__, errno, strerror(errno));
+ return HDF_ERR_IO;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t HdfDevListenerThreadDoInit(struct HdfDevListenerThread *thread)
+{
+ if (OsalMutexInit(&thread->mutex) != HDF_SUCCESS) {
+ HDF_LOGE("%s: fail to create thread lock", __func__);
+ return HDF_FAILURE;
+ }
+
+ int32_t ret = OsalThreadCreate(&thread->thread, HdfDevEventListenTask, thread);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s: fail to create thread", __func__);
+ thread->status = LISTENER_UNINITED;
+ OsalMutexDestroy(&thread->mutex);
+ return HDF_ERR_THREAD_CREATE_FAIL;
+ }
+
+ thread->status = LISTENER_INITED;
+ thread->shouldStop = false;
+ thread->pollChanged = true;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t HdfDevListenerThreadInit(struct HdfDevListenerThread *thread)
+{
+ switch (thread->status) {
+ case LISTENER_RUNNING: // fall-through
+ case LISTENER_INITED: // fall-through
+ case LISTENER_WAITING:
+ return HDF_SUCCESS;
+ case LISTENER_EXITED:
+ thread->status = LISTENER_INITED;
+ thread->shouldStop = false;
+ return HDF_SUCCESS;
+ case LISTENER_UNINITED:
+ return HdfDevListenerThreadDoInit(thread);
+ default:
+ break;
+ }
+
+ return HDF_FAILURE;
+}
+
+static int32_t GetValidPfdIndexLocked(struct HdfDevListenerThread *thread, struct HdfSyscallAdapter *adapter)
+{
+ uint32_t index = 0;
+ struct pollfd *pfds = thread->pfds;
+ for (; index < thread->pfdSize; index++) {
+ if (pfds[index].fd == SYSCALL_INVALID_FD) {
+ break;
+ }
+
+ if (pfds[index].fd == adapter->fd) {
+ return index;
+ }
+ }
+
+ if (index >= thread->pfdSize) {
+ uint32_t newSize = thread->pfdSize + HDF_PFD_GROW_SIZE;
+ struct pollfd *newPfds = OsalMemCalloc(sizeof(struct pollfd) * newSize);
+ if (newPfds == NULL) {
+ return HDF_ERR_MALLOC_FAIL;
+ }
+ if (thread->pfdSize != 0) {
+ (void)memcpy_s(newPfds, sizeof(struct pollfd) * newSize,
+ thread->pfds, sizeof(struct pollfd) * thread->pfdSize);
+ }
+
+ for (uint32_t i = index; i < newSize; i++) {
+ newPfds[i].fd = SYSCALL_INVALID_FD;
+ }
+
+ OsalMemFree(thread->pfds);
+ thread->pfds = newPfds;
+ thread->pfdSize = newSize;
+ }
+
+ return index;
+}
+
+static int32_t HdfAddAdapterToPfds(struct HdfDevListenerThread *thread, struct HdfSyscallAdapter *adapter)
+{
+ int32_t index = GetValidPfdIndexLocked(thread, adapter);
+ if (index < 0) {
+ return HDF_ERR_MALLOC_FAIL;
+ }
+
+ thread->pfds[index].fd = adapter->fd;
+ thread->pfds[index].events = POLLIN;
+ thread->pfds[index].revents = 0;
+
+ return HDF_SUCCESS;
+}
+
+static int32_t HdfListenThreadInitPollFds(struct HdfDevListenerThread *thread)
+{
+ struct HdfSyscallAdapter *adapter = NULL;
+ if (thread->adapterListPtr != NULL) {
+ DLIST_FOR_EACH_ENTRY(adapter, thread->adapterListPtr, struct HdfSyscallAdapter, listNode) {
+ if (HdfAddAdapterToPfds(thread, adapter) != HDF_SUCCESS) {
+ return HDF_ERR_MALLOC_FAIL;
+ }
+ }
+ }
+
+ if (thread->adapter != NULL) {
+ return HdfAddAdapterToPfds(thread, thread->adapter);
+ }
+
+ return HDF_SUCCESS;
+}
+
+static int32_t HdfDevListenerThreadStart(struct HdfDevListenerThread *thread)
+{
+ if (thread->status == LISTENER_RUNNING) {
+ return HDF_SUCCESS;
+ }
+
+ if (thread->status != LISTENER_INITED) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ int32_t ret = HdfListenThreadInitPollFds(thread);
+ if (ret != HDF_SUCCESS || thread->pfdSize <= 0) {
+ HDF_LOGE("%s:invalid poll list", __func__);
+ return HDF_DEV_ERR_NO_DEVICE;
+ }
+
+ do {
+ for (int i = 0; i < thread->pfdSize; i++) {
+ if (thread->pfds[i].fd == SYSCALL_INVALID_FD) {
+ continue;
+ }
+ if (HdfAdapterStartListenIoctl(thread->pfds[i].fd)) {
+ return HDF_ERR_IO;
+ }
+ }
+
+ struct OsalThreadParam config = {
+ .name = "hdf_event_listener",
+ .priority = OSAL_THREAD_PRI_DEFAULT,
+ .stackSize = 0,
+ };
+
+ if (OsalThreadStart(&thread->thread, &config) != HDF_SUCCESS) {
+ HDF_LOGE("%s:OsalThreadStart failed", __func__);
+ ret = HDF_FAILURE;
+ break;
+ }
+ thread->status = LISTENER_RUNNING;
+ return HDF_SUCCESS;
+ } while (0);
+
+ return ret;
+}
+
+static struct HdfDevListenerThread *HdfDevListenerThreadObtain(void)
+{
+ struct HdfDevListenerThread *thread = OsalMemCalloc(sizeof(struct HdfDevListenerThread));
+ if (thread == NULL) {
+ return NULL;
+ }
+ thread->status = LISTENER_UNINITED;
+ if (HdfDevListenerThreadInit(thread) != HDF_SUCCESS) {
+ OsalMemFree(thread);
+ return NULL;
+ }
+ return thread;
+}
+
+static int32_t HdfIoServiceGroupThreadInit(struct HdfSyscallAdapterGroup *group)
+{
+ if (group->thread == NULL) {
+ struct HdfDevListenerThread *listenerThread = HdfDevListenerThreadObtain();
+ if (listenerThread == NULL) {
+ return HDF_ERR_THREAD_CREATE_FAIL;
+ }
+ group->thread = listenerThread;
+ }
+ group->thread->adapterListPtr = &group->adapterList;
+ group->thread->listenerListPtr = &group->listenerList;
+ return HdfDevListenerThreadInit(group->thread);
+}
+
+static int32_t HdfIoServiceGroupThreadStart(struct HdfSyscallAdapterGroup *group)
+{
+ OsalMutexLock(&group->mutex);
+ if (HdfIoServiceGroupThreadInit(group) != HDF_SUCCESS) {
+ OsalMutexUnlock(&group->mutex);
+ return HDF_FAILURE;
+ }
+ int32_t ret = HdfDevListenerThreadStart(group->thread);
+ OsalMutexUnlock(&group->mutex);
+ return ret;
+}
+
+static int32_t HdfListenThreadPollAdd(struct HdfDevListenerThread *thread, struct HdfSyscallAdapter *adapter)
+{
+ /* if thread is not bind to service group, not need to do poll add */
+ if (thread->adapterListPtr == NULL) {
+ return HDF_SUCCESS;
+ }
+
+ OsalMutexLock(&thread->mutex);
+ struct HdfSyscallAdapter *headAdapter = DListIsEmpty(thread->adapterListPtr) ?
+ NULL : DLIST_FIRST_ENTRY(thread->adapterListPtr, struct HdfSyscallAdapter, listNode);
+
+ DListInsertTail(&adapter->listNode, thread->adapterListPtr);
+
+ if (thread->status != LISTENER_RUNNING) {
+ OsalMutexUnlock(&thread->mutex);
+ return HDF_SUCCESS;
+ }
+
+ int32_t ret = HDF_SUCCESS;
+ do {
+ int32_t index = GetValidPfdIndexLocked(thread, adapter);
+ if (index < 0) {
+ ret = HDF_ERR_MALLOC_FAIL;
+ break;
+ }
+
+ thread->pfds[index].fd = adapter->fd;
+ thread->pfds[index].events = POLLIN;
+ thread->pfds[index].revents = 0;
+
+ if (headAdapter != NULL) {
+ if (ioctl(headAdapter->fd, HDF_LISTEN_EVENT_WAKEUP, 0) != 0) {
+ HDF_LOGE("%s: fail to wakeup drv to add poll %d %s", __func__, errno, strerror(errno));
+ thread->pfds[index].fd = SYSCALL_INVALID_FD;
+ ret = HDF_ERR_IO;
+ break;
+ }
+ }
+
+ if (HdfAdapterStartListenIoctl(adapter->fd) != HDF_SUCCESS) {
+ thread->pfds[index].fd = SYSCALL_INVALID_FD;
+ ret = HDF_DEV_ERR_OP;
+ break;
+ }
+ thread->pollChanged = true;
+ OsalMutexUnlock(&thread->mutex);
+ return ret;
+ } while (false);
+
+ DListRemove(&adapter->listNode);
+ OsalMutexUnlock(&thread->mutex);
+ return ret;
+}
+
+static void HdfListenThreadPollDel(struct HdfDevListenerThread *thread, struct HdfSyscallAdapter *adapter)
+{
+ if (thread == NULL) {
+ DListRemove(&adapter->listNode);
+ adapter->group = NULL;
+ return;
+ }
+ OsalMutexLock(&thread->mutex);
+ struct pollfd *pfds = thread->pfds;
+ for (uint32_t index = 0; index < thread->pfdSize; index++) {
+ if (pfds[index].fd == adapter->fd) {
+ pfds[index].fd = SYSCALL_INVALID_FD;
+ break;
+ }
+ }
+
+ if (HdfAdapterStopListenIoctl(adapter->fd)) {
+ HDF_LOGE("%s: fail to stop device report %d %s", __func__, errno, strerror(errno));
+ }
+
+ if (ioctl(adapter->fd, HDF_LISTEN_EVENT_WAKEUP, 0) != 0) {
+ HDF_LOGE("%s: fail to wakeup drv to del poll %d %s", __func__, errno, strerror(errno));
+ }
+ DListRemove(&adapter->listNode);
+ adapter->group = NULL;
+ thread->pollChanged = true;
+ OsalMutexUnlock(&thread->mutex);
+}
+
+static void HdfDevListenerThreadFree(struct HdfDevListenerThread *thread)
+{
+ OsalMutexDestroy(&thread->mutex);
+ OsalMemFree(thread->pfds);
+ OsalThreadDestroy(&thread->thread);
+ OsalMemFree(thread);
+}
+
+static void HdfDevListenerThreadDestroy(struct HdfDevListenerThread *thread)
+{
+ if (thread == NULL) {
+ return;
+ }
+
+ switch (thread->status) {
+ case LISTENER_RUNNING: {
+ uint32_t stopCount = 0;
+ OsalMutexLock(&thread->mutex);
+ thread->adapter = NULL;
+ thread->adapterListPtr = NULL;
+ thread->listenerListPtr = NULL;
+ OsalMutexUnlock(&thread->mutex);
+ for (int i = 0; i < thread->pfdSize; i++) {
+ if (thread->pfds[i].fd == SYSCALL_INVALID_FD) {
+ continue;
+ }
+ if (HdfAdapterExitListenIoctl(thread->pfds[i].fd) == HDF_SUCCESS) {
+ stopCount++;
+ }
+ }
+
+ if (stopCount == 0) {
+ thread->shouldStop = true;
+ HDF_LOGE("%s:failed to exit listener thread with ioctl, will go async way", __func__);
+ }
+
+ return;
+ }
+ case LISTENER_EXITED: // fall-through
+ case LISTENER_INITED:
+ HdfDevListenerThreadFree(thread);
+ break;
+ default:
+ break;
+ }
+}
+
+static int32_t HdfSyscallAdapterDispatch(struct HdfObject *object, int32_t code,
+ struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ if (object == NULL) {
+ HDF_LOGE("Input object is null");
+ return HDF_FAILURE;
+ }
+ struct HdfSyscallAdapter *ioService = (struct HdfSyscallAdapter *)object;
+ struct HdfWriteReadBuf wrBuf;
+ if (reply != NULL) {
+ wrBuf.readBuffer = (uintptr_t)HdfSbufGetData(reply);
+ wrBuf.readSize = HdfSbufGetCapacity(reply);
+ } else {
+ wrBuf.readBuffer = 0;
+ wrBuf.readSize = 0;
+ }
+ if (data != NULL) {
+ wrBuf.writeBuffer = (uintptr_t)HdfSbufGetData(data);
+ wrBuf.writeSize = HdfSbufGetDataSize(data);
+ } else {
+ wrBuf.writeBuffer = 0;
+ wrBuf.writeSize = 0;
+ }
+
+ wrBuf.readConsumed = 0;
+ wrBuf.writeConsumed = 0;
+ wrBuf.cmdCode = code;
+ int32_t ret = ioctl(ioService->fd, HDF_WRITE_READ, &wrBuf);
+ if (ret < 0) {
+ HDF_LOGE("dispatch serv call ioctl fail %d", errno);
+ }
+ if (reply != NULL) {
+ reply->writePos = wrBuf.readConsumed;
+ }
+ return ret;
+}
+
+struct HdfIoService *HdfIoServiceAdapterObtain(const char *serviceName)
+{
+ struct HdfSyscallAdapter *adapter = NULL;
+ struct HdfIoService *ioService = NULL;
+ char devNodePath[PATH_MAX] = {0};
+ char realPath[PATH_MAX] = {0};
+
+ const char *devPath = DEV_NODE_PATH;
+ if (access(DEV_NODE_PATH, F_OK) != 0) {
+ devPath = DEV_PATH;
+ }
+
+ if (sprintf_s(devNodePath, PATH_MAX - 1, "%s%s", devPath, serviceName) < 0) {
+ HDF_LOGE("Get node path failed");
+ return NULL;
+ }
+
+ if (realpath(devNodePath, realPath) == NULL) {
+ if (HdfLoadDriverByServiceName(serviceName) != HDF_SUCCESS) {
+ HDF_LOGE("%s load %s driver failed", __func__, serviceName);
+ return NULL;
+ }
+ if (realpath(devNodePath, realPath) == NULL) {
+ HDF_LOGE("%s file name %s is invalid", __func__, devNodePath);
+ return NULL;
+ }
+ }
+
+ adapter = (struct HdfSyscallAdapter *)OsalMemCalloc(sizeof(struct HdfSyscallAdapter));
+ if (adapter == NULL) {
+ HDF_LOGE("Alloc syscall adapter failed");
+ return NULL;
+ }
+
+ DListHeadInit(&adapter->listenerList);
+ if (OsalMutexInit(&adapter->mutex)) {
+ HDF_LOGE("%s: create mutex fail", __func__);
+ OsalMemFree(adapter);
+ return NULL;
+ }
+
+ adapter->fd = open(realPath, O_RDWR);
+ if (adapter->fd < 0) {
+ HDF_LOGE("Open file node %s failed, (%d)%s", realPath, errno, strerror(errno));
+ OsalMutexDestroy(&adapter->mutex);
+ OsalMemFree(adapter);
+ return NULL;
+ }
+ ioService = &adapter->super;
+ static struct HdfIoDispatcher dispatch = {
+ .Dispatch = HdfSyscallAdapterDispatch,
+ };
+ ioService->dispatcher = &dispatch;
+ return ioService;
+}
+
+void HdfIoServiceAdapterRecycle(struct HdfIoService *service)
+{
+ struct HdfSyscallAdapter *adapter = (struct HdfSyscallAdapter *)service;
+ if (adapter != NULL) {
+ HdfDevListenerThreadDestroy(adapter->thread);
+ adapter->thread = NULL;
+ if (adapter->fd >= 0) {
+ close(adapter->fd);
+ adapter->fd = -1;
+ }
+ OsalMutexDestroy(&adapter->mutex);
+ OsalMemFree(adapter);
+ }
+}
+
+static int32_t HdfIoServiceThreadBindLocked(struct HdfSyscallAdapter *adapter)
+{
+ if (adapter->thread == NULL) {
+ struct HdfDevListenerThread *listenerthread = HdfDevListenerThreadObtain();
+ if (listenerthread == NULL) {
+ return HDF_ERR_THREAD_CREATE_FAIL;
+ }
+ adapter->thread = listenerthread;
+ }
+ adapter->thread->adapter = adapter;
+ return HdfDevListenerThreadInit(adapter->thread);
+}
+
+static int32_t HdfIoServiceStartListen(struct HdfSyscallAdapter *adapter)
+{
+ if (HdfIoServiceThreadBindLocked(adapter) != HDF_SUCCESS) {
+ HDF_LOGE("%s:adapter bind thread fail", __func__);
+ return HDF_FAILURE;
+ }
+
+ return HdfDevListenerThreadStart(adapter->thread);
+}
+
+static bool AddListenerToAdapterLocked(struct HdfSyscallAdapter *adapter, struct HdfDevEventlistener *listener)
+{
+ struct HdfDevEventlistener *it = NULL;
+ DLIST_FOR_EACH_ENTRY(it, &adapter->listenerList, struct HdfDevEventlistener, listNode) {
+ if (it == listener) {
+ HDF_LOGE("add duplicate dev-event listener");
+ return false;
+ }
+ }
+ DListInsertTail(&listener->listNode, &adapter->listenerList);
+ return true;
+}
+
+int32_t HdfDeviceRegisterEventListener(struct HdfIoService *target, struct HdfDevEventlistener *listener)
+{
+ if (target == NULL || listener == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ if (listener->callBack == NULL && listener->onReceive == NULL) {
+ HDF_LOGE("listenr onReceive func not implement");
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ struct HdfSyscallAdapter *adapter = CONTAINER_OF(target, struct HdfSyscallAdapter, super);
+ int32_t ret = HDF_SUCCESS;
+
+ OsalMutexLock(&adapter->mutex);
+ if (!AddListenerToAdapterLocked(adapter, listener)) {
+ OsalMutexUnlock(&adapter->mutex);
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ if (adapter->group != NULL) {
+ /* service in group, should not bind to self hold thread and try to start group thread */
+ ret = HdfIoServiceGroupThreadStart(adapter->group);
+ OsalMutexUnlock(&adapter->mutex);
+ return ret;
+ }
+
+ if (HdfIoServiceStartListen(adapter) != HDF_SUCCESS) {
+ DListRemove(&listener->listNode);
+ ret = HDF_FAILURE;
+ }
+
+ OsalMutexUnlock(&adapter->mutex);
+ return ret;
+}
+
+int32_t HdfDeviceUnregisterEventListener(struct HdfIoService *target, struct HdfDevEventlistener *listener)
+{
+ if (target == NULL || listener == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ if (listener->listNode.next == NULL || listener->listNode.prev == NULL) {
+ HDF_LOGE("%s:broken listener, may double unregister", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ struct HdfSyscallAdapter *adapter = (struct HdfSyscallAdapter *)target;
+ OsalMutexLock(&adapter->mutex);
+
+ DListRemove(&listener->listNode);
+
+ if (DListIsEmpty(&adapter->listenerList)) {
+ HdfDevListenerThreadDestroy(adapter->thread);
+ adapter->thread = NULL;
+ }
+ OsalMutexUnlock(&adapter->mutex);
+
+ return HDF_SUCCESS;
+}
+
+struct HdfIoServiceGroup *HdfIoServiceGroupObtain(void)
+{
+ struct HdfSyscallAdapterGroup *adapterGroup = OsalMemCalloc(sizeof(struct HdfSyscallAdapterGroup));
+ if (adapterGroup == NULL) {
+ return NULL;
+ }
+
+ if (OsalMutexInit(&adapterGroup->mutex)) {
+ OsalMemFree(adapterGroup);
+ return NULL;
+ }
+ DListHeadInit(&adapterGroup->adapterList);
+ DListHeadInit(&adapterGroup->listenerList);
+ return &adapterGroup->serviceGroup;
+}
+
+void HdfIoServiceGroupRecycle(struct HdfIoServiceGroup *group)
+{
+ if (group == NULL) {
+ return;
+ }
+
+ struct HdfSyscallAdapterGroup *adapterGroup = CONTAINER_OF(group, struct HdfSyscallAdapterGroup, serviceGroup);
+ OsalMutexLock(&adapterGroup->mutex);
+
+ HdfDevListenerThreadDestroy(adapterGroup->thread);
+ adapterGroup->thread = NULL;
+
+ struct HdfSyscallAdapter *adapter = NULL;
+ struct HdfSyscallAdapter *tmp = NULL;
+ DLIST_FOR_EACH_ENTRY_SAFE(adapter, tmp, &adapterGroup->adapterList, struct HdfSyscallAdapter, listNode) {
+ DListRemove(&adapter->listNode);
+ adapter->group = NULL;
+ }
+
+ OsalMutexUnlock(&adapterGroup->mutex);
+
+ OsalMutexDestroy(&adapterGroup->mutex);
+ OsalMemFree(adapterGroup);
+}
+
+int32_t HdfIoServiceGroupRegisterListener(struct HdfIoServiceGroup *group, struct HdfDevEventlistener *listener)
+{
+ if (group == NULL || listener == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ if (listener->callBack == NULL && listener->onReceive == NULL) {
+ HDF_LOGE("listenr onReceive func not implement");
+ return HDF_ERR_INVALID_OBJECT;
+ }
+ struct HdfSyscallAdapterGroup *adapterGroup = CONTAINER_OF(group, struct HdfSyscallAdapterGroup, serviceGroup);
+
+ OsalMutexLock(&adapterGroup->mutex);
+ if (HdfIoServiceGroupThreadInit(adapterGroup) != HDF_SUCCESS) {
+ HDF_LOGE("%s:failed to bind listener thread for service group", __func__);
+ OsalMutexUnlock(&adapterGroup->mutex);
+ return HDF_FAILURE;
+ }
+
+ int32_t ret = HDF_SUCCESS;
+ struct HdfDevListenerThread *listenerThread = adapterGroup->thread;
+
+ OsalMutexLock(&listenerThread->mutex);
+ struct HdfDevEventlistener *it = NULL;
+ DLIST_FOR_EACH_ENTRY(it, &adapterGroup->listenerList, struct HdfDevEventlistener, listNode) {
+ if (it == listener) {
+ HDF_LOGE("add group listener failed, repeated registration");
+ ret = HDF_ERR_INVALID_OBJECT;
+ goto finish;
+ }
+ }
+ DListInsertTail(&listener->listNode, &adapterGroup->listenerList);
+ if (!DListIsEmpty(&adapterGroup->adapterList) && listenerThread->status != LISTENER_RUNNING) {
+ ret = HdfDevListenerThreadStart(listenerThread);
+ if (ret != HDF_SUCCESS) {
+ DListRemove(&listener->listNode);
+ }
+ }
+
+finish:
+ OsalMutexUnlock(&listenerThread->mutex);
+ OsalMutexUnlock(&adapterGroup->mutex);
+ return ret;
+}
+
+static int32_t GetListenerCount(struct HdfDevListenerThread *thread)
+{
+ struct HdfDevEventlistener *listener = NULL;
+ int32_t count = 0;
+
+ OsalMutexLock(&thread->mutex);
+ if (thread->listenerListPtr != NULL) {
+ DLIST_FOR_EACH_ENTRY (listener, thread->listenerListPtr, struct HdfDevEventlistener, listNode) {
+ count++;
+ }
+ }
+
+ struct HdfSyscallAdapter *adapter = NULL;
+ DLIST_FOR_EACH_ENTRY (adapter, thread->adapterListPtr, struct HdfSyscallAdapter, listNode) {
+ OsalMutexLock(&adapter->mutex);
+ DLIST_FOR_EACH_ENTRY (listener, &adapter->listenerList, struct HdfDevEventlistener, listNode) {
+ count++;
+ }
+ OsalMutexUnlock(&adapter->mutex);
+ }
+ OsalMutexUnlock(&thread->mutex);
+
+ return count;
+}
+
+int32_t HdfIoServiceGroupUnregisterListener(struct HdfIoServiceGroup *group, struct HdfDevEventlistener *listener)
+{
+ if (group == NULL || listener == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ if (listener->listNode.next == NULL || listener->listNode.prev == NULL) {
+ HDF_LOGE("%s:broken listener, may double unregister", __func__);
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ struct HdfSyscallAdapterGroup *adapterGroup = CONTAINER_OF(group, struct HdfSyscallAdapterGroup, serviceGroup);
+
+ OsalMutexLock(&adapterGroup->mutex);
+ struct HdfDevListenerThread *listenerThread = adapterGroup->thread;
+
+ DListRemove(&listener->listNode);
+
+ if (listenerThread != NULL && GetListenerCount(listenerThread) == 0) {
+ HdfDevListenerThreadDestroy(listenerThread);
+ adapterGroup->thread = NULL;
+ }
+ OsalMutexUnlock(&adapterGroup->mutex);
+
+ return HDF_SUCCESS;
+}
+
+int32_t HdfIoServiceGroupAddService(struct HdfIoServiceGroup *group, struct HdfIoService *service)
+{
+ if (group == NULL || service == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ struct HdfSyscallAdapter *adapter = CONTAINER_OF(service, struct HdfSyscallAdapter, super);
+ struct HdfSyscallAdapterGroup *adapterGroup = CONTAINER_OF(group, struct HdfSyscallAdapterGroup, serviceGroup);
+
+ if (adapter->group != NULL) {
+ HDF_LOGE("service already in group");
+ return HDF_ERR_DEVICE_BUSY;
+ }
+
+ if (adapter->thread != NULL) {
+ HDF_LOGE("service already has independent thread");
+ return HDF_ERR_DEVICE_BUSY;
+ }
+
+ OsalMutexLock(&adapterGroup->mutex);
+ if (HdfIoServiceGroupThreadInit(adapterGroup) != HDF_SUCCESS) {
+ HDF_LOGE("%s:failed to bind listener thread for service group", __func__);
+ OsalMutexUnlock(&adapterGroup->mutex);
+ return HDF_FAILURE;
+ }
+
+ struct HdfDevListenerThread *listenerThread = adapterGroup->thread;
+ int32_t ret = HdfListenThreadPollAdd(listenerThread, adapter);
+ if (ret != HDF_SUCCESS) {
+ OsalMutexUnlock(&adapterGroup->mutex);
+ return ret;
+ }
+
+ adapter->group = adapterGroup;
+
+ OsalMutexLock(&listenerThread->mutex);
+ if ((!DListIsEmpty(&adapterGroup->listenerList) || !DListIsEmpty(&adapter->listenerList)) &&
+ listenerThread->status != LISTENER_RUNNING) {
+ ret = HdfDevListenerThreadStart(adapterGroup->thread);
+ if (ret != HDF_SUCCESS) {
+ HdfListenThreadPollDel(adapterGroup->thread, adapter);
+ }
+ }
+ OsalMutexUnlock(&listenerThread->mutex);
+ OsalMutexUnlock(&adapterGroup->mutex);
+ return ret;
+}
+
+void HdfIoServiceGroupRemoveService(struct HdfIoServiceGroup *group, struct HdfIoService *service)
+{
+ if (group == NULL || service == NULL) {
+ return;
+ }
+ struct HdfSyscallAdapter *adapter = CONTAINER_OF(service, struct HdfSyscallAdapter, super);
+ struct HdfSyscallAdapterGroup *adapterGroup = CONTAINER_OF(group, struct HdfSyscallAdapterGroup, serviceGroup);
+ if (adapterGroup->thread == NULL || adapter->group == NULL) {
+ return;
+ }
+
+ OsalMutexLock(&adapterGroup->mutex);
+ if (HaveOnlyOneElement(&adapterGroup->adapterList)) {
+ HdfDevListenerThreadDestroy(adapterGroup->thread);
+ adapterGroup->thread = NULL;
+ DListRemove(&adapter->listNode);
+ adapter->group = NULL;
+ } else {
+ HdfListenThreadPollDel(adapterGroup->thread, adapter);
+ }
+ OsalMutexUnlock(&adapterGroup->mutex);
+ adapter->group = NULL;
+}
+
+static int DlistGetCount(const struct DListHead *head)
+{
+ struct DListHead *next = head->next;
+ int count = 0;
+ while (next != head) {
+ next = next->next;
+ count++;
+ }
+ return count;
+}
+
+int HdfIoserviceGetListenerCount(const struct HdfIoService *service)
+{
+ if (service == NULL) {
+ return 0;
+ }
+
+ struct HdfSyscallAdapter *adapter = CONTAINER_OF(service, struct HdfSyscallAdapter, super);
+
+ OsalMutexLock(&adapter->mutex);
+ int count = DlistGetCount(&adapter->listenerList);
+ OsalMutexUnlock(&adapter->mutex);
+ return count;
+}
+
+int HdfIoserviceGroupGetListenerCount(const struct HdfIoServiceGroup *group)
+{
+ if (group == NULL) {
+ return 0;
+ }
+
+ struct HdfSyscallAdapterGroup *adapterGroup = CONTAINER_OF(group, struct HdfSyscallAdapterGroup, serviceGroup);
+ OsalMutexLock(&adapterGroup->mutex);
+ if (adapterGroup->thread == NULL) {
+ OsalMutexUnlock(&adapterGroup->mutex);
+ return 0;
+ }
+ int count = GetListenerCount(adapterGroup->thread);
+ OsalMutexUnlock(&adapterGroup->mutex);
+ return count;
+}
+
+int HdfIoserviceGroupGetServiceCount(const struct HdfIoServiceGroup *group)
+{
+ if (group == NULL) {
+ return 0;
+ }
+
+ struct HdfSyscallAdapterGroup *adapterGroup = CONTAINER_OF(group, struct HdfSyscallAdapterGroup, serviceGroup);
+
+ OsalMutexLock(&adapterGroup->mutex);
+ if (adapterGroup->thread == NULL) {
+ OsalMutexUnlock(&adapterGroup->mutex);
+ return 0;
+ }
+
+ OsalMutexLock(&adapterGroup->thread->mutex);
+ int count = DlistGetCount(&adapterGroup->adapterList);
+ OsalMutexUnlock(&adapterGroup->thread->mutex);
+
+ OsalMutexUnlock(&adapterGroup->mutex);
+
+ return count;
+}
diff --git a/core/adapter/vnode/include/hdf_vnode_adapter.h b/core/adapter/vnode/include/hdf_vnode_adapter.h
new file mode 100644
index 00000000..96fcb9db
--- /dev/null
+++ b/core/adapter/vnode/include/hdf_vnode_adapter.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#ifndef HDF_VNODE_ADAPTER_H
+#define HDF_VNODE_ADAPTER_H
+#include "hdf_dlist.h"
+#include "osal_mutex.h"
+#include "hdf_sbuf.h"
+#include "hdf_io_service.h"
+
+struct OsalCdev;
+
+struct HdfVNodeAdapter {
+ struct HdfIoService ioService;
+ char *vNodePath;
+ struct OsalMutex mutex;
+ struct DListHead clientList;
+ struct OsalCdev *cdev;
+};
+
+struct HdfDevEvent {
+ uint32_t id;
+ struct HdfSBuf *data;
+ struct DListHead listNode;
+};
+
+#endif /* HDF_VNODE_ADAPTER_H */
+
diff --git a/core/adapter/vnode/src/hdf_vnode_adapter.c b/core/adapter/vnode/src/hdf_vnode_adapter.c
new file mode 100644
index 00000000..0d39bd60
--- /dev/null
+++ b/core/adapter/vnode/src/hdf_vnode_adapter.c
@@ -0,0 +1,662 @@
+/*
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include "hdf_vnode_adapter.h"
+#include
+#include
+#include
+#include
+#include
+#include "devsvc_manager_clnt.h"
+#include "hdf_device_node_ext.h"
+#include "hdf_log.h"
+#include "hdf_sbuf.h"
+
+#define HDF_LOG_TAG hdf_vnode
+#define VOID_DATA_SIZE 4
+#define EVENT_QUEUE_MAX 100
+#define MAX_RW_SIZE (1024*1204) // 1M
+
+enum HdfVNodeClientStatus {
+ VNODE_CLIENT_RUNNING,
+ VNODE_CLIENT_LISTENING,
+ VNODE_CLIENT_STOPPED,
+ VNODE_CLIENT_EXITED,
+};
+
+struct HdfVNodeAdapterClient {
+ struct HdfVNodeAdapter *adapter;
+ struct HdfDeviceIoClient ioServiceClient;
+ wait_queue_head_t pollWait;
+ struct HdfIoService *serv;
+ struct OsalMutex mutex;
+ struct DListHead eventQueue;
+ struct DListHead listNode;
+ int32_t eventQueueSize;
+ int32_t wakeup;
+ uint32_t status;
+};
+
+struct HdfIoServiceKClient {
+ struct HdfIoService ioService;
+ struct HdfDeviceIoClient client;
+};
+
+int HdfKIoServiceDispatch (struct HdfObject *service, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ struct HdfIoService *ioService = (struct HdfIoService*)service;
+ struct HdfIoServiceKClient *kClient = NULL;
+
+ if (ioService == NULL || ioService->dispatcher == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ kClient = CONTAINER_OF(ioService, struct HdfIoServiceKClient, ioService);
+ if (kClient->client.device == NULL || kClient->client.device->service == NULL ||
+ kClient->client.device->service->Dispatch == NULL) {
+ return HDF_ERR_INVALID_OBJECT;
+ }
+
+ return kClient->client.device->service->Dispatch(&kClient->client, cmdId, data, reply);
+}
+
+static struct HdfIoServiceKClient *HdfHdfIoServiceKClientInstance(struct HdfDeviceObject *deviceObject)
+{
+ static struct HdfIoDispatcher kDispatcher = {
+ .Dispatch = HdfKIoServiceDispatch,
+ };
+
+ struct HdfIoServiceKClient *client = OsalMemCalloc(sizeof(struct HdfIoServiceKClient));
+ if (client == NULL) {
+ return NULL;
+ }
+
+ client->client.device = deviceObject;
+ if (deviceObject->service != NULL && deviceObject->service->Open != NULL) {
+ if (deviceObject->service->Open(&client->client) != HDF_SUCCESS) {
+ OsalMemFree(client);
+ return NULL;
+ }
+ }
+
+ client->ioService.dispatcher = &kDispatcher;
+ return client;
+}
+
+struct HdfIoService *HdfIoServiceAdapterObtain(const char *serviceName)
+{
+ struct DevSvcManagerClnt *svcMgr = NULL;
+ struct HdfDeviceObject *deviceObject = NULL;
+ struct HdfIoServiceKClient *kClient = NULL;
+
+ if (serviceName == NULL) {
+ return NULL;
+ }
+
+ svcMgr = DevSvcManagerClntGetInstance();
+ if (svcMgr == NULL) {
+ return NULL;
+ }
+ deviceObject = svcMgr->devSvcMgrIf->GetObject(svcMgr->devSvcMgrIf, serviceName);
+ if (deviceObject == NULL) {
+ return NULL;
+ }
+
+ kClient = HdfHdfIoServiceKClientInstance(deviceObject);
+ if (kClient == NULL) {
+ return NULL;
+ }
+
+ return &kClient->ioService;
+}
+
+void HdfIoServiceAdapterRecycle(struct HdfIoService *ioService)
+{
+ struct HdfIoServiceKClient *kClient = NULL;
+
+ if (ioService == NULL) {
+ return;
+ }
+
+ kClient = CONTAINER_OF(ioService, struct HdfIoServiceKClient, ioService);
+ if (kClient->client.device != NULL && kClient->client.device->service != NULL &&
+ kClient->client.device->service->Release != NULL) {
+ kClient->client.device->service->Release(&kClient->client);
+ }
+ OsalMemFree(kClient);
+}
+
+static struct HdfSBuf *HdfSbufCopyFromUser(uintptr_t data, size_t size)
+{
+ uint8_t *kData = NULL;
+ struct HdfSBuf *sbuf = NULL;
+
+ if (size == 0) {
+ return HdfSBufObtain(VOID_DATA_SIZE);
+ }
+
+ kData = OsalMemAlloc(size);
+ if (kData == NULL) {
+ HDF_LOGE("%s:oom", __func__);
+ return NULL;
+ }
+ if (CopyFromUser((void*)kData, (void*)data, size) != 0) {
+ HDF_LOGE("%s:copy from user fail", __func__);
+ OsalMemFree(kData);
+ return NULL;
+ }
+
+ sbuf = HdfSBufBind((uintptr_t)kData, size);
+ if (sbuf == NULL) {
+ OsalMemFree(kData);
+ }
+ HdfSbufTransDataOwnership(sbuf);
+
+ return sbuf;
+}
+
+static int HdfSbufCopyToUser(const struct HdfSBuf *sbuf, void *dstUser, size_t dstUserSize)
+{
+ size_t sbufSize = HdfSbufGetDataSize(sbuf);
+ if (sbufSize == 0) {
+ return HDF_SUCCESS;
+ }
+ if (dstUserSize < sbufSize) {
+ HDF_LOGE("%s: readBuffer too small %u", __func__, sbufSize);
+ return HDF_DEV_ERR_NORANGE;
+ }
+
+ if (CopyToUser(dstUser, HdfSbufGetData(sbuf), sbufSize) != 0) {
+ HDF_LOGE("%s: copy buff data fail", __func__);
+ return HDF_ERR_IO;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static void DevEventFree(struct HdfDevEvent *event)
+{
+ if (event == NULL) {
+ return;
+ }
+ if (event->data != NULL) {
+ HdfSBufRecycle(event->data);
+ event->data = NULL;
+ }
+ OsalMemFree(event);
+}
+
+static int HdfVNodeAdapterServCall(const struct HdfVNodeAdapterClient *client, unsigned long arg)
+{
+ struct HdfWriteReadBuf bwr;
+ struct HdfWriteReadBuf *bwrUser = (struct HdfWriteReadBuf *)((uintptr_t)arg);
+ struct HdfSBuf *data = NULL;
+ struct HdfSBuf *reply = NULL;
+ int ret;
+
+ if (client->serv == NULL) {
+ return HDF_DEV_ERR_NO_DEVICE;
+ }
+
+ if (bwrUser == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ if (CopyFromUser(&bwr, (void*)bwrUser, sizeof(bwr)) != 0) {
+ HDF_LOGE("Copy from user failed");
+ return HDF_FAILURE;
+ }
+ if (bwr.writeSize > MAX_RW_SIZE || bwr.readSize > MAX_RW_SIZE) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ data = HdfSbufCopyFromUser(bwr.writeBuffer, bwr.writeSize);
+ if (data == NULL) {
+ HDF_LOGE("Vnode adapter bind data is null");
+ return HDF_FAILURE;
+ }
+ reply = HdfSBufObtainDefaultSize();
+ if (reply == NULL) {
+ HDF_LOGE("%s:oom", __func__);
+ HdfSBufRecycle(data);
+ return HDF_FAILURE;
+ }
+ (void)HdfSbufWriteUint64(reply, (uintptr_t)&client->ioServiceClient);
+ ret = client->adapter->ioService.dispatcher->Dispatch(client->adapter->ioService.target,
+ bwr.cmdCode, data, reply);
+ if (bwr.readSize != 0 && HdfSbufCopyToUser(reply, (void*)bwr.readBuffer, bwr.readSize) != HDF_SUCCESS) {
+ HdfSBufRecycle(data);
+ HdfSBufRecycle(reply);
+ return HDF_ERR_IO;
+ }
+ bwr.readConsumed = HdfSbufGetDataSize(reply);
+ if (CopyToUser(bwrUser, &bwr, sizeof(struct HdfWriteReadBuf)) != 0) {
+ HDF_LOGE("%s: copy bwr fail", __func__);
+ ret = HDF_FAILURE;
+ }
+
+ HdfSBufRecycle(data);
+ HdfSBufRecycle(reply);
+ return ret;
+}
+
+static int HdfVNodeAdapterReadDevEvent(struct HdfVNodeAdapterClient *client, unsigned long arg)
+{
+ struct HdfWriteReadBuf bwr;
+ struct HdfWriteReadBuf *bwrUser = (struct HdfWriteReadBuf *)((uintptr_t)arg);
+ struct HdfDevEvent *event = NULL;
+ size_t eventSize;
+
+ int ret = HDF_SUCCESS;
+ if (bwrUser == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ if (CopyFromUser(&bwr, (void*)bwrUser, sizeof(bwr)) != 0) {
+ HDF_LOGE("Copy from user failed");
+ return HDF_FAILURE;
+ }
+
+ if (bwr.readSize > MAX_RW_SIZE) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ OsalMutexLock(&client->mutex);
+
+ if (DListIsEmpty(&client->eventQueue)) {
+ OsalMutexUnlock(&client->mutex);
+ return HDF_DEV_ERR_NODATA;
+ }
+
+ event = CONTAINER_OF(client->eventQueue.next, struct HdfDevEvent, listNode);
+ eventSize = HdfSbufGetDataSize(event->data);
+ if (eventSize > bwr.readSize) {
+ bwr.readSize = eventSize;
+ ret = HDF_DEV_ERR_NORANGE;
+ } else {
+ if (HdfSbufCopyToUser(event->data, (void *)bwr.readBuffer, bwr.readSize) != HDF_SUCCESS) {
+ OsalMutexUnlock(&client->mutex);
+ return HDF_ERR_IO;
+ }
+ bwr.readConsumed = eventSize;
+ bwr.cmdCode = event->id;
+ }
+
+ if (CopyToUser(bwrUser, &bwr, sizeof(struct HdfWriteReadBuf)) != 0) {
+ HDF_LOGE("%s: copy bwr fail", __func__);
+ ret = HDF_ERR_IO;
+ }
+ if (ret == HDF_SUCCESS) {
+ DListRemove(&event->listNode);
+ DevEventFree(event);
+ client->eventQueueSize--;
+ }
+
+ OsalMutexUnlock(&client->mutex);
+ return ret;
+}
+
+static void HdfVnodeAdapterDropOldEventLocked(struct HdfVNodeAdapterClient *client)
+{
+ struct HdfDevEvent *dropEvent = CONTAINER_OF(client->eventQueue.next, struct HdfDevEvent, listNode);
+
+ HDF_LOGE("dev event queue full, drop old one");
+ DListRemove(&dropEvent->listNode);
+ DevEventFree(dropEvent);
+ client->eventQueueSize--;
+}
+
+static int VNodeAdapterSendDevEventToClient(struct HdfVNodeAdapterClient *vnodeClient,
+ uint32_t id, const struct HdfSBuf *data)
+{
+ struct HdfDevEvent *event = NULL;
+
+ OsalMutexLock(&vnodeClient->mutex);
+ if (vnodeClient->status != VNODE_CLIENT_LISTENING) {
+ OsalMutexUnlock(&vnodeClient->mutex);
+ return HDF_SUCCESS;
+ }
+ if (vnodeClient->eventQueueSize >= EVENT_QUEUE_MAX) {
+ HdfVnodeAdapterDropOldEventLocked(vnodeClient);
+ }
+ event = OsalMemAlloc(sizeof(struct HdfDevEvent));
+ if (event == NULL) {
+ OsalMutexUnlock(&vnodeClient->mutex);
+ return HDF_DEV_ERR_NO_MEMORY;
+ }
+ event->id = id;
+ event->data = HdfSBufCopy(data);
+ if (event->data == NULL) {
+ OsalMutexUnlock(&vnodeClient->mutex);
+ HDF_LOGE("%s: sbuf oom", __func__);
+ OsalMemFree(event);
+ return HDF_DEV_ERR_NO_MEMORY;
+ }
+ DListInsertTail(&event->listNode, &vnodeClient->eventQueue);
+ vnodeClient->eventQueueSize++;
+ wake_up_interruptible(&vnodeClient->pollWait);
+ OsalMutexUnlock(&vnodeClient->mutex);
+
+ return HDF_SUCCESS;
+}
+
+static int HdfVNodeAdapterSendDevEvent(struct HdfVNodeAdapter *adapter, struct HdfVNodeAdapterClient *vnodeClient,
+ uint32_t id, const struct HdfSBuf *data)
+{
+ struct HdfVNodeAdapterClient *client = NULL;
+ int ret = HDF_FAILURE;
+
+ if (adapter == NULL || data == NULL || HdfSbufGetDataSize(data) == 0) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+ OsalMutexLock(&adapter->mutex);
+ DLIST_FOR_EACH_ENTRY(client, &adapter->clientList, struct HdfVNodeAdapterClient, listNode) {
+ if (vnodeClient != NULL && client != vnodeClient) {
+ continue;
+ }
+ ret = VNodeAdapterSendDevEventToClient(client, id, data);
+ if (ret != HDF_SUCCESS) {
+ break;
+ }
+ }
+ OsalMutexUnlock(&adapter->mutex);
+ return ret;
+}
+
+static void HdfVNodeAdapterClientStartListening(struct HdfVNodeAdapterClient *client)
+{
+ OsalMutexLock(&client->mutex);
+ client->status = VNODE_CLIENT_LISTENING;
+ OsalMutexUnlock(&client->mutex);
+}
+
+static void HdfVnodeCleanEventQueue(struct HdfVNodeAdapterClient *client)
+{
+ struct HdfDevEvent *event = NULL;
+ struct HdfDevEvent *eventTemp = NULL;
+ DLIST_FOR_EACH_ENTRY_SAFE(event, eventTemp, &client->eventQueue, struct HdfDevEvent, listNode) {
+ DListRemove(&event->listNode);
+ DevEventFree(event);
+ }
+}
+
+static void HdfVNodeAdapterClientStopListening(struct HdfVNodeAdapterClient *client)
+{
+ OsalMutexLock(&client->mutex);
+ client->status = VNODE_CLIENT_STOPPED;
+ HdfVnodeCleanEventQueue(client);
+ wake_up_interruptible(&client->pollWait);
+ OsalMutexUnlock(&client->mutex);
+}
+
+static void HdfVNodeAdapterClientExitListening(struct HdfVNodeAdapterClient *client)
+{
+ OsalMutexLock(&client->mutex);
+ client->status = VNODE_CLIENT_EXITED;
+ HdfVnodeCleanEventQueue(client);
+ wake_up_interruptible(&client->pollWait);
+ OsalMutexUnlock(&client->mutex);
+}
+
+static void HdfVNodeAdapterClientWakeup(struct HdfVNodeAdapterClient *client)
+{
+ OsalMutexLock(&client->mutex);
+ if (client->status != VNODE_CLIENT_LISTENING) {
+ OsalMutexUnlock(&client->mutex);
+ return;
+ }
+ client->wakeup++;
+ wake_up_interruptible(&client->pollWait);
+ OsalMutexUnlock(&client->mutex);
+}
+
+static long HdfVNodeAdapterIoctl(struct file *filep, unsigned int cmd, unsigned long arg)
+{
+ struct HdfVNodeAdapterClient *client = (struct HdfVNodeAdapterClient *)OsalGetFilePriv(filep);
+ if (client == NULL) {
+ return HDF_DEV_ERR_NO_DEVICE;
+ }
+ switch (cmd) {
+ case HDF_WRITE_READ:
+ return HdfVNodeAdapterServCall(client, arg);
+ case HDF_READ_DEV_EVENT:
+ return HdfVNodeAdapterReadDevEvent(client, arg);
+ case HDF_LISTEN_EVENT_START:
+ HdfVNodeAdapterClientStartListening(client);
+ break;
+ case HDF_LISTEN_EVENT_STOP:
+ HdfVNodeAdapterClientStopListening(client);
+ break;
+ case HDF_LISTEN_EVENT_WAKEUP:
+ HdfVNodeAdapterClientWakeup(client);
+ break;
+ case HDF_LISTEN_EVENT_EXIT:
+ HdfVNodeAdapterClientExitListening(client);
+ break;
+ default:
+ return HDF_FAILURE;
+ }
+
+ return HDF_SUCCESS;
+}
+
+static struct HdfVNodeAdapterClient *HdfNewVNodeAdapterClient(struct HdfVNodeAdapter *adapter)
+{
+ struct HdfVNodeAdapterClient *client = OsalMemCalloc(sizeof(struct HdfVNodeAdapterClient));
+ if (client == NULL) {
+ HDF_LOGE("%s: oom", __func__);
+ return NULL;
+ }
+ if (OsalMutexInit(&client->mutex) != HDF_SUCCESS) {
+ OsalMemFree(client);
+ HDF_LOGE("%s: no mutex", __func__);
+ return NULL;
+ }
+
+ DListHeadInit(&client->eventQueue);
+ client->eventQueueSize = 0;
+ client->serv = &adapter->ioService;
+ client->status = VNODE_CLIENT_RUNNING;
+ client->adapter = adapter;
+ client->eventQueueSize = 0;
+ client->ioServiceClient.device = (struct HdfDeviceObject *)adapter->ioService.target;
+ client->ioServiceClient.priv = NULL;
+ client->wakeup = 0;
+ init_waitqueue_head(&client->pollWait);
+ OsalMutexLock(&adapter->mutex);
+ DListInsertTail(&client->listNode, &adapter->clientList);
+ OsalMutexUnlock(&adapter->mutex);
+
+ return client;
+}
+
+static void HdfDestoryVNodeAdapterClient(struct HdfVNodeAdapterClient *client)
+{
+ struct HdfDevEvent *event = NULL;
+ struct HdfDevEvent *eventTemp = NULL;
+
+ client->status = VNODE_CLIENT_STOPPED;
+
+ OsalMutexLock(&client->adapter->mutex);
+ DListRemove(&client->listNode);
+ OsalMutexUnlock(&client->adapter->mutex);
+
+ OsalMutexLock(&client->mutex);
+ DLIST_FOR_EACH_ENTRY_SAFE(event, eventTemp, &client->eventQueue, struct HdfDevEvent, listNode) {
+ DListRemove(&event->listNode);
+ DevEventFree(event);
+ }
+ OsalMutexUnlock(&client->mutex);
+ OsalMutexDestroy(&client->mutex);
+ OsalMemFree(client);
+}
+
+int HdfVNodeAdapterOpen(struct OsalCdev *cdev, struct file *filep)
+{
+ struct HdfVNodeAdapter *adapter = (struct HdfVNodeAdapter *)OsalGetCdevPriv(cdev);
+ struct HdfVNodeAdapterClient *client = NULL;
+ int32_t ret;
+
+ if (adapter == NULL) {
+ HDF_LOGE("Vnode adapter dispatcher is null");
+ return HDF_FAILURE;
+ }
+ client = HdfNewVNodeAdapterClient(adapter);
+ if (client == NULL) {
+ return ETXTBSY;
+ }
+ OsalSetFilePriv(filep, client);
+ if (client->ioServiceClient.device != NULL && client->ioServiceClient.device->service != NULL &&
+ client->ioServiceClient.device->service->Open != NULL) {
+ ret = client->ioServiceClient.device->service->Open(&client->ioServiceClient);
+ if (ret != HDF_SUCCESS) {
+ HdfDestoryVNodeAdapterClient(client);
+ return ret;
+ }
+ }
+
+ return HDF_SUCCESS;
+}
+
+static unsigned int HdfVNodeAdapterPoll(struct file *filep, poll_table *wait)
+{
+ unsigned int mask = 0;
+ struct HdfVNodeAdapterClient *client = (struct HdfVNodeAdapterClient *)OsalGetFilePriv(filep);
+
+ poll_wait(filep, &client->pollWait, wait);
+ OsalMutexLock(&client->mutex);
+ if (client->status == VNODE_CLIENT_EXITED) {
+ mask |= POLLHUP;
+ } else if (!DListIsEmpty(&client->eventQueue)) {
+ mask |= POLLIN;
+ } else if (client->wakeup > 0) {
+ mask |= POLLIN;
+ client->wakeup--;
+ }
+ OsalMutexUnlock(&client->mutex);
+ return mask;
+}
+
+static int HdfVNodeAdapterClose(struct OsalCdev *cdev, struct file *filep)
+{
+ (void)cdev;
+ struct HdfVNodeAdapterClient *client = (struct HdfVNodeAdapterClient *)OsalGetFilePriv(filep);
+ if (client->ioServiceClient.device != NULL && client->ioServiceClient.device->service != NULL &&
+ client->ioServiceClient.device->service->Release != NULL) {
+ client->ioServiceClient.device->service->Release(&client->ioServiceClient);
+ }
+ HdfDestoryVNodeAdapterClient(client);
+ return HDF_SUCCESS;
+}
+
+struct HdfIoService *HdfIoServiceAdapterPublish(const char *serviceName, uint32_t mode)
+{
+ int nodePathLength;
+ struct HdfVNodeAdapter *vnodeAdapter = NULL;
+ int ret;
+ static const struct OsalCdevOps fileOps = {
+ .open = HdfVNodeAdapterOpen,
+ .release = HdfVNodeAdapterClose,
+ .ioctl = HdfVNodeAdapterIoctl,
+ .poll = HdfVNodeAdapterPoll,
+ };
+
+ if ((serviceName == NULL) || (mode > MAX_MODE_SIZE)) {
+ HDF_LOGE("Input param is invalid, mode is %x", mode);
+ return NULL;
+ }
+
+ vnodeAdapter = (struct HdfVNodeAdapter *)OsalMemCalloc(sizeof(struct HdfVNodeAdapter));
+ if (vnodeAdapter == NULL) {
+ HDF_LOGE("Alloc remote service is null");
+ return NULL;
+ }
+
+ nodePathLength = strlen(serviceName) + strlen(DEV_NODE_PATH) + 1;
+ vnodeAdapter->vNodePath = (char *)OsalMemCalloc(nodePathLength);
+ if (vnodeAdapter->vNodePath == NULL) {
+ HDF_LOGE("Alloc vnode path is null");
+ OsalMemFree(vnodeAdapter);
+ return NULL;
+ }
+
+ if (sprintf_s(vnodeAdapter->vNodePath, nodePathLength, "%s%s", DEV_NODE_PATH, serviceName) < 0) {
+ HDF_LOGE("Get node path failed");
+ OsalMemFree(vnodeAdapter->vNodePath);
+ OsalMemFree(vnodeAdapter);
+ return NULL;
+ }
+ DListHeadInit(&vnodeAdapter->clientList);
+ if (OsalMutexInit(&vnodeAdapter->mutex) != HDF_SUCCESS) {
+ HDF_LOGE("vnode adapter out of mutex");
+ goto error;
+ }
+ vnodeAdapter->cdev = OsalAllocCdev(&fileOps);
+ if (vnodeAdapter->cdev == NULL) {
+ HDF_LOGE("fail to alloc osalcdev");
+ OsalMutexDestroy(&vnodeAdapter->mutex);
+ goto error;
+ }
+ ret = OsalRegisterCdev(vnodeAdapter->cdev, vnodeAdapter->vNodePath, mode, vnodeAdapter);
+ if (ret != 0) {
+ HDF_LOGE("register dev node %s failed, ret is: %d", vnodeAdapter->vNodePath, ret);
+ OsalMutexDestroy(&vnodeAdapter->mutex);
+ goto error;
+ }
+
+ return &vnodeAdapter->ioService;
+error:
+ OsalMemFree(vnodeAdapter->vNodePath);
+ OsalMemFree(vnodeAdapter);
+ return NULL;
+}
+
+void HdfIoServiceAdapterRemove(struct HdfIoService *service)
+{
+ if (service != NULL) {
+ struct HdfVNodeAdapter *vnodeAdapter = (struct HdfVNodeAdapter *)service;
+ if (vnodeAdapter->vNodePath != NULL) {
+ OsalUnregisterCdev(vnodeAdapter->cdev);
+ OsalFreeCdev(vnodeAdapter->cdev);
+ OsalMemFree(vnodeAdapter->vNodePath);
+ }
+ OsalMutexDestroy(&vnodeAdapter->mutex);
+ OsalMemFree(vnodeAdapter);
+ }
+}
+
+int32_t HdfDeviceSendEvent(const struct HdfDeviceObject *deviceObject, uint32_t id, const struct HdfSBuf *data)
+{
+ struct HdfDeviceNode *deviceNode = NULL;
+ struct HdfVNodeAdapter *adapter = NULL;
+
+ if (deviceObject == NULL || data == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ deviceNode = CONTAINER_OF(deviceObject, struct HdfDeviceNode, deviceObject);
+ if (deviceNode->deviceInfo->policy != SERVICE_POLICY_CAPACITY) {
+ return HDF_ERR_NOT_SUPPORT;
+ }
+
+ adapter = (struct HdfVNodeAdapter *)(((struct DeviceNodeExt*)deviceNode)->ioService);
+ return HdfVNodeAdapterSendDevEvent(adapter, NULL, id, data);
+}
+
+int32_t HdfDeviceSendEventToClient(const struct HdfDeviceIoClient *client, uint32_t id, const struct HdfSBuf *data)
+{
+ struct HdfVNodeAdapterClient *vnodeClient = NULL;
+ if (client == NULL || client->device == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ vnodeClient = CONTAINER_OF(client, struct HdfVNodeAdapterClient, ioServiceClient);
+ if (vnodeClient->adapter == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ return HdfVNodeAdapterSendDevEvent(vnodeClient->adapter, vnodeClient, id, data);
+}
diff --git a/core/common/include/host/hdf_device_section.h b/core/common/include/host/hdf_device_section.h
new file mode 100644
index 00000000..fea82a1c
--- /dev/null
+++ b/core/common/include/host/hdf_device_section.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#ifndef HDF_DEVICE_SECTION_H
+#define HDF_DEVICE_SECTION_H
+
+#if !defined(NON_HDF_DRIVER_SECTION)
+#define USED_ATTR __attribute__((used))
+#define HDF_SECTION __attribute__((section(".hdf.driver")))
+#define HDF_DRIVER_INIT(module) \
+ const size_t USED_ATTR module##HdfEntry HDF_SECTION = (size_t)(&(module))
+
+#if (defined(__GNUC__) || defined(__clang__))
+#define HDF_DRIVER_SEC_NAME(type, name) \
+ ({ extern type name; \
+ &name; \
+ })
+#define HDF_DRIVER_BEGIN() HDF_DRIVER_SEC_NAME(size_t, _hdf_drivers_start)
+#define HDF_DRIVER_END() HDF_DRIVER_SEC_NAME(size_t, _hdf_drivers_end)
+
+#elif defined(__ICCARM__)
+#define HDF_DRIVER_BEGIN() __section_begin(".hdf.driver")
+#define HDF_DRIVER_END() __section_end(".hdf.driver")
+#pragma section = ".hdf.driver"
+#else
+#error "No support section begin and section end!"
+#endif /* defined(__GNUC__) || defined(__clang__) */
+#endif /* NON_HDF_DRIVER_SECTION */
+
+#endif /* HDF_DEVICE_SECTION_H */
+
diff --git a/core/common/include/manager/devmgr_service_start.h b/core/common/include/manager/devmgr_service_start.h
new file mode 100644
index 00000000..6a2d571e
--- /dev/null
+++ b/core/common/include/manager/devmgr_service_start.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#ifndef DEVICE_SERVICE_START_H
+#define DEVICE_SERVICE_START_H
+
+enum {
+ DEV_MGR_SLOW_LOAD = 0,
+ DEV_MGR_QUICK_LOAD,
+};
+
+int DeviceManagerStart(void);
+int DeviceManagerStartStep2(void);
+void DeviceManagerSetQuickLoad(int isQuickLoad);
+int DeviceManagerIsQuickLoad(void);
+
+#endif /* DEVICE_SERVICE_START_H */
diff --git a/core/common/include/manager/hdf_device_node_ext.h b/core/common/include/manager/hdf_device_node_ext.h
new file mode 100644
index 00000000..b0bb685c
--- /dev/null
+++ b/core/common/include/manager/hdf_device_node_ext.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#ifndef HDF_DEVICE_NODE_EXT_H
+#define HDF_DEVICE_NODE_EXT_H
+
+#include "hdf_io_service.h"
+#include "hdf_device_node.h"
+
+struct DeviceNodeExt {
+ struct HdfDeviceNode super;
+ struct HdfIoService *ioService;
+};
+
+struct HdfObject *DeviceNodeExtCreate(void);
+void DeviceNodeExtRelease(struct HdfObject *object);
+
+#endif /* HDF_DEVICE_NODE_EXT_H */
+
diff --git a/core/common/src/devlite_object_config.c b/core/common/src/devlite_object_config.c
new file mode 100644
index 00000000..bea66407
--- /dev/null
+++ b/core/common/src/devlite_object_config.c
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include "hdf_object_manager.h"
+#include "devhost_service.h"
+#include "devmgr_service.h"
+#include "devsvc_manager.h"
+#include "hdf_device.h"
+#include "hdf_device_node_ext.h"
+#include "hdf_device_token.h"
+#include "hdf_driver_installer.h"
+#include "hdf_driver_loader.h"
+
+static const struct HdfObjectCreator g_liteObjectCreators[] = {
+ [HDF_OBJECT_ID_DEVMGR_SERVICE] =
+ {
+ .Create = DevmgrServiceCreate,
+ .Release = DevmgrServiceRelease,
+ },
+ [HDF_OBJECT_ID_DEVSVC_MANAGER] =
+ {
+ .Create = DevSvcManagerCreate,
+ .Release = DevSvcManagerRelease,
+ },
+ [HDF_OBJECT_ID_DEVHOST_SERVICE] =
+ {
+ .Create = DevHostServiceCreate,
+ .Release = DevHostServiceRelease,
+ },
+ [HDF_OBJECT_ID_DRIVER_INSTALLER] =
+ {
+ .Create = DriverInstallerCreate,
+ .Release = NULL,
+ },
+ [HDF_OBJECT_ID_DRIVER_LOADER] =
+ {
+ .Create = HdfDriverLoaderCreate,
+ .Release = NULL,
+ },
+ [HDF_OBJECT_ID_DEVICE] =
+ {
+ .Create = HdfDeviceCreate,
+ .Release = HdfDeviceRelease,
+ },
+ [HDF_OBJECT_ID_DEVICE_TOKEN] =
+ {
+ .Create = HdfDeviceTokenCreate,
+ .Release = HdfDeviceTokenRelease,
+ },
+ [HDF_OBJECT_ID_DEVICE_SERVICE] =
+ {
+ .Create = DeviceNodeExtCreate,
+ .Release = DeviceNodeExtRelease,
+ }
+};
+
+const struct HdfObjectCreator *HdfObjectManagerGetCreators(int objectId)
+{
+ int numConfigs = sizeof(g_liteObjectCreators) / sizeof(g_liteObjectCreators[0]);
+ if ((objectId >= 0) && (objectId < numConfigs)) {
+ return &g_liteObjectCreators[objectId];
+ }
+ return NULL;
+}
diff --git a/core/common/src/devmgr_service_start.c b/core/common/src/devmgr_service_start.c
new file mode 100644
index 00000000..a1c78200
--- /dev/null
+++ b/core/common/src/devmgr_service_start.c
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include "devmgr_service_start.h"
+#include "devhost_service_clnt.h"
+#include "devmgr_service.h"
+#include "devsvc_manager_clnt.h"
+#include "hdf_base.h"
+#include "hdf_device_node.h"
+#include "hdf_io_service.h"
+#include "hdf_log.h"
+#include "hdf_sbuf.h"
+
+#define DEV_MGR_NODE_PERM 0660
+
+static int g_isQuickLoad = DEV_MGR_SLOW_LOAD;
+
+static void GetDeviceServiceNameByClass(DeviceClass deviceClass, struct HdfSBuf *reply)
+{
+ struct HdfSListIterator itHost;
+ struct HdfSListIterator itDeviceInfo;
+ struct HdfDeviceInfo *deviceInfo = NULL;
+ struct DevHostServiceClnt *hostClnt = NULL;
+ struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
+ if (devMgrSvc == NULL) {
+ return;
+ }
+
+ reply->readPos = 0;
+ reply->writePos = 0;
+ HdfSListIteratorInit(&itHost, &devMgrSvc->hosts);
+ while (HdfSListIteratorHasNext(&itHost)) {
+ hostClnt = (struct DevHostServiceClnt *)HdfSListIteratorNext(&itHost);
+ 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);
+ }
+ }
+ }
+ HdfSbufWriteString(reply, NULL);
+}
+
+int DeviceManagerDispatch(struct HdfObject *stub, int code, struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ (void)reply;
+ int ret = HDF_FAILURE;
+ int32_t deviceClass = 0;
+ const char *svcName = NULL;
+ struct DevmgrService *devMgrSvc = (struct DevmgrService *)stub;
+ if (data == NULL || devMgrSvc == NULL) {
+ HDF_LOGE("%s: input param is invalid", __func__);
+ return ret;
+ }
+ OsalMutexLock(&devMgrSvc->devMgrMutex);
+ switch (code) {
+ case DEVMGR_LOAD_SERVICE:
+ svcName = HdfSbufReadString(data);
+ if (svcName == NULL) {
+ HDF_LOGE("%s: get svc name is null", __func__);
+ break;
+ }
+ static struct SubscriberCallback callback = {
+ .deviceObject = NULL,
+ .OnServiceConnected = NULL,
+ };
+ ret = DevSvcManagerClntSubscribeService(svcName, callback);
+ break;
+ case DEVMGR_UNLOAD_SERVICE:
+ svcName = HdfSbufReadString(data);
+ if (svcName == NULL) {
+ HDF_LOGE("%s: get svc name is null", __func__);
+ break;
+ }
+ ret = DevSvcManagerClntUnsubscribeService(svcName);
+ break;
+ case DEVMGR_GET_SERVICE:
+ if (!HdfSbufReadInt32(data, &deviceClass)) {
+ HDF_LOGE("%s: get deviceClass failed", __func__);
+ break;
+ }
+ GetDeviceServiceNameByClass(deviceClass, reply);
+ ret = HDF_SUCCESS;
+ break;
+ default:
+ HDF_LOGE("%s: Currently, this configuration type is not supported. the type is %d", __func__, code);
+ break;
+ }
+ OsalMutexUnlock(&devMgrSvc->devMgrMutex);
+ return ret;
+}
+
+void DeviceManagerSetQuickLoad(int loadFlag)
+{
+ g_isQuickLoad = loadFlag;
+}
+
+int DeviceManagerIsQuickLoad()
+{
+ return g_isQuickLoad;
+}
+
+int DeviceManagerStart()
+{
+ struct IDevmgrService *instance = DevmgrServiceGetInstance();
+
+ if (instance == NULL || instance->StartService == NULL) {
+ HDF_LOGE("Device manager start failed, service instance is null!");
+ return HDF_FAILURE;
+ }
+ struct HdfIoService *ioService = HdfIoServicePublish(DEV_MGR_NODE, DEV_MGR_NODE_PERM);
+ if (ioService != NULL) {
+ static struct HdfIoDispatcher dispatcher = {
+ .Dispatch = DeviceManagerDispatch,
+ };
+ ioService->dispatcher = &dispatcher;
+ ioService->target = &instance->base;
+ }
+ return instance->StartService(instance);
+}
+
+int DeviceManagerStartStep2()
+{
+ if (DeviceManagerIsQuickLoad() == DEV_MGR_SLOW_LOAD) {
+ HDF_LOGW("%s device manager is not set quick load!", __func__);
+ return HDF_SUCCESS;
+ }
+ struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
+ return DevmgrServiceLoadLeftDriver(devMgrSvc);
+}
+
diff --git a/core/common/src/hdf_attribute.c b/core/common/src/hdf_attribute.c
new file mode 100644
index 00000000..71583265
--- /dev/null
+++ b/core/common/src/hdf_attribute.c
@@ -0,0 +1,369 @@
+/*
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include "hdf_attribute_manager.h"
+#include "devhost_service_clnt.h"
+#include "devmgr_service.h"
+#include "hcs_blob_if.h"
+#include "hcs_parser.h"
+#include "hcs_tree_if.h"
+#include "hdf_base.h"
+#include "hdf_device_info.h"
+#include "hdf_host_info.h"
+#include "hdf_log.h"
+#include "osal_mem.h"
+#include "securec.h"
+
+#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 struct DeviceResourceNode *g_hcsTreeRoot = NULL;
+
+void HdfGetBuildInConfigData(const unsigned char **data, unsigned int *size);
+static bool CreateHcsToTree(void)
+{
+ uint32_t length;
+ const unsigned char *hcsBlob = NULL;
+ HdfGetBuildInConfigData(&hcsBlob, &length);
+ if (!HcsCheckBlobFormat((const char *)hcsBlob, length)) {
+ return false;
+ }
+ if (!HcsDecompile((const char *)hcsBlob, HBC_HEADER_LENGTH, &g_hcsTreeRoot)) {
+ return false;
+ }
+ return true;
+}
+
+const struct DeviceResourceNode *HcsGetRootNode(void)
+{
+ if ((g_hcsTreeRoot == NULL) && !CreateHcsToTree()) {
+ HDF_LOGE("%s failed", __func__);
+ return NULL;
+ }
+ return g_hcsTreeRoot;
+}
+
+const struct DeviceResourceNode *HdfGetRootNode(void)
+{
+ return HcsGetRootNode();
+}
+
+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("%s get host name failed", __func__);
+ return false;
+ }
+ if ((HcsGetUint16(hostNode, ATTR_DEV_PRIORITY, &readNum, 0) != HDF_SUCCESS) ||
+ (readNum > MAX_PRIORITY_NUM)) {
+ HDF_LOGW("%s get host priority failed, priority is: %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(HcsGetRootNode());
+ if (hdfManagerNode == NULL) {
+ HDF_LOGE("%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("%s new hostInfo is null", __func__);
+ return false;
+ }
+ if (!GetHostInfo(hostNode, hostInfo)) {
+ HdfHostInfoFreeInstance(hostInfo);
+ hostInfo = NULL;
+ hostNode = hostNode->sibling;
+ continue;
+ }
+ hostInfo->hostId = hostId;
+ if (!HdfSListAddOrder(hostList, &hostInfo->node, HdfHostListCompare)) {
+ HdfHostInfoFreeInstance(hostInfo);
+ hostInfo = NULL;
+ 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(HcsGetRootNode());
+ 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(const struct HdfDeviceInfo *deviceNodeInfo)
+{
+ if (deviceNodeInfo->policy > SERVICE_POLICY_PRIVATE) {
+ HDF_LOGE("%s policy is invalid", __func__);
+ return false;
+ }
+
+ if (deviceNodeInfo->priority > MAX_PRIORITY_NUM) {
+ HDF_LOGE("%s priority is invalid", __func__);
+ return false;
+ }
+
+ if (deviceNodeInfo->preload > DEVICE_PRELOAD_DISABLE) {
+ HDF_LOGE("%s preload is invalid", __func__);
+ return false;
+ }
+
+ return (strcmp(deviceNodeInfo->moduleName, "") != 0);
+}
+
+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("%s get policy failed", __func__);
+ return false;
+ }
+ deviceNodeInfo->policy = readNum;
+
+ if (HcsGetUint16(deviceNode, ATTR_DEV_PRIORITY, &readNum, 0) != HDF_SUCCESS) {
+ HDF_LOGE("%s get priority failed", __func__);
+ return false;
+ }
+ deviceNodeInfo->priority = readNum;
+
+ if (HcsGetUint16(deviceNode, ATTR_DEV_PRELOAD, &readNum, 0) != HDF_SUCCESS) {
+ HDF_LOGE("%s get preload failed", __func__);
+ return false;
+ }
+ deviceNodeInfo->preload = readNum;
+
+ if (HcsGetUint16(deviceNode, ATTR_DEV_PERMISSION, &readNum, 0) != HDF_SUCCESS) {
+ HDF_LOGE("%s get permission failed", __func__);
+ return false;
+ }
+ deviceNodeInfo->permission = readNum;
+
+ if (HcsGetString(deviceNode, ATTR_DEV_MODULENAME, &readString, NULL) != HDF_SUCCESS) {
+ HDF_LOGE("%s get module name failed", __func__);
+ return false;
+ }
+ deviceNodeInfo->moduleName = readString;
+
+ if (HcsGetString(deviceNode, ATTR_DEV_SVCNAME, &readString, NULL) != HDF_SUCCESS) {
+ HDF_LOGE("%s get service name failed", __func__);
+ return false;
+ }
+ deviceNodeInfo->svcName = readString;
+
+ if (HcsGetString(deviceNode, ATTR_DEV_MATCHATTR, &readString, NULL) != HDF_SUCCESS) {
+ HDF_LOGE("%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;
+ 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) {
+ struct HdfDeviceInfo *deviceNodeInfo = HdfDeviceInfoNewInstance();
+ if (deviceNodeInfo == NULL) {
+ HdfSListFlush(deviceList, HdfDeviceInfoDelete);
+ OsalMemFree(deviceList);
+ return NULL;
+ }
+ deviceNodeInfo->hostId = hostId;
+ if (!GetDeviceNodeInfo(deviceNode, deviceNodeInfo)) {
+ HdfDeviceInfoFreeInstance(deviceNodeInfo);
+ HDF_LOGE("%s get device failed", __func__);
+ deviceNodeInfo = NULL;
+ deviceNode = deviceNode->sibling;
+ continue;
+ }
+ if (!HdfSListAddOrder(deviceList, &deviceNodeInfo->node, HdfDeviceListCompare)) {
+ HDF_LOGE("%s add device %s failed", __func__, deviceNodeInfo->svcName);
+ HdfDeviceInfoFreeInstance(deviceNodeInfo);
+ deviceNodeInfo = NULL;
+ deviceNode = deviceNode->sibling;
+ continue;
+ }
+ deviceNodeInfo->deviceId = deviceIdx;
+ deviceNode = deviceNode->sibling;
+ }
+ device = device->sibling;
+ deviceIdx++;
+ }
+ if (HdfSListCount(deviceList) == 0) {
+ OsalMemFree(deviceList);
+ return NULL;
+ }
+ return deviceList;
+}
+
+bool HdfDeviceListAdd(const char *moduleName, const char *serviceName)
+{
+ struct HdfSListIterator itHost;
+ struct HdfSListIterator itDeviceInfo;
+ struct HdfDeviceInfo *deviceInfo = NULL;
+ struct DevHostServiceClnt *hostClnt = NULL;
+ struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
+ if (devMgrSvc == NULL || moduleName == NULL || serviceName == NULL) {
+ return false;
+ }
+
+ struct HdfDeviceInfo *deviceNodeInfo = HdfDeviceInfoNewInstance();
+ if (deviceNodeInfo == NULL) {
+ return false;
+ }
+ HdfSListIteratorInit(&itHost, &devMgrSvc->hosts);
+ while (HdfSListIteratorHasNext(&itHost)) {
+ hostClnt = (struct DevHostServiceClnt *)HdfSListIteratorNext(&itHost);
+ HdfSListIteratorInit(&itDeviceInfo, hostClnt->deviceInfos);
+ while (HdfSListIteratorHasNext(&itDeviceInfo)) {
+ deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo);
+ if (deviceInfo->moduleName == NULL) {
+ continue;
+ }
+ if (strcmp(deviceInfo->moduleName, moduleName) == 0) {
+ deviceInfo->isDynamic = true;
+ deviceNodeInfo->hostId = deviceInfo->hostId;
+ deviceNodeInfo->deviceId = hostClnt->devCount;
+ deviceNodeInfo->policy = deviceInfo->policy;
+ deviceNodeInfo->priority = deviceInfo->priority;
+ deviceNodeInfo->preload = DEVICE_PRELOAD_DISABLE;
+ deviceNodeInfo->permission = deviceInfo->permission;
+ deviceNodeInfo->deviceMatchAttr = deviceInfo->deviceMatchAttr;
+ deviceNodeInfo->moduleName = deviceInfo->moduleName;
+ char *svcName = OsalMemCalloc(strlen(serviceName) + 1);
+ if (svcName == NULL) {
+ break;
+ }
+ if (strcpy_s(svcName, strlen(serviceName) + 1, serviceName) != EOK) {
+ HDF_LOGE("%s: string copy fail", __func__);
+ OsalMemFree(svcName);
+ break;
+ }
+ deviceNodeInfo->svcName = svcName;
+ HdfSListAdd(hostClnt->deviceInfos, &deviceNodeInfo->node);
+ hostClnt->devCount++;
+ return true;
+ }
+ }
+ }
+ HdfDeviceInfoFreeInstance(deviceNodeInfo);
+ return false;
+}
+
+void HdfDeviceListDel(const char *moduleName, const char *serviceName)
+{
+ struct HdfSListIterator itHost;
+ struct HdfSListIterator itDeviceInfo;
+ struct HdfDeviceInfo *deviceInfo = NULL;
+ struct DevHostServiceClnt *hostClnt = NULL;
+ struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
+ if (devMgrSvc == NULL || moduleName == NULL || serviceName == NULL) {
+ return;
+ }
+
+ HdfSListIteratorInit(&itHost, &devMgrSvc->hosts);
+ while (HdfSListIteratorHasNext(&itHost)) {
+ hostClnt = (struct DevHostServiceClnt *)HdfSListIteratorNext(&itHost);
+ HdfSListIteratorInit(&itDeviceInfo, hostClnt->deviceInfos);
+ while (HdfSListIteratorHasNext(&itDeviceInfo)) {
+ deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo);
+ if ((strcmp(deviceInfo->moduleName, moduleName) == 0) &&
+ (strcmp(deviceInfo->svcName, serviceName) == 0)) {
+ HdfSListRemove(hostClnt->deviceInfos, &deviceInfo->node);
+ HdfDeviceInfoFreeInstance(deviceInfo);
+ hostClnt->devCount--;
+ return;
+ }
+ }
+ }
+}
+
diff --git a/core/common/src/hdf_device_node_ext.c b/core/common/src/hdf_device_node_ext.c
new file mode 100644
index 00000000..493cd51e
--- /dev/null
+++ b/core/common/src/hdf_device_node_ext.c
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include "hdf_device_node_ext.h"
+#include "devsvc_manager_clnt.h"
+#include "hdf_base.h"
+#include "hdf_device_desc.h"
+#include "hdf_io_service.h"
+#include "hdf_log.h"
+#include "hdf_sbuf.h"
+#include "osal_mem.h"
+
+#define HDF_LOG_TAG device_node_ext
+
+static int DeviceNodeExtDispatch(struct HdfObject *stub, int code, struct HdfSBuf *data, struct HdfSBuf *reply)
+{
+ struct IDeviceIoService *deviceMethod = NULL;
+ const struct HdfDeviceInfo *deviceInfo = NULL;
+ struct HdfDeviceNode *devNode = NULL;
+
+ if (stub == NULL) {
+ HDF_LOGE("input ioService null");
+ return HDF_FAILURE;
+ }
+ uint64_t ioClientPtr = 0;
+ if (!HdfSbufReadUint64(reply, &ioClientPtr) || ioClientPtr == 0) {
+ HDF_LOGE("input ioClient null");
+ return HDF_FAILURE;
+ }
+ HdfSbufFlush(reply);
+ devNode = CONTAINER_OF(stub, struct HdfDeviceNode, deviceObject);
+ deviceMethod = devNode->deviceObject.service;
+ if (deviceMethod == NULL) {
+ HDF_LOGE("Device service interface is null");
+ return HDF_FAILURE;
+ }
+ deviceInfo = devNode->deviceInfo;
+ if (deviceInfo == NULL) {
+ HDF_LOGE("Device deviceInfo is null");
+ return HDF_FAILURE;
+ }
+ if (deviceInfo->policy == SERVICE_POLICY_CAPACITY) {
+ if (deviceMethod->Dispatch == NULL) {
+ HDF_LOGE("Remote service dispatch is null");
+ return HDF_FAILURE;
+ }
+ return deviceMethod->Dispatch((struct HdfDeviceIoClient *)((uintptr_t)ioClientPtr), code, data, reply);
+ }
+ return HDF_FAILURE;
+}
+
+static int DeviceNodeExtPublishService(struct HdfDeviceNode *inst, const char *serviceName)
+{
+ const struct HdfDeviceInfo *deviceInfo = NULL;
+ struct HdfDeviceObject *deviceObject = NULL;
+ struct DeviceNodeExt *devNodeExt = (struct DeviceNodeExt *)inst;
+ if (devNodeExt == NULL) {
+ return HDF_FAILURE;
+ }
+ int ret = HdfDeviceNodePublishPublicService(inst, serviceName);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("Device publish service failed, ret is: %d", ret);
+ return HDF_FAILURE;
+ }
+
+ deviceInfo = inst->deviceInfo;
+ deviceObject = &devNodeExt->super.deviceObject;
+ if ((deviceObject->service == NULL) || (deviceInfo == NULL)) {
+ HDF_LOGE("Device service interface or deviceInfo is null");
+ return HDF_FAILURE;
+ }
+ if (deviceInfo->policy == SERVICE_POLICY_CAPACITY) {
+ devNodeExt->ioService = HdfIoServicePublish(serviceName, deviceInfo->permission);
+ if (devNodeExt->ioService != NULL) {
+ devNodeExt->ioService->target = (struct HdfObject*)(&inst->deviceObject);
+ static struct HdfIoDispatcher dispatcher = {
+ .Dispatch = DeviceNodeExtDispatch
+ };
+ devNodeExt->ioService->dispatcher = &dispatcher;
+ } else {
+ HDF_LOGE("Device remote service bind failed");
+ HdfDeviceNodeReclaimService(serviceName);
+ return HDF_FAILURE;
+ }
+ }
+ return HDF_SUCCESS;
+}
+
+static void DeviceNodeExtConstruct(struct DeviceNodeExt *inst)
+{
+ struct IDeviceNode *nodeIf = (struct IDeviceNode *)inst;
+ if (nodeIf != NULL) {
+ HdfDeviceNodeConstruct(&inst->super);
+ nodeIf->PublishService = DeviceNodeExtPublishService;
+ }
+}
+
+struct HdfObject *DeviceNodeExtCreate()
+{
+ struct DeviceNodeExt *instance =
+ (struct DeviceNodeExt *)OsalMemCalloc(sizeof(struct DeviceNodeExt));
+ if (instance != NULL) {
+ DeviceNodeExtConstruct(instance);
+ instance->ioService = NULL;
+ }
+ return (struct HdfObject *)instance;
+}
+
+void DeviceNodeExtRelease(struct HdfObject *object)
+{
+ struct DeviceNodeExt *instance = (struct DeviceNodeExt *)object;
+ if (instance != NULL) {
+ if (instance->ioService != NULL) {
+ HdfIoServiceRemove(instance->ioService);
+ }
+ HdfDeviceNodeDestruct(&instance->super);
+ OsalMemFree(instance);
+ }
+}
+
diff --git a/core/common/src/load_driver_entry.c b/core/common/src/load_driver_entry.c
new file mode 100644
index 00000000..39e420a4
--- /dev/null
+++ b/core/common/src/load_driver_entry.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include "hdf_driver_loader.h"
+#include "hdf_log.h"
+#include "osal_mem.h"
+
+static struct HdfDriverEntry *HdfDriverEntryConstruct(int32_t *driverCount)
+{
+ int i;
+ *driverCount = (int32_t)(((uint8_t *)(HDF_DRIVER_END()) - (uint8_t *)(HDF_DRIVER_BEGIN())) / sizeof(size_t));
+ if (*driverCount <= 0) {
+ HDF_LOGE("%s hdf get device counts failed!", __func__);
+ return NULL;
+ }
+ struct HdfDriverEntry *driverEntry = OsalMemCalloc(*driverCount * sizeof(struct HdfDriverEntry));
+ if (driverEntry == NULL) {
+ HDF_LOGE("%s hdf alloc driver entry mem failed!", __func__);
+ *driverCount = 0;
+ return NULL;
+ }
+ size_t *addrBegin = (size_t *)(HDF_DRIVER_BEGIN());
+ for (i = 0; i < *driverCount; i++) {
+ driverEntry[i] = *(struct HdfDriverEntry *)(*addrBegin);
+ addrBegin++;
+ }
+ return driverEntry;
+}
+
+struct HdfDriverEntry *HdfDriverLoaderGetDriverEntry(const struct HdfDeviceInfo *deviceInfo)
+{
+ int i;
+ if ((deviceInfo == NULL) || (deviceInfo->moduleName == NULL) || (deviceInfo->svcName == NULL)) {
+ HDF_LOGE("%s hdf get device entry failed, input deviceInfo is NULL!", __func__);
+ return NULL;
+ }
+ static struct HdfDriverEntry *driverEntry = NULL;
+ static int32_t driverCount = 0;
+ if (driverEntry == NULL) {
+ driverEntry = HdfDriverEntryConstruct(&driverCount);
+ if (driverEntry == NULL) {
+ HDF_LOGE("%s driver entry construct failed!", __func__);
+ return NULL;
+ }
+ }
+ for (i = 0; i < driverCount; i++) {
+ if (driverEntry == NULL) {
+ HDF_LOGE("%s driver entry is null!", __func__);
+ return NULL;
+ }
+ if (driverEntry[i].moduleName == NULL) {
+ HDF_LOGE("%s driver entry module name is null!", __func__);
+ return NULL;
+ }
+ if (strcmp(deviceInfo->moduleName, driverEntry[i].moduleName) == 0) {
+ return &driverEntry[i];
+ }
+ }
+ HDF_LOGE("Hdf get %s device entry failed!", deviceInfo->svcName);
+ return NULL;
+}
+
diff --git a/core/host/include/devhost_service.h b/core/host/include/devhost_service.h
old mode 100755
new mode 100644
index 402e67ce..26d8972c
--- a/core/host/include/devhost_service.h
+++ b/core/host/include/devhost_service.h
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#ifndef DEVICE_HOST_SERVICE_H
@@ -45,6 +22,9 @@ struct DevHostService {
struct HdfServiceObserver observer;
};
+void DevHostServiceConstruct(struct DevHostService *service);
+void DevHostServiceDestruct(struct DevHostService *service);
+int DevHostServiceAddDevice(struct IDevHostService *inst, const struct HdfDeviceInfo *deviceInfo);
struct IDevHostService *DevHostServiceNewInstance(uint16_t hostId, const char *hostName);
void DevHostServiceFreeInstance(struct IDevHostService *service);
struct HdfObject *DevHostServiceCreate(void);
diff --git a/core/host/include/devmgr_service_clnt.h b/core/host/include/devmgr_service_clnt.h
old mode 100755
new mode 100644
index 962cf208..87216668
--- a/core/host/include/devmgr_service_clnt.h
+++ b/core/host/include/devmgr_service_clnt.h
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#ifndef DEVMGR_SERVICE_CLIENT_H
diff --git a/core/host/include/devsvc_manager_clnt.h b/core/host/include/devsvc_manager_clnt.h
old mode 100755
new mode 100644
index 03be6eca..e164d8ae
--- a/core/host/include/devsvc_manager_clnt.h
+++ b/core/host/include/devsvc_manager_clnt.h
@@ -1,39 +1,15 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#ifndef DEVSVC_MANAGER_CLNT_H
#define DEVSVC_MANAGER_CLNT_H
#include "devsvc_manager_if.h"
-#include "devsvc_manager_stub.h"
struct DevSvcManagerClnt {
struct IDevSvcManager *devSvcMgrIf;
@@ -43,5 +19,9 @@ struct DevSvcManagerClnt *DevSvcManagerClntGetInstance(void);
struct HdfDeviceObject *DevSvcManagerClntGetDeviceObject(const char *svcName);
int DevSvcManagerClntAddService(const char *svcName, struct HdfDeviceObject *service);
void DevSvcManagerClntRemoveService(const char *svcName);
+int DevSvcManagerClntSubscribeService(const char *svcName, struct SubscriberCallback callback);
+int DevSvcManagerClntUnsubscribeService(const char *svcName);
+struct HdfDeviceObject *HdfRegisterDevice(const char *moduleName, const char *serviceName);
+void HdfUnregisterDevice(const char *moduleName, const char *serviceName);
#endif /* DEVSVC_MANAGER_CLNT_H */
diff --git a/core/host/include/hdf_device.h b/core/host/include/hdf_device.h
old mode 100755
new mode 100644
index 26b2189f..c14e9901
--- a/core/host/include/hdf_device.h
+++ b/core/host/include/hdf_device.h
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#ifndef HDF_DEVICE_H
@@ -54,7 +31,8 @@ struct HdfDevice {
uint16_t deviceId;
uint16_t hostId;
};
-
+void HdfDeviceConstruct(struct HdfDevice *device);
+void HdfDeviceDestruct(struct HdfDevice *device);
struct HdfObject *HdfDeviceCreate(void);
void HdfDeviceRelease(struct HdfObject *object);
struct HdfDevice *HdfDeviceNewInstance(void);
diff --git a/core/host/include/hdf_device_node.h b/core/host/include/hdf_device_node.h
old mode 100755
new mode 100644
index 1af1982b..aee06dd2
--- a/core/host/include/hdf_device_node.h
+++ b/core/host/include/hdf_device_node.h
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#ifndef HDF_DEVICE_NODE_H
diff --git a/core/host/include/hdf_device_object.h b/core/host/include/hdf_device_object.h
old mode 100755
new mode 100644
index 62732f9c..ec194e46
--- a/core/host/include/hdf_device_object.h
+++ b/core/host/include/hdf_device_object.h
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#ifndef HDF_DEVICE_OBJECT_H
diff --git a/core/host/include/hdf_device_token.h b/core/host/include/hdf_device_token.h
old mode 100755
new mode 100644
index 851766e5..2f4f24c9
--- a/core/host/include/hdf_device_token.h
+++ b/core/host/include/hdf_device_token.h
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#ifndef HDF_DEVICE_TOKEN_H
diff --git a/core/host/include/hdf_driver_loader.h b/core/host/include/hdf_driver_loader.h
old mode 100755
new mode 100644
index 3551fed1..e6fbb413
--- a/core/host/include/hdf_driver_loader.h
+++ b/core/host/include/hdf_driver_loader.h
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#ifndef HDF_DRIVER_LOADER_H
@@ -51,5 +28,7 @@ struct HdfObject *HdfDriverLoaderCreate(void);
void HdfDriverLoaderRelease(struct HdfObject *object);
struct IDriverLoader *HdfDriverLoaderGetInstance(void);
struct HdfDriverEntry *HdfDriverLoaderGetDriverEntry(const struct HdfDeviceInfo *deviceInfo);
+struct HdfDeviceNode *HdfDriverLoaderLoadNode(
+ struct IDriverLoader *loader, const struct HdfDeviceInfo *deviceInfo);
#endif /* HDF_DRIVER_LOADER_H */
diff --git a/core/host/include/hdf_observer_record.h b/core/host/include/hdf_observer_record.h
old mode 100755
new mode 100644
index 4dd7370d..a8bcbd93
--- a/core/host/include/hdf_observer_record.h
+++ b/core/host/include/hdf_observer_record.h
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#ifndef HDF_OBSERVER_RECORD_H
diff --git a/core/host/include/hdf_service_observer.h b/core/host/include/hdf_service_observer.h
old mode 100755
new mode 100644
index 530a09c3..d9a23038
--- a/core/host/include/hdf_service_observer.h
+++ b/core/host/include/hdf_service_observer.h
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#ifndef HDF_SERVICE_OBSERVER_H
diff --git a/core/host/include/hdf_service_subscriber.h b/core/host/include/hdf_service_subscriber.h
old mode 100755
new mode 100644
index 3ec9106b..2d2528b0
--- a/core/host/include/hdf_service_subscriber.h
+++ b/core/host/include/hdf_service_subscriber.h
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#ifndef HDF_SERVICE_SUBSCRIBER_H
diff --git a/core/host/include/power_state_token.h b/core/host/include/power_state_token.h
old mode 100755
new mode 100644
index c75cdb19..eda268bf
--- a/core/host/include/power_state_token.h
+++ b/core/host/include/power_state_token.h
@@ -1,50 +1,27 @@
-/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, 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 POWER_STATE_TOKEN_H
-#define POWER_STATE_TOKEN_H
-
-#include "hdf_sref.h"
-#include "power_state_token_if.h"
-
-struct PowerStateToken {
- struct IPowerStateToken super;
- struct IPowerEventListener *listener;
- struct HdfDeviceObject *deviceObject;
- struct HdfSRef wakeRef;
- HdfPowerState state;
-};
-
-struct PowerStateToken *PowerStateTokenNewInstance(
- struct HdfDeviceObject *deviceObject, struct IPowerEventListener *listener);
-void PowerStateTokenFreeInstance(struct PowerStateToken *stateToken);
-
+/*
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#ifndef POWER_STATE_TOKEN_H
+#define POWER_STATE_TOKEN_H
+
+#include "hdf_sref.h"
+#include "power_state_token_if.h"
+
+struct PowerStateToken {
+ struct IPowerStateToken super;
+ struct IPowerEventListener *listener;
+ struct HdfDeviceObject *deviceObject;
+ struct HdfSRef wakeRef;
+ HdfPowerState state;
+};
+
+struct PowerStateToken *PowerStateTokenNewInstance(
+ struct HdfDeviceObject *deviceObject, struct IPowerEventListener *listener);
+void PowerStateTokenFreeInstance(struct PowerStateToken *stateToken);
+
#endif /* POWER_STATE_TOKEN_H */
\ No newline at end of file
diff --git a/core/host/src/devhost_service.c b/core/host/src/devhost_service.c
old mode 100755
new mode 100644
index d5f91073..71f1ffd9
--- a/core/host/src/devhost_service.c
+++ b/core/host/src/devhost_service.c
@@ -1,39 +1,18 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#include "devhost_service.h"
#include "devmgr_service_clnt.h"
#include "devsvc_manager_clnt.h"
#include "hdf_base.h"
+#include "hdf_device_node_ext.h"
#include "hdf_driver_loader.h"
+#include "hdf_io_service.h"
#include "hdf_log.h"
#include "hdf_object_manager.h"
#include "osal_mem.h"
@@ -79,12 +58,13 @@ static struct HdfDevice *DevHostServiceGetDevice(struct DevHostService *inst, ui
return NULL;
}
device->hostId = inst->hostId;
+ device->deviceId = deviceId;
HdfSListAdd(&inst->devices, &device->node);
}
return device;
}
-static int DevHostServiceAddDevice(struct IDevHostService *inst, const struct HdfDeviceInfo *deviceInfo)
+int DevHostServiceAddDevice(struct IDevHostService *inst, const struct HdfDeviceInfo *deviceInfo)
{
int ret = HDF_FAILURE;
struct HdfDevice *device = NULL;
@@ -116,8 +96,8 @@ static int DevHostServiceAddDevice(struct IDevHostService *inst, const struct Hd
return HDF_SUCCESS;
error:
- if (HdfSListIsEmpty(&hostService->devices)) {
- DevHostServiceFreeDevice(hostService, hostService->hostId);
+ if (!HdfSListIsEmpty(&hostService->devices)) {
+ DevHostServiceFreeDevice(hostService, deviceInfo->deviceId);
}
return ret;
}
@@ -140,7 +120,21 @@ static int DevHostServiceDelDevice(struct IDevHostService *inst, const struct Hd
}
driverLoader->UnLoadNode(driverLoader, deviceInfo);
- if (HdfSListIsEmpty(&hostService->devices)) {
+ struct HdfSListIterator it;
+ struct HdfDeviceNode *deviceNode = NULL;
+ HdfSListIteratorInit(&it, &device->services);
+ while (HdfSListIteratorHasNext(&it)) {
+ deviceNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
+ struct HdfSListNode, HdfSListIteratorNext(&it), struct HdfDeviceNode, entry);
+ if ((strcmp(deviceNode->deviceInfo->moduleName, deviceInfo->moduleName) == 0) &&
+ (strcmp(deviceNode->deviceInfo->svcName, deviceInfo->svcName) == 0)) {
+ struct DeviceNodeExt *deviceNodeExt = (struct DeviceNodeExt *)deviceNode;
+ HdfSListRemove(&device->services, &deviceNode->entry);
+ DeviceNodeExtRelease(&deviceNodeExt->super.super.object);
+ }
+ }
+
+ if (!HdfSListIsEmpty(&hostService->devices)) {
DevHostServiceFreeDevice(hostService, device->deviceId);
}
DevSvcManagerClntRemoveService(deviceInfo->svcName);
@@ -157,7 +151,7 @@ static int DevHostServiceStartService(struct IDevHostService *service)
return DevmgrServiceClntAttachDeviceHost(hostService->hostId, service);
}
-static void DevHostServiceConstruct(struct DevHostService *service)
+void DevHostServiceConstruct(struct DevHostService *service)
{
struct IDevHostService *hostServiceIf = &service->super;
if (hostServiceIf != NULL) {
@@ -169,7 +163,7 @@ static void DevHostServiceConstruct(struct DevHostService *service)
}
}
-static void DevHostServiceDestruct(struct DevHostService *service)
+void DevHostServiceDestruct(struct DevHostService *service)
{
HdfSListFlush(&service->devices, HdfDeviceDelete);
HdfServiceObserverDestruct(&service->observer);
diff --git a/core/host/src/devmgr_service_clnt.c b/core/host/src/devmgr_service_clnt.c
old mode 100755
new mode 100644
index 4991e631..712e2098
--- a/core/host/src/devmgr_service_clnt.c
+++ b/core/host/src/devmgr_service_clnt.c
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#include "devmgr_service_clnt.h"
diff --git a/core/host/src/devsvc_manager_clnt.c b/core/host/src/devsvc_manager_clnt.c
old mode 100755
new mode 100644
index 8d5a61fd..e3ae2142
--- a/core/host/src/devsvc_manager_clnt.c
+++ b/core/host/src/devsvc_manager_clnt.c
@@ -1,36 +1,15 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#include "devsvc_manager_clnt.h"
+#include "devmgr_service.h"
#include "devsvc_manager.h"
+#include "hdf_attribute_manager.h"
#include "hdf_base.h"
#include "hdf_log.h"
#include "hdf_object_manager.h"
@@ -46,7 +25,7 @@ int DevSvcManagerClntAddService(const char *svcName, struct HdfDeviceObject *ser
}
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
- if (serviceManager->AddService == NULL) {
+ if (serviceManager == NULL || serviceManager->AddService == NULL) {
HDF_LOGE("AddService function is not assigned");
return HDF_FAILURE;
}
@@ -62,7 +41,7 @@ const struct HdfObject *DevSvcManagerClntGetService(const char *svcName)
}
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
- if (serviceManager->GetService == NULL) {
+ if (serviceManager == NULL || serviceManager->GetService == NULL) {
HDF_LOGE("GetService function is not assigned");
return NULL;
}
@@ -78,13 +57,39 @@ struct HdfDeviceObject *DevSvcManagerClntGetDeviceObject(const char *svcName)
}
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
- if (serviceManager->GetObject == NULL) {
+ if (serviceManager == NULL || serviceManager->GetObject == NULL) {
HDF_LOGE("GetObject function is not assigned");
return NULL;
}
return serviceManager->GetObject(serviceManager, svcName);
}
+struct HdfDeviceObject *HdfRegisterDevice(const char *moduleName, const char *serviceName)
+{
+ int ret;
+ if (!HdfDeviceListAdd(moduleName, serviceName)) {
+ HDF_LOGE("%s device info add failed!", __func__);
+ return NULL;
+ }
+ ret = DevmgrServiceLoadDevice(serviceName);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s load device %s failed!", __func__, serviceName);
+ HdfDeviceListDel(moduleName, serviceName);
+ return NULL;
+ }
+ return DevSvcManagerClntGetDeviceObject(serviceName);
+}
+
+void HdfUnregisterDevice(const char *moduleName, const char *serviceName)
+{
+ int ret;
+ ret = DevmgrServiceUnLoadDevice(serviceName);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s unload device %s failed!", __func__, serviceName);
+ }
+ HdfDeviceListDel(moduleName, serviceName);
+}
+
int DevSvcManagerClntSubscribeService(const char *svcName, struct SubscriberCallback callback)
{
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
@@ -94,7 +99,7 @@ int DevSvcManagerClntSubscribeService(const char *svcName, struct SubscriberCall
}
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
- if (serviceManager->SubscribeService == NULL) {
+ if (serviceManager == NULL || serviceManager->SubscribeService == NULL) {
HDF_LOGE("SubscribeService function is not assigned");
return HDF_FAILURE;
}
@@ -110,7 +115,7 @@ int DevSvcManagerClntUnsubscribeService(const char *svcName)
}
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
- if (serviceManager->UnsubscribeService == NULL) {
+ if (serviceManager == NULL || serviceManager->UnsubscribeService == NULL) {
HDF_LOGE("UnsubService function is not assigned");
return HDF_FAILURE;
}
@@ -126,7 +131,7 @@ void DevSvcManagerClntRemoveService(const char *svcName)
}
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
- if (serviceManager->RemoveService == NULL) {
+ if (serviceManager == NULL || serviceManager->RemoveService == NULL) {
HDF_LOGE("Remove service function is not assigned");
return;
}
diff --git a/core/host/src/hdf_device.c b/core/host/src/hdf_device.c
old mode 100755
new mode 100644
index 15660ddb..b4f27d19
--- a/core/host/src/hdf_device.c
+++ b/core/host/src/hdf_device.c
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#include "hdf_device.h"
@@ -53,13 +30,13 @@ static int HdfDeviceAttach(struct IHdfDevice *devInst, struct HdfDeviceNode *dev
return nodeIf->LaunchNode(devNode, devInst);
}
-static void HdfDeviceConstruct(struct HdfDevice *device)
+void HdfDeviceConstruct(struct HdfDevice *device)
{
device->super.Attach = HdfDeviceAttach;
HdfSListInit(&device->services);
}
-static void HdfDeviceDestruct(struct HdfDevice *device)
+void HdfDeviceDestruct(struct HdfDevice *device)
{
HdfSListFlush(&device->services, HdfDeviceNodeDelete);
}
diff --git a/core/host/src/hdf_device_node.c b/core/host/src/hdf_device_node.c
old mode 100755
new mode 100644
index a518cc91..4ccd58a1
--- a/core/host/src/hdf_device_node.c
+++ b/core/host/src/hdf_device_node.c
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#include "hdf_device_node.h"
@@ -65,6 +42,7 @@ static int HdfDeviceNodePublishLocalService(
static int HdfDeviceNodePublishService(
struct HdfDeviceNode *devNode, const struct HdfDeviceInfo *deviceInfo, struct IHdfDevice *device)
{
+ (void)device;
int status = HDF_SUCCESS;
if (deviceInfo->policy == SERVICE_POLICY_NONE) {
HDF_LOGI("policy is %d", SERVICE_POLICY_NONE);
@@ -139,7 +117,7 @@ int HdfDeviceNodeAddPowerStateListener(
if (devNode->powerToken == NULL) {
devNode->powerToken = PowerStateTokenNewInstance(&devNode->deviceObject, listener);
}
- return (devNode->powerToken == NULL) ? HDF_SUCCESS : HDF_FAILURE;
+ return (devNode->powerToken != NULL) ? HDF_SUCCESS : HDF_FAILURE;
}
int HdfDeviceNodePublishPublicService(struct HdfDeviceNode *devNode, const char *svcName)
diff --git a/core/host/src/hdf_device_object.c b/core/host/src/hdf_device_object.c
old mode 100755
new mode 100644
index 397f448f..2c109ac3
--- a/core/host/src/hdf_device_object.c
+++ b/core/host/src/hdf_device_object.c
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#include "hdf_device_object.h"
@@ -120,10 +97,21 @@ void HdfDeviceReleaseWakeLock(struct HdfDeviceObject *deviceObject)
}
}
+bool HdfDeviceSetClass(struct HdfDeviceObject *deviceObject, DeviceClass deviceClass)
+{
+ if ((deviceObject == NULL) || (deviceClass >= DEVICE_CLASS_MAX) ||
+ (deviceClass < DEVICE_CLASS_DEFAULT)) {
+ return false;
+ }
+ deviceObject->deviceClass = deviceClass;
+ return true;
+}
+
void HdfDeviceObjectConstruct(struct HdfDeviceObject *deviceObject)
{
if (deviceObject != NULL) {
deviceObject->property = NULL;
deviceObject->service = NULL;
+ deviceObject->deviceClass = DEVICE_CLASS_DEFAULT;
}
}
diff --git a/core/host/src/hdf_device_token.c b/core/host/src/hdf_device_token.c
old mode 100755
new mode 100644
index fd8098dd..3d52d26f
--- a/core/host/src/hdf_device_token.c
+++ b/core/host/src/hdf_device_token.c
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#include "hdf_device_token.h"
diff --git a/core/host/src/hdf_driver_loader.c b/core/host/src/hdf_driver_loader.c
old mode 100755
new mode 100644
index f779c3ad..ec9f7801
--- a/core/host/src/hdf_driver_loader.c
+++ b/core/host/src/hdf_driver_loader.c
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#include "hdf_driver_loader.h"
@@ -36,10 +13,11 @@
#include "hdf_device_node.h"
#include "hdf_log.h"
#include "hdf_object_manager.h"
+#include "hdf_attribute_manager.h"
#define HDF_LOG_TAG driver_loader
-static struct HdfDeviceNode *HdfDriverLoaderLoadNode(
+struct HdfDeviceNode *HdfDriverLoaderLoadNode(
struct IDriverLoader *loader, const struct HdfDeviceInfo *deviceInfo)
{
struct HdfDriverEntry *driverEntry = NULL;
@@ -63,7 +41,7 @@ static struct HdfDeviceNode *HdfDriverLoaderLoadNode(
devNode->driverEntry = driverEntry;
devNode->deviceInfo = deviceInfo;
- devNode->deviceObject.property = HcsGetNodeByMatchAttr(HcsGetRootNode(), deviceInfo->deviceMatchAttr);
+ devNode->deviceObject.property = HcsGetNodeByMatchAttr(HdfGetRootNode(), deviceInfo->deviceMatchAttr);
if (devNode->deviceObject.property == NULL) {
HDF_LOGW("Get property is null, match attr is: %s", deviceInfo->deviceMatchAttr);
}
diff --git a/core/host/src/hdf_observer_record.c b/core/host/src/hdf_observer_record.c
old mode 100755
new mode 100644
index b0dc8847..d75f5c95
--- a/core/host/src/hdf_observer_record.c
+++ b/core/host/src/hdf_observer_record.c
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#include "hdf_observer_record.h"
diff --git a/core/host/src/hdf_service_observer.c b/core/host/src/hdf_service_observer.c
old mode 100755
new mode 100644
index c68089a1..52bafee2
--- a/core/host/src/hdf_service_observer.c
+++ b/core/host/src/hdf_service_observer.c
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#include "hdf_service_observer.h"
diff --git a/core/host/src/hdf_service_subscriber.c b/core/host/src/hdf_service_subscriber.c
old mode 100755
new mode 100644
index 14b31c86..6307977e
--- a/core/host/src/hdf_service_subscriber.c
+++ b/core/host/src/hdf_service_subscriber.c
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#include "osal_mem.h"
diff --git a/core/host/src/power_state_token.c b/core/host/src/power_state_token.c
old mode 100755
new mode 100644
index 441b42a4..41702590
--- a/core/host/src/power_state_token.c
+++ b/core/host/src/power_state_token.c
@@ -1,159 +1,136 @@
-/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, 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.
- */
-
-#include "power_state_token.h"
-#include "devmgr_service_clnt.h"
-#include "hdf_device_desc.h"
-#include "hdf_slist.h"
-#include "osal_mem.h"
-
-static void PowerStateTokenAcqureWakeLock(struct IPowerStateToken *token)
-{
- struct HdfSRef *sref = NULL;
- struct PowerStateToken *stateToken = (struct PowerStateToken *)token;
- if (stateToken == NULL) {
- return;
- }
- sref = (struct HdfSRef *)&stateToken->wakeRef;
- if ((sref != NULL) && (sref->Acquire != NULL)) {
- sref->Acquire(sref);
- }
-}
-
-static void PowerStateTokenReleaseWakeLock(struct IPowerStateToken *token)
-{
- struct HdfSRef *sref = NULL;
- struct PowerStateToken *stateToken = (struct PowerStateToken *)token;
- if (stateToken == NULL) {
- return;
- }
- sref = (struct HdfSRef *)&stateToken->wakeRef;
- if ((sref != NULL) && (sref->Release != NULL)) {
- sref->Release(sref);
- }
-}
-
-static void PowerStateTokenOnFirstAcquire(struct HdfSRef *sref)
-{
- if (sref == NULL) {
- return;
- }
- struct PowerStateToken *stateToken = (struct PowerStateToken *)HDF_SLIST_CONTAINER_OF(
- struct HdfSRef, sref, struct PowerStateToken, wakeRef);
- if (stateToken->state != POWER_STATE_ACTIVE) {
- struct IDevmgrService *devMgrSvcIf = NULL;
- struct IPowerEventListener* listener = stateToken->listener;
- struct DevmgrServiceClnt *inst = DevmgrServiceClntGetInstance();
- if (inst == NULL) {
- return;
- }
- devMgrSvcIf = (struct IDevmgrService *)inst->devMgrSvcIf;
- if (devMgrSvcIf->AcquireWakeLock == NULL) {
- return;
- }
- devMgrSvcIf->AcquireWakeLock(devMgrSvcIf, &stateToken->super);
- if (stateToken->state == POWER_STATE_INACTIVE) {
- if ((listener != NULL) && (listener->Resume != NULL)) {
- listener->Resume(stateToken->deviceObject);
- }
- }
- stateToken->state = POWER_STATE_ACTIVE;
- }
-}
-
-static void PowerStateTokenOnLastRelease(struct HdfSRef *sref)
-{
- if (sref == NULL) {
- return;
- }
- struct PowerStateToken *stateToken = (struct PowerStateToken *)HDF_SLIST_CONTAINER_OF(
- struct HdfSRef, sref, struct PowerStateToken, wakeRef);
- if (stateToken->state == POWER_STATE_ACTIVE) {
- struct IDevmgrService *devMgrSvcIf = NULL;
- struct IPowerEventListener *listener = stateToken->listener;
- struct DevmgrServiceClnt *inst = DevmgrServiceClntGetInstance();
- if (inst == NULL) {
- return;
- }
- devMgrSvcIf = (struct IDevmgrService *)inst->devMgrSvcIf;
- if ((devMgrSvcIf == NULL) || (devMgrSvcIf->AcquireWakeLock == NULL)) {
- return;
- }
- devMgrSvcIf->ReleaseWakeLock(devMgrSvcIf, &stateToken->super);
- if ((listener != NULL) && (listener->Suspend != NULL)) {
- listener->Suspend(stateToken->deviceObject);
- }
- stateToken->state = POWER_STATE_INACTIVE;
- }
-}
-
-static void PowerStateTokenConstruct(
- struct PowerStateToken *powerStateToken, struct HdfDeviceObject *deviceObject, struct IPowerEventListener *listener)
-{
- struct IPowerStateToken *tokenIf = (struct IPowerStateToken *)powerStateToken;
- struct IHdfSRefListener *srefListener = (struct IHdfSRefListener *)OsalMemCalloc(sizeof(struct IHdfSRefListener));
- if (srefListener == NULL) {
- return;
- }
-
- tokenIf->AcquireWakeLock = PowerStateTokenAcqureWakeLock;
- tokenIf->ReleaseWakeLock = PowerStateTokenReleaseWakeLock;
-
- srefListener->OnFirstAcquire = PowerStateTokenOnFirstAcquire;
- srefListener->OnLastRelease = PowerStateTokenOnLastRelease;
-
- powerStateToken->state = POWER_STATE_IDLE;
- powerStateToken->listener = listener;
- powerStateToken->deviceObject = deviceObject;
- HdfSRefConstruct(&powerStateToken->wakeRef, srefListener);
-}
-
-struct PowerStateToken *PowerStateTokenNewInstance(
- struct HdfDeviceObject *deviceObject, struct IPowerEventListener *listener)
-{
- struct PowerStateToken *stateToken =
- (struct PowerStateToken *)OsalMemCalloc(sizeof(struct PowerStateToken));
- if (stateToken != NULL) {
- PowerStateTokenConstruct(stateToken, deviceObject, listener);
- }
- return stateToken;
-}
-
-void PowerStateTokenFreeInstance(struct PowerStateToken *stateToken)
-{
- if (stateToken != NULL) {
- if (stateToken->wakeRef.listener != NULL) {
- OsalMemFree(stateToken->wakeRef.listener);
- stateToken->wakeRef.listener = NULL;
- }
- OsalMemFree(stateToken);
- }
-}
+/*
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include "power_state_token.h"
+#include "devmgr_service_clnt.h"
+#include "hdf_device_desc.h"
+#include "hdf_slist.h"
+#include "osal_mem.h"
+
+static void PowerStateTokenAcqureWakeLock(struct IPowerStateToken *token)
+{
+ struct HdfSRef *sref = NULL;
+ struct PowerStateToken *stateToken = (struct PowerStateToken *)token;
+ if (stateToken == NULL) {
+ return;
+ }
+ sref = (struct HdfSRef *)&stateToken->wakeRef;
+ if ((sref != NULL) && (sref->Acquire != NULL)) {
+ sref->Acquire(sref);
+ }
+}
+
+static void PowerStateTokenReleaseWakeLock(struct IPowerStateToken *token)
+{
+ struct HdfSRef *sref = NULL;
+ struct PowerStateToken *stateToken = (struct PowerStateToken *)token;
+ if (stateToken == NULL) {
+ return;
+ }
+ sref = (struct HdfSRef *)&stateToken->wakeRef;
+ if ((sref != NULL) && (sref->Release != NULL)) {
+ sref->Release(sref);
+ }
+}
+
+static void PowerStateTokenOnFirstAcquire(struct HdfSRef *sref)
+{
+ if (sref == NULL) {
+ return;
+ }
+ struct PowerStateToken *stateToken = (struct PowerStateToken *)HDF_SLIST_CONTAINER_OF(
+ struct HdfSRef, sref, struct PowerStateToken, wakeRef);
+ if (stateToken->state != POWER_STATE_ACTIVE) {
+ struct IDevmgrService *devMgrSvcIf = NULL;
+ struct IPowerEventListener* listener = stateToken->listener;
+ struct DevmgrServiceClnt *inst = DevmgrServiceClntGetInstance();
+ if (inst == NULL) {
+ return;
+ }
+ devMgrSvcIf = (struct IDevmgrService *)inst->devMgrSvcIf;
+ if (devMgrSvcIf == NULL || devMgrSvcIf->AcquireWakeLock == NULL) {
+ return;
+ }
+ devMgrSvcIf->AcquireWakeLock(devMgrSvcIf, &stateToken->super);
+ if (stateToken->state == POWER_STATE_INACTIVE) {
+ if ((listener != NULL) && (listener->Resume != NULL)) {
+ listener->Resume(stateToken->deviceObject);
+ }
+ }
+ stateToken->state = POWER_STATE_ACTIVE;
+ }
+}
+
+static void PowerStateTokenOnLastRelease(struct HdfSRef *sref)
+{
+ if (sref == NULL) {
+ return;
+ }
+ struct PowerStateToken *stateToken = (struct PowerStateToken *)HDF_SLIST_CONTAINER_OF(
+ struct HdfSRef, sref, struct PowerStateToken, wakeRef);
+ if (stateToken->state == POWER_STATE_ACTIVE) {
+ struct IDevmgrService *devMgrSvcIf = NULL;
+ struct IPowerEventListener *listener = stateToken->listener;
+ struct DevmgrServiceClnt *inst = DevmgrServiceClntGetInstance();
+ if (inst == NULL) {
+ return;
+ }
+ devMgrSvcIf = (struct IDevmgrService *)inst->devMgrSvcIf;
+ if ((devMgrSvcIf == NULL) || (devMgrSvcIf->AcquireWakeLock == NULL)) {
+ return;
+ }
+ devMgrSvcIf->ReleaseWakeLock(devMgrSvcIf, &stateToken->super);
+ if ((listener != NULL) && (listener->Suspend != NULL)) {
+ listener->Suspend(stateToken->deviceObject);
+ }
+ stateToken->state = POWER_STATE_INACTIVE;
+ }
+}
+
+static void PowerStateTokenConstruct(
+ struct PowerStateToken *powerStateToken, struct HdfDeviceObject *deviceObject, struct IPowerEventListener *listener)
+{
+ struct IPowerStateToken *tokenIf = &powerStateToken->super;
+ struct IHdfSRefListener *srefListener = (struct IHdfSRefListener *)OsalMemCalloc(sizeof(struct IHdfSRefListener));
+ if (srefListener == NULL) {
+ return;
+ }
+
+ tokenIf->AcquireWakeLock = PowerStateTokenAcqureWakeLock;
+ tokenIf->ReleaseWakeLock = PowerStateTokenReleaseWakeLock;
+
+ srefListener->OnFirstAcquire = PowerStateTokenOnFirstAcquire;
+ srefListener->OnLastRelease = PowerStateTokenOnLastRelease;
+
+ powerStateToken->state = POWER_STATE_IDLE;
+ powerStateToken->listener = listener;
+ powerStateToken->deviceObject = deviceObject;
+ HdfSRefConstruct(&powerStateToken->wakeRef, srefListener);
+}
+
+struct PowerStateToken *PowerStateTokenNewInstance(
+ struct HdfDeviceObject *deviceObject, struct IPowerEventListener *listener)
+{
+ struct PowerStateToken *stateToken =
+ (struct PowerStateToken *)OsalMemCalloc(sizeof(struct PowerStateToken));
+ if (stateToken != NULL) {
+ PowerStateTokenConstruct(stateToken, deviceObject, listener);
+ }
+ return stateToken;
+}
+
+void PowerStateTokenFreeInstance(struct PowerStateToken *stateToken)
+{
+ if (stateToken != NULL) {
+ if (stateToken->wakeRef.listener != NULL) {
+ OsalMemFree(stateToken->wakeRef.listener);
+ stateToken->wakeRef.listener = NULL;
+ }
+ OsalMemFree(stateToken);
+ }
+}
diff --git a/core/manager/include/devhost_service_clnt.h b/core/manager/include/devhost_service_clnt.h
old mode 100755
new mode 100644
index d38c98b3..3a641297
--- a/core/manager/include/devhost_service_clnt.h
+++ b/core/manager/include/devhost_service_clnt.h
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#ifndef DEVHOST_SERVICE_CLNT_H
@@ -40,6 +17,7 @@ struct DevHostServiceClnt {
struct HdfSList devices;
struct HdfSList *deviceInfos;
struct IDevHostService *hostService;
+ uint16_t devCount;
uint16_t hostId;
int hostPid;
const char *hostName;
diff --git a/core/manager/include/device_token_clnt.h b/core/manager/include/device_token_clnt.h
old mode 100755
new mode 100644
index 047ed729..818bba94
--- a/core/manager/include/device_token_clnt.h
+++ b/core/manager/include/device_token_clnt.h
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#ifndef DEVICE_TOKEN_CLNT_H
diff --git a/core/manager/include/devmgr_service.h b/core/manager/include/devmgr_service.h
old mode 100755
new mode 100644
index 2fd02601..1d255d18
--- a/core/manager/include/devmgr_service.h
+++ b/core/manager/include/devmgr_service.h
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#ifndef DEVICE_MANAGER_SERVICE_H
@@ -43,11 +20,13 @@ struct DevmgrService {
};
int DevmgrServiceStartService(struct IDevmgrService *inst);
+bool DevmgrServiceConstruct(struct DevmgrService *inst);
struct HdfObject *DevmgrServiceCreate(void);
void DevmgrServiceRelease(struct HdfObject *object);
struct IDevmgrService *DevmgrServiceGetInstance(void);
int DevmgrServiceLoadDevice(const char *svcName);
int DevmgrServiceUnLoadDevice(const char *svcName);
+int32_t DevmgrServiceLoadLeftDriver(struct DevmgrService *devMgrSvc);
void DevmgrServiceAcquireWakeLock(struct IDevmgrService *inst, struct IPowerStateToken *tokenIf);
void DevmgrServiceReleaseWakeLock(struct IDevmgrService *inst, struct IPowerStateToken *tokenIf);
diff --git a/core/manager/include/devsvc_manager.h b/core/manager/include/devsvc_manager.h
old mode 100755
new mode 100644
index 65829a59..658fd49e
--- a/core/manager/include/devsvc_manager.h
+++ b/core/manager/include/devsvc_manager.h
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#ifndef DEVICE_SERVICE_MANAGER_H
@@ -45,6 +22,7 @@ struct DevSvcManager {
};
struct HdfObject *DevSvcManagerCreate(void);
+bool DevSvcManagerConstruct(struct DevSvcManager *inst);
void DevSvcManagerRelease(struct HdfObject *object);
struct IDevSvcManager *DevSvcManagerGetInstance(void);
int DevSvcManagerAddService(struct IDevSvcManager *manager, const char *svcName, struct HdfDeviceObject *service);
diff --git a/core/manager/include/devsvc_manager_stub.h b/core/manager/include/devsvc_manager_stub.h
deleted file mode 100755
index ef8b7856..00000000
--- a/core/manager/include/devsvc_manager_stub.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, 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 DEVSVC_MANAGER_STUB_H
-#define DEVSVC_MANAGER_STUB_H
-
-#include "hdf_device_desc.h"
-
-int DevSvcManagerClntSubscribeService(const char *svcName, struct SubscriberCallback callback);
-int DevSvcManagerClntUnsubscribeService(const char *svcName);
-
-#endif /* DEVSVC_MANAGER_STUB_H */
-
diff --git a/core/manager/include/hdf_driver_installer.h b/core/manager/include/hdf_driver_installer.h
old mode 100755
new mode 100644
index fed4dfb9..d21ab365
--- a/core/manager/include/hdf_driver_installer.h
+++ b/core/manager/include/hdf_driver_installer.h
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#ifndef HDF_DRIVER_INSTALLER_H
diff --git a/core/manager/include/hdf_host_info.h b/core/manager/include/hdf_host_info.h
old mode 100755
new mode 100644
index 6fe5e57d..a607e412
--- a/core/manager/include/hdf_host_info.h
+++ b/core/manager/include/hdf_host_info.h
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#ifndef HDF_HOST_INFO_H
diff --git a/core/manager/include/power_state_manager.h b/core/manager/include/power_state_manager.h
old mode 100755
new mode 100644
index 186db047..0cf87de3
--- a/core/manager/include/power_state_manager.h
+++ b/core/manager/include/power_state_manager.h
@@ -1,48 +1,25 @@
-/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, 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 POWER_STATE_MANAGER_H
-#define POWER_STATE_MANAGER_H
-
-#include "hdf_sref.h"
-#include "hdf_slist.h"
-#include "power_state_token_if.h"
-
-struct PowerStateManager {
- struct HdfSRef wakeRef;
- struct HdfSList tokens;
- void (*AcquireWakeLock)(struct PowerStateManager *, struct IPowerStateToken *);
- void (*ReleaseWakeLock)(struct PowerStateManager *, struct IPowerStateToken *);
-};
-
-struct PowerStateManager *PowerStateManagerGetInstance(void);
-
+/*
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#ifndef POWER_STATE_MANAGER_H
+#define POWER_STATE_MANAGER_H
+
+#include "hdf_sref.h"
+#include "hdf_slist.h"
+#include "power_state_token_if.h"
+
+struct PowerStateManager {
+ struct HdfSRef wakeRef;
+ struct HdfSList tokens;
+ void (*AcquireWakeLock)(struct PowerStateManager *, struct IPowerStateToken *);
+ void (*ReleaseWakeLock)(struct PowerStateManager *, struct IPowerStateToken *);
+};
+
+struct PowerStateManager *PowerStateManagerGetInstance(void);
+
#endif /* POWER_STATE_MANAGER_H */
\ No newline at end of file
diff --git a/core/manager/include/power_state_token_clnt.h b/core/manager/include/power_state_token_clnt.h
old mode 100755
new mode 100644
index cd963cbb..ba700d8b
--- a/core/manager/include/power_state_token_clnt.h
+++ b/core/manager/include/power_state_token_clnt.h
@@ -1,48 +1,25 @@
-/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, 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 POWER_STATE_TOKEN_CLNT_H
-#define POWER_STATE_TOKEN_CLNT_H
-
-#include "hdf_slist.h"
-#include "power_state_token_if.h"
-
-struct PowerStateTokenClnt {
- struct HdfSListNode entry;
- HdfPowerState powerState;
- struct IPowerStateToken* tokenIf;
-};
-
-struct PowerStateTokenClnt *PowerStateTokenClntNewInstance(struct IPowerStateToken *tokenIf);
-void PowerStateTokenClntFreeInstance(struct PowerStateTokenClnt *tokenClnt);
-
+/*
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+
+#ifndef POWER_STATE_TOKEN_CLNT_H
+#define POWER_STATE_TOKEN_CLNT_H
+
+#include "hdf_slist.h"
+#include "power_state_token_if.h"
+
+struct PowerStateTokenClnt {
+ struct HdfSListNode entry;
+ HdfPowerState powerState;
+ struct IPowerStateToken* tokenIf;
+};
+
+struct PowerStateTokenClnt *PowerStateTokenClntNewInstance(struct IPowerStateToken *tokenIf);
+void PowerStateTokenClntFreeInstance(struct PowerStateTokenClnt *tokenClnt);
+
#endif /* POWER_STATE_TOKEN_CLNT_H */
\ No newline at end of file
diff --git a/core/manager/src/devhost_service_clnt.c b/core/manager/src/devhost_service_clnt.c
old mode 100755
new mode 100644
index 5d9d5262..ee31bab4
--- a/core/manager/src/devhost_service_clnt.c
+++ b/core/manager/src/devhost_service_clnt.c
@@ -1,36 +1,14 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#include "device_token_clnt.h"
#include "devhost_service_clnt.h"
+#include "devmgr_service_start.h"
#include "hdf_base.h"
#include "hdf_driver_installer.h"
#include "hdf_log.h"
@@ -57,7 +35,11 @@ int DevHostServiceClntInstallDriver(struct DevHostServiceClnt *hostClnt)
HdfSListIteratorInit(&it, hostClnt->deviceInfos);
while (HdfSListIteratorHasNext(&it)) {
deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&it);
- if ((deviceInfo == NULL) || (deviceInfo->preload != DEVICE_PRELOAD_ENABLE)) {
+ if ((deviceInfo == NULL) || (deviceInfo->preload == DEVICE_PRELOAD_DISABLE)) {
+ continue;
+ }
+ if ((DeviceManagerIsQuickLoad() == DEV_MGR_QUICK_LOAD) &&
+ (deviceInfo->preload == DEVICE_PRELOAD_ENABLE_STEP2)) {
continue;
}
ret = devHostSvcIf->AddDevice(devHostSvcIf, deviceInfo);
@@ -80,6 +62,7 @@ struct DevHostServiceClnt *DevHostServiceClntNewInstance(uint16_t hostId, const
if (hostClnt != NULL) {
hostClnt->hostId = hostId;
hostClnt->hostName = hostName;
+ hostClnt->devCount = 0;
DevHostServiceClntConstruct(hostClnt);
}
return hostClnt;
diff --git a/core/manager/src/device_token_clnt.c b/core/manager/src/device_token_clnt.c
old mode 100755
new mode 100644
index f90d7f5a..e912a5c8
--- a/core/manager/src/device_token_clnt.c
+++ b/core/manager/src/device_token_clnt.c
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#include "device_token_clnt.h"
diff --git a/core/manager/src/devmgr_service.c b/core/manager/src/devmgr_service.c
old mode 100755
new mode 100644
index d6d5d0c0..3472cf9e
--- a/core/manager/src/devmgr_service.c
+++ b/core/manager/src/devmgr_service.c
@@ -1,36 +1,12 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#include "devmgr_service.h"
-#include
#include "devhost_service_clnt.h"
#include "device_token_clnt.h"
#include "hdf_attribute_manager.h"
@@ -47,16 +23,18 @@
static int DevmgrServiceActiveDevice(struct DevHostServiceClnt *hostClnt, struct HdfDeviceInfo *deviceInfo, bool isLoad)
{
struct IDevHostService *devHostSvcIf = (struct IDevHostService *)hostClnt->hostService;
- if (isLoad) {
+ if (isLoad && (deviceInfo->preload != DEVICE_PRELOAD_ENABLE)) {
int ret = devHostSvcIf->AddDevice(devHostSvcIf, deviceInfo);
if (ret == HDF_SUCCESS) {
deviceInfo->preload = DEVICE_PRELOAD_ENABLE;
}
return ret;
- } else {
+ } else if (!isLoad && (deviceInfo->preload != DEVICE_PRELOAD_DISABLE)) {
devHostSvcIf->DelDevice(devHostSvcIf, deviceInfo);
deviceInfo->preload = DEVICE_PRELOAD_DISABLE;
return HDF_SUCCESS;
+ } else {
+ return HDF_FAILURE;
}
}
@@ -68,6 +46,31 @@ static int DevmgrServiceFindAndActiveDevice(const char *svcName, bool isLoad)
struct DevHostServiceClnt *hostClnt = NULL;
struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
if (devMgrSvc == NULL || svcName == NULL) {
+ return HDF_ERR_INVALID_PARAM;
+ }
+
+ HdfSListIteratorInit(&itHost, &devMgrSvc->hosts);
+ while (HdfSListIteratorHasNext(&itHost)) {
+ hostClnt = (struct DevHostServiceClnt *)HdfSListIteratorNext(&itHost);
+ HdfSListIteratorInit(&itDeviceInfo, hostClnt->deviceInfos);
+ while (HdfSListIteratorHasNext(&itDeviceInfo)) {
+ deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo);
+ if (strcmp(deviceInfo->svcName, svcName) == 0) {
+ return DevmgrServiceActiveDevice(hostClnt, deviceInfo, isLoad);
+ }
+ }
+ }
+ return HDF_FAILURE;
+}
+
+int32_t DevmgrServiceLoadLeftDriver(struct DevmgrService *devMgrSvc)
+{
+ int32_t ret;
+ struct HdfSListIterator itHost;
+ struct HdfSListIterator itDeviceInfo;
+ struct HdfDeviceInfo *deviceInfo = NULL;
+ struct DevHostServiceClnt *hostClnt = NULL;
+ if (devMgrSvc == NULL) {
return HDF_FAILURE;
}
@@ -77,15 +80,18 @@ static int DevmgrServiceFindAndActiveDevice(const char *svcName, bool isLoad)
HdfSListIteratorInit(&itDeviceInfo, hostClnt->deviceInfos);
while (HdfSListIteratorHasNext(&itDeviceInfo)) {
deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo);
- if ((strcmp(deviceInfo->svcName, svcName) == 0) && (deviceInfo->preload == DEVICE_PRELOAD_DISABLE)) {
- return DevmgrServiceActiveDevice(hostClnt, deviceInfo, isLoad);
+ if (deviceInfo->preload == DEVICE_PRELOAD_ENABLE_STEP2) {
+ ret = DevmgrServiceActiveDevice(hostClnt, deviceInfo, true);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("%s load driver %s failed!", __func__, deviceInfo->moduleName);
+ }
}
}
}
- HDF_LOGE("Find %s deviceInfo failed, active is: %u", svcName, isLoad);
- return HDF_FAILURE;
+ return HDF_SUCCESS;
}
+
int DevmgrServiceLoadDevice(const char *svcName)
{
return DevmgrServiceFindAndActiveDevice(svcName, true);
@@ -156,6 +162,7 @@ static int DevmgrServiceAttachDeviceHost(
HDF_LOGE("Get device list failed");
return HDF_FAILURE;
}
+ hostClnt->devCount = HdfSListCount(hostClnt->deviceInfos);
hostClnt->hostService = hostService;
return DevHostServiceClntInstallDriver(hostClnt);
}
@@ -174,8 +181,8 @@ static int DevmgrServiceStartDeviceHosts(struct DevmgrService *inst)
}
HdfSListInit(&hostList);
if (!HdfAttributeManagerGetHostList(&hostList)) {
- HDF_LOGW("Get device host list failed");
- return HDF_FAILURE;
+ HDF_LOGW("%s get host list is null", __func__);
+ return HDF_SUCCESS;
}
HdfSListIteratorInit(&it, &hostList);
while (HdfSListIteratorHasNext(&it)) {
@@ -207,7 +214,7 @@ int DevmgrServiceStartService(struct IDevmgrService *inst)
return DevmgrServiceStartDeviceHosts(dmService);
}
-static bool DevmgrServiceConstruct(struct DevmgrService *inst)
+bool DevmgrServiceConstruct(struct DevmgrService *inst)
{
if (OsalMutexInit(&inst->devMgrMutex) != HDF_SUCCESS) {
HDF_LOGE("%s mutex init failed", __func__);
@@ -260,6 +267,7 @@ void DevmgrServiceRelease(struct HdfObject *object)
void DevmgrServiceAcquireWakeLock(struct IDevmgrService *inst, struct IPowerStateToken *tokenIf)
{
+ (void)inst;
struct PowerStateManager *stateManager = PowerStateManagerGetInstance();
if ((stateManager != NULL) && (stateManager->AcquireWakeLock != NULL)) {
stateManager->AcquireWakeLock(stateManager, tokenIf);
@@ -268,6 +276,7 @@ void DevmgrServiceAcquireWakeLock(struct IDevmgrService *inst, struct IPowerStat
void DevmgrServiceReleaseWakeLock(struct IDevmgrService *inst, struct IPowerStateToken *tokenIf)
{
+ (void)inst;
struct PowerStateManager *stateManager = PowerStateManagerGetInstance();
if ((stateManager != NULL) && (stateManager->ReleaseWakeLock != NULL)) {
stateManager->ReleaseWakeLock(stateManager, tokenIf);
diff --git a/core/manager/src/devsvc_manager.c b/core/manager/src/devsvc_manager.c
old mode 100755
new mode 100644
index 4cdb93f4..7feac34c
--- a/core/manager/src/devsvc_manager.c
+++ b/core/manager/src/devsvc_manager.c
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#include "devsvc_manager.h"
@@ -82,8 +59,7 @@ int DevSvcManagerAddService(struct IDevSvcManager *inst, const char *svcName, st
OsalMutexLock(&devSvcManager->mutex);
HdfSListAdd(&devSvcManager->services, &record->entry);
OsalMutexUnlock(&devSvcManager->mutex);
- return HdfServiceObserverPublishService(
- &devSvcManager->observer, svcName, 0, SERVICE_POLICY_PUBLIC, (struct HdfObject *)service->service);
+ return HDF_SUCCESS;
}
int DevSvcManagerSubscribeService(struct IDevSvcManager *inst, const char *svcName, struct SubscriberCallback callBack)
@@ -94,11 +70,6 @@ int DevSvcManagerSubscribeService(struct IDevSvcManager *inst, const char *svcNa
return ret;
}
- ret = HdfServiceObserverSubscribeService(&devSvcMgr->observer, svcName, 0, callBack);
- if (ret != HDF_SUCCESS) {
- return ret;
- }
-
struct HdfObject *deviceService = DevSvcManagerGetService(inst, svcName);
if (deviceService != NULL) {
if (callBack.OnServiceConnected != NULL) {
@@ -110,17 +81,6 @@ int DevSvcManagerSubscribeService(struct IDevSvcManager *inst, const char *svcNa
return DevmgrServiceLoadDevice(svcName);
}
-int DevSvcManagerUnsubscribeService(struct IDevSvcManager *inst, const char *svcName)
-{
- struct DevSvcManager *devSvcMgr = (struct DevSvcManager *)inst;
- if (devSvcMgr == NULL) {
- return HDF_FAILURE;
- }
- HdfServiceObserverRemoveRecord(&devSvcMgr->observer, svcName);
- return HDF_SUCCESS;
-}
-
-
void DevSvcManagerRemoveService(struct IDevSvcManager *inst, const char *svcName)
{
struct DevSvcManager *devSvcManager = (struct DevSvcManager *)inst;
@@ -147,7 +107,6 @@ struct HdfDeviceObject *DevSvcManagerGetObject(struct IDevSvcManager *inst, cons
if (serviceRecord != NULL) {
return serviceRecord->value;
}
- HDF_LOGE("Get object failed, serviceRecord is null, svcName is %s", svcName);
return NULL;
}
@@ -155,18 +114,21 @@ struct HdfObject *DevSvcManagerGetService(struct IDevSvcManager *inst, const cha
{
struct HdfDeviceObject *deviceObject = DevSvcManagerGetObject(inst, svcName);
if (deviceObject == NULL) {
- HDF_LOGE("Get service failed");
return NULL;
}
return (struct HdfObject *)deviceObject->service;
}
-static bool DevSvcManagerConstruct(struct DevSvcManager *inst)
+bool DevSvcManagerConstruct(struct DevSvcManager *inst)
{
+ if (inst == NULL) {
+ HDF_LOGE("%s: inst is null!", __func__);
+ return false;
+ }
struct IDevSvcManager *devSvcMgrIf = &inst->super;
devSvcMgrIf->AddService = DevSvcManagerAddService;
devSvcMgrIf->SubscribeService = DevSvcManagerSubscribeService;
- devSvcMgrIf->UnsubscribeService = DevSvcManagerUnsubscribeService;
+ devSvcMgrIf->UnsubscribeService = NULL;
devSvcMgrIf->RemoveService = DevSvcManagerRemoveService;
devSvcMgrIf->GetService = DevSvcManagerGetService;
devSvcMgrIf->GetObject = DevSvcManagerGetObject;
diff --git a/core/manager/src/hdf_driver_installer.c b/core/manager/src/hdf_driver_installer.c
old mode 100755
new mode 100644
index b199b7fe..df91b52a
--- a/core/manager/src/hdf_driver_installer.c
+++ b/core/manager/src/hdf_driver_installer.c
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#include "hdf_driver_installer.h"
diff --git a/core/manager/src/hdf_host_info.c b/core/manager/src/hdf_host_info.c
old mode 100755
new mode 100644
index 70e9126a..cf5b79c6
--- a/core/manager/src/hdf_host_info.c
+++ b/core/manager/src/hdf_host_info.c
@@ -1,32 +1,9 @@
/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
- * 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.
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
*/
#include "hdf_host_info.h"
diff --git a/core/manager/src/power_state_manager.c b/core/manager/src/power_state_manager.c
old mode 100755
new mode 100644
index 700453c7..99e02f50
--- a/core/manager/src/power_state_manager.c
+++ b/core/manager/src/power_state_manager.c
@@ -1,107 +1,84 @@
-/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, 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.
- */
-
-#include "power_state_manager.h"
-#include "hdf_object_manager.h"
-#include "power_state_token_clnt.h"
-
-static struct PowerStateTokenClnt *PowerStateManagerGetStateTokenClnt(
- struct PowerStateManager *inst, struct IPowerStateToken *tokenIf)
-{
- struct HdfSListIterator it;
- if (inst == NULL) {
- return NULL;
- }
- HdfSListIteratorInit(&it, &inst->tokens);
- while (HdfSListIteratorHasNext(&it)) {
- struct PowerStateTokenClnt *tokenClnt =
- (struct PowerStateTokenClnt *)HdfSListIteratorNext(&it);
- if (tokenClnt->tokenIf == tokenIf) {
- return tokenClnt;
- }
- }
- return NULL;
-}
-
-static void PowerStateManagerAcquireWakeLock(
- struct PowerStateManager *inst, struct IPowerStateToken *tokenIf)
-{
- if (inst == NULL) {
- return;
- }
- struct HdfSRef *sref = &inst->wakeRef;
- struct PowerStateTokenClnt *stateTokeClnt = PowerStateManagerGetStateTokenClnt(inst, tokenIf);
- if (stateTokeClnt == NULL) {
- return;
- }
- stateTokeClnt->powerState = POWER_STATE_ACTIVE;
- if (sref->Acquire != NULL) {
- sref->Acquire(sref);
- }
-}
-
-static void PowerStateManagerReleaseWakeLock(
- struct PowerStateManager *inst, struct IPowerStateToken *tokenIf)
-{
- struct HdfSRef *sref = NULL;
- struct PowerStateTokenClnt *stateTokeClnt = PowerStateManagerGetStateTokenClnt(inst, tokenIf);
- if (inst == NULL || stateTokeClnt == NULL) {
- return;
- }
- stateTokeClnt->powerState = POWER_STATE_INACTIVE;
- sref = &inst->wakeRef;
- if (sref->Release != NULL) {
- sref->Release(sref);
- }
-}
-
-static void PowerStateManagerConstruct(struct PowerStateManager *inst)
-{
- // not support system acquire and release
- static struct IHdfSRefListener wakeLockRefListener = {
- .OnFirstAcquire = NULL,
- .OnLastRelease = NULL,
- };
-
- inst->AcquireWakeLock = PowerStateManagerAcquireWakeLock;
- inst->ReleaseWakeLock = PowerStateManagerReleaseWakeLock;
- HdfSListInit(&inst->tokens);
- HdfSRefConstruct(&inst->wakeRef, &wakeLockRefListener);
-}
-
-struct PowerStateManager *PowerStateManagerGetInstance()
-{
- static struct PowerStateManager powerStateManager = { 0 };
- if (powerStateManager.AcquireWakeLock == NULL) {
- PowerStateManagerConstruct(&powerStateManager);
- }
- return &powerStateManager;
-}
+/*
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include "power_state_manager.h"
+#include "hdf_object_manager.h"
+#include "power_state_token_clnt.h"
+
+static struct PowerStateTokenClnt *PowerStateManagerGetStateTokenClnt(
+ struct PowerStateManager *inst, struct IPowerStateToken *tokenIf)
+{
+ struct HdfSListIterator it;
+ if (inst == NULL) {
+ return NULL;
+ }
+ HdfSListIteratorInit(&it, &inst->tokens);
+ while (HdfSListIteratorHasNext(&it)) {
+ struct PowerStateTokenClnt *tokenClnt =
+ (struct PowerStateTokenClnt *)HdfSListIteratorNext(&it);
+ if (tokenClnt->tokenIf == tokenIf) {
+ return tokenClnt;
+ }
+ }
+ return NULL;
+}
+
+static void PowerStateManagerAcquireWakeLock(
+ struct PowerStateManager *inst, struct IPowerStateToken *tokenIf)
+{
+ if (inst == NULL) {
+ return;
+ }
+ struct HdfSRef *sref = &inst->wakeRef;
+ struct PowerStateTokenClnt *stateTokenClnt = PowerStateManagerGetStateTokenClnt(inst, tokenIf);
+ if (stateTokenClnt == NULL) {
+ return;
+ }
+ stateTokenClnt->powerState = POWER_STATE_ACTIVE;
+ if (sref->Acquire != NULL) {
+ sref->Acquire(sref);
+ }
+}
+
+static void PowerStateManagerReleaseWakeLock(
+ struct PowerStateManager *inst, struct IPowerStateToken *tokenIf)
+{
+ struct HdfSRef *sref = NULL;
+ struct PowerStateTokenClnt *stateTokenClnt = PowerStateManagerGetStateTokenClnt(inst, tokenIf);
+ if (inst == NULL || stateTokenClnt == NULL) {
+ return;
+ }
+ stateTokenClnt->powerState = POWER_STATE_INACTIVE;
+ sref = &inst->wakeRef;
+ if (sref->Release != NULL) {
+ sref->Release(sref);
+ }
+}
+
+static void PowerStateManagerConstruct(struct PowerStateManager *inst)
+{
+ // not support system acquire and release
+ static struct IHdfSRefListener wakeLockRefListener = {
+ .OnFirstAcquire = NULL,
+ .OnLastRelease = NULL,
+ };
+
+ inst->AcquireWakeLock = PowerStateManagerAcquireWakeLock;
+ inst->ReleaseWakeLock = PowerStateManagerReleaseWakeLock;
+ HdfSListInit(&inst->tokens);
+ HdfSRefConstruct(&inst->wakeRef, &wakeLockRefListener);
+}
+
+struct PowerStateManager *PowerStateManagerGetInstance()
+{
+ static struct PowerStateManager powerStateManager = { 0 };
+ if (powerStateManager.AcquireWakeLock == NULL) {
+ PowerStateManagerConstruct(&powerStateManager);
+ }
+ return &powerStateManager;
+}
diff --git a/core/manager/src/power_state_token_clnt.c b/core/manager/src/power_state_token_clnt.c
old mode 100755
new mode 100644
index ee5dac31..31eedb88
--- a/core/manager/src/power_state_token_clnt.c
+++ b/core/manager/src/power_state_token_clnt.c
@@ -1,57 +1,34 @@
-/*
- * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
- * Copyright (c) 2020, 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.
- */
-
-#include "power_state_token_clnt.h"
-#include "osal_mem.h"
-
-static void PowerStateTokenClntConstruct(struct PowerStateTokenClnt *clnt, struct IPowerStateToken *tokenIf)
-{
- clnt->tokenIf = tokenIf;
- clnt->powerState = POWER_STATE_INACTIVE;
-}
-
-struct PowerStateTokenClnt *PowerStateTokenClntNewInstance(struct IPowerStateToken *tokenIf)
-{
- struct PowerStateTokenClnt *tokenClnt =
- (struct PowerStateTokenClnt *)OsalMemCalloc(sizeof(struct PowerStateTokenClnt));
- if (tokenClnt != NULL) {
- PowerStateTokenClntConstruct(tokenClnt, tokenIf);
- return tokenClnt;
- }
- return tokenClnt;
-}
-
-void PowerStateTokenClntFreeInstance(struct PowerStateTokenClnt *tokenClnt)
-{
- if (tokenClnt != NULL) {
- OsalMemFree(tokenClnt);
- }
-}
+/*
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include "power_state_token_clnt.h"
+#include "osal_mem.h"
+
+static void PowerStateTokenClntConstruct(struct PowerStateTokenClnt *clnt, struct IPowerStateToken *tokenIf)
+{
+ clnt->tokenIf = tokenIf;
+ clnt->powerState = POWER_STATE_INACTIVE;
+}
+
+struct PowerStateTokenClnt *PowerStateTokenClntNewInstance(struct IPowerStateToken *tokenIf)
+{
+ struct PowerStateTokenClnt *tokenClnt =
+ (struct PowerStateTokenClnt *)OsalMemCalloc(sizeof(struct PowerStateTokenClnt));
+ if (tokenClnt != NULL) {
+ PowerStateTokenClntConstruct(tokenClnt, tokenIf);
+ return tokenClnt;
+ }
+ return tokenClnt;
+}
+
+void PowerStateTokenClntFreeInstance(struct PowerStateTokenClnt *tokenClnt)
+{
+ if (tokenClnt != NULL) {
+ OsalMemFree(tokenClnt);
+ }
+}
diff --git a/core/manager/test/unittest/common/hdf_ioservice_test.cpp b/core/manager/test/unittest/common/hdf_ioservice_test.cpp
new file mode 100644
index 00000000..0542ab9c
--- /dev/null
+++ b/core/manager/test/unittest/common/hdf_ioservice_test.cpp
@@ -0,0 +1,598 @@
+/*
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "hdf_uhdf_test.h"
+#include "hdf_io_service.h"
+#include "osal_time.h"
+#include "sample_driver_test.h"
+#include "hdf_log.h"
+
+using namespace testing::ext;
+
+struct Eventlistener {
+ struct HdfDevEventlistener listener;
+ int32_t eventCount;
+};
+
+class IoServiceTest : public testing::Test {
+public:
+ static void SetUpTestCase();
+ static void TearDownTestCase();
+ void SetUp();
+ void TearDown();
+ static int OnDevEventReceived(struct HdfDevEventlistener *listener, struct HdfIoService *service, uint32_t id,
+ struct HdfSBuf *data);
+
+ static struct Eventlistener listener0;
+ static struct Eventlistener listener1;
+ const char *testSvcName = SAMPLE_SERVICE;
+ const int eventWaitTimeUs = (50 * 1000);
+ static int eventCount;
+};
+
+int IoServiceTest::eventCount = 0;
+
+struct Eventlistener IoServiceTest::listener0;
+struct Eventlistener IoServiceTest::listener1;
+
+void IoServiceTest::SetUpTestCase()
+{
+ listener0.listener.onReceive = OnDevEventReceived;
+ listener0.listener.priv = (void *)"listener0";
+
+ listener1.listener.onReceive = OnDevEventReceived;
+ listener1.listener.priv = (void *)"listener1";
+}
+
+void IoServiceTest::TearDownTestCase() {}
+
+void IoServiceTest::SetUp()
+{
+ listener0.eventCount = 0;
+ listener1.eventCount = 0;
+ eventCount = 0;
+}
+
+void IoServiceTest::TearDown() {}
+
+int IoServiceTest::OnDevEventReceived(struct HdfDevEventlistener *listener, struct HdfIoService *service, uint32_t id,
+ struct HdfSBuf *data)
+{
+ OsalTimespec time;
+ OsalGetTime(&time);
+ HDF_LOGE("%s received event[%d] from %s at %llu.%llu", (char *)listener->priv, eventCount++, (char *)service->priv,
+ time.sec, time.usec);
+
+ const char *string = HdfSbufReadString(data);
+ if (string == nullptr) {
+ HDF_LOGE("fail to read string in event data");
+ return 0;
+ }
+ struct Eventlistener *l = CONTAINER_OF(listener, struct Eventlistener, listener);
+ l->eventCount++;
+ HDF_LOGE("%s: dev event received: %d %s", (char *)service->priv, id, string);
+ return 0;
+}
+
+static int SendEvent(struct HdfIoService *serv, const char *eventData)
+{
+ OsalTimespec time;
+ OsalGetTime(&time);
+
+ int ret;
+ struct HdfSBuf *data = HdfSBufObtainDefaultSize();
+ if (data == nullptr) {
+ HDF_LOGE("fail to obtain sbuf data");
+ return HDF_FAILURE;
+ }
+
+ struct HdfSBuf *reply = HdfSBufObtainDefaultSize();
+ if (reply == nullptr) {
+ HDF_LOGE("fail to obtain sbuf reply");
+ HdfSBufRecycle(data);
+ return HDF_DEV_ERR_NO_MEMORY;
+ }
+
+ do {
+ if (!HdfSbufWriteString(data, eventData)) {
+ HDF_LOGE("fail to write sbuf");
+ ret = HDF_FAILURE;
+ break;
+ }
+
+ ret = serv->dispatcher->Dispatch(&serv->object, SAMPLE_DRIVER_SENDEVENT_SINGLE_DEVICE, data, reply);
+ if (ret != HDF_SUCCESS) {
+ HDF_LOGE("fail to send service call");
+ break;
+ }
+
+ int replyData = 0;
+ if (!HdfSbufReadInt32(reply, &replyData)) {
+ HDF_LOGE("fail to get service call reply");
+ ret = HDF_ERR_INVALID_OBJECT;
+ } else if (replyData != INT32_MAX) {
+ HDF_LOGE("service call reply check fail, replyData=0x%x", replyData);
+ ret = HDF_ERR_INVALID_OBJECT;
+ }
+ HDF_LOGE("send event finish at %llu.%llu", time.sec, time.usec);
+ } while (0);
+
+ HdfSBufRecycle(data);
+ HdfSBufRecycle(reply);
+ return ret;
+}
+
+/* *
+ * @tc.name: HdfIoService001
+ * @tc.desc: service bind test
+ * @tc.type: FUNC
+ * @tc.require: AR000F869B
+ */
+HWTEST_F(IoServiceTest, HdfIoService001, TestSize.Level0)
+{
+ struct HdfIoService *testServ = HdfIoServiceBind(testSvcName);
+ ASSERT_NE(testServ, nullptr);
+ HdfIoServiceRecycle(testServ);
+}
+
+/* *
+ * @tc.name: HdfIoService002
+ * @tc.desc: service group linten test
+ * @tc.type: FUNC
+ * @tc.require: AR000F869B
+ */
+HWTEST_F(IoServiceTest, HdfIoService002, TestSize.Level0)
+{
+ struct HdfIoService *serv = HdfIoServiceBind(testSvcName);
+ ASSERT_NE(serv, nullptr);
+ serv->priv = (void *)"serv0";
+
+ struct HdfIoServiceGroup *group = HdfIoServiceGroupObtain();
+ ASSERT_NE(group, nullptr);
+
+ int ret = HdfIoServiceGroupAddService(group, serv);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = HdfIoServiceGroupRegisterListener(group, &listener0.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = SendEvent(serv, testSvcName);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ usleep(eventWaitTimeUs);
+ ASSERT_EQ(1, listener0.eventCount);
+
+ ret = HdfDeviceUnregisterEventListener(serv, &listener0.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ HdfIoServiceGroupRecycle(group);
+ group = HdfIoServiceGroupObtain();
+ ASSERT_NE(group, nullptr);
+
+ ret = HdfIoServiceGroupAddService(group, serv);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = HdfIoServiceGroupRegisterListener(group, &listener0.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = SendEvent(serv, testSvcName);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ usleep(eventWaitTimeUs);
+ ASSERT_EQ(2, listener0.eventCount);
+ HdfIoServiceGroupRecycle(group);
+
+ HdfIoServiceRecycle(serv);
+}
+
+/* *
+ * @tc.name: HdfIoService003
+ * @tc.desc: remove service from service group by recycle group test
+ * @tc.type: FUNC
+ * @tc.require: AR000F869B
+ */
+HWTEST_F(IoServiceTest, HdfIoService003, TestSize.Level0)
+{
+ struct HdfIoService *serv = HdfIoServiceBind(testSvcName);
+ ASSERT_NE(serv, nullptr);
+ serv->priv = (void *)"serv0";
+
+ struct HdfIoService *serv1 = HdfIoServiceBind(testSvcName);
+ ASSERT_NE(serv1, nullptr);
+ serv1->priv = (void *)"serv1";
+
+ struct HdfIoServiceGroup *group = HdfIoServiceGroupObtain();
+ ASSERT_NE(group, nullptr);
+
+ int ret = HdfIoServiceGroupAddService(group, serv);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = HdfIoServiceGroupRegisterListener(group, &listener0.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = SendEvent(serv, testSvcName);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ usleep(eventWaitTimeUs);
+ ASSERT_EQ(1, listener0.eventCount);
+
+ ret = HdfIoServiceGroupAddService(group, serv1);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = HdfDeviceUnregisterEventListener(serv, &listener0.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = HdfIoServiceGroupRegisterListener(group, &listener0.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = HdfDeviceRegisterEventListener(serv, &listener1.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = SendEvent(serv, testSvcName);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ usleep(eventWaitTimeUs);
+ ASSERT_EQ(2, listener0.eventCount);
+ ASSERT_EQ(1, listener1.eventCount);
+ HdfIoServiceGroupRecycle(group);
+ HdfDeviceUnregisterEventListener(serv, &listener1.listener);
+ HdfIoServiceRecycle(serv);
+ HdfIoServiceRecycle(serv1);
+}
+
+/* *
+ * @tc.name: HdfIoService004
+ * @tc.desc: single service listen test
+ * @tc.type: FUNC
+ * @tc.require: AR000F869B
+ */
+HWTEST_F(IoServiceTest, HdfIoService004, TestSize.Level0)
+{
+ struct HdfIoService *serv1 = HdfIoServiceBind(testSvcName);
+ ASSERT_NE(serv1, nullptr);
+ serv1->priv = (void *)"serv1";
+
+ int ret = HdfDeviceRegisterEventListener(serv1, &listener0.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+ ret = SendEvent(serv1, testSvcName);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ usleep(eventWaitTimeUs);
+ ASSERT_EQ(1, listener0.eventCount);
+
+ ret = HdfDeviceUnregisterEventListener(serv1, &listener0.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+ HdfIoServiceRecycle(serv1);
+}
+
+/* *
+ * @tc.name: HdfIoService005
+ * @tc.desc: service group add remove test
+ * @tc.type: FUNC
+ * @tc.require: AR000F869B
+ */
+HWTEST_F(IoServiceTest, HdfIoService005, TestSize.Level0)
+{
+ struct HdfIoService *serv = HdfIoServiceBind(testSvcName);
+ ASSERT_NE(serv, nullptr);
+ serv->priv = (void *)"serv";
+
+ struct HdfIoServiceGroup *group = HdfIoServiceGroupObtain();
+ ASSERT_NE(group, nullptr);
+
+ int ret = HdfIoServiceGroupAddService(group, serv);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = HdfIoServiceGroupRegisterListener(group, &listener0.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = SendEvent(serv, testSvcName);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ usleep(eventWaitTimeUs);
+ ASSERT_EQ(1, listener0.eventCount);
+
+ HdfIoServiceGroupRemoveService(group, serv);
+
+ ret = HdfIoServiceGroupAddService(group, serv);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = SendEvent(serv, testSvcName);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ usleep(eventWaitTimeUs);
+ ASSERT_EQ(2, listener0.eventCount);
+ HdfIoServiceGroupRecycle(group);
+}
+
+
+/* *
+ * @tc.name: HdfIoService006
+ * @tc.desc: service group add remove listener test
+ * @tc.type: FUNC
+ * @tc.require: AR000F869B
+ */
+HWTEST_F(IoServiceTest, HdfIoService006, TestSize.Level0)
+{
+ struct HdfIoServiceGroup *group = HdfIoServiceGroupObtain();
+ ASSERT_NE(group, nullptr);
+
+ struct HdfIoService *serv = HdfIoServiceBind(testSvcName);
+ ASSERT_NE(serv, nullptr);
+ serv->priv = (void *)"serv";
+
+ struct HdfIoService *serv1 = HdfIoServiceBind(testSvcName);
+ ASSERT_NE(serv1, nullptr);
+ serv1->priv = (void *)"serv1";
+
+ int ret = HdfIoServiceGroupAddService(group, serv);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = HdfIoServiceGroupRegisterListener(group, &listener0.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = HdfIoServiceGroupAddService(group, serv1);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = SendEvent(serv, testSvcName);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ usleep(eventWaitTimeUs);
+ ASSERT_EQ(1, listener0.eventCount);
+
+ ret = SendEvent(serv1, testSvcName);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ usleep(eventWaitTimeUs);
+ ASSERT_EQ(2, listener0.eventCount);
+
+ HdfIoServiceGroupRemoveService(group, serv);
+
+ ret = SendEvent(serv, testSvcName);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ usleep(eventWaitTimeUs);
+ ASSERT_EQ(2, listener0.eventCount);
+
+ ret = SendEvent(serv1, testSvcName);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ usleep(eventWaitTimeUs);
+ ASSERT_EQ(3, listener0.eventCount);
+
+ ret = HdfIoServiceGroupAddService(group, serv);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = SendEvent(serv, testSvcName);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ usleep(eventWaitTimeUs);
+ ASSERT_EQ(4, listener0.eventCount);
+
+ HdfIoServiceGroupRecycle(group);
+ HdfIoServiceRecycle(serv);
+ HdfIoServiceRecycle(serv1);
+}
+
+
+/* *
+ * @tc.name: HdfIoService007
+ * @tc.desc: duplicate remove group listener
+ * @tc.type: FUNC
+ * @tc.require: AR000F869B
+ */
+HWTEST_F(IoServiceTest, HdfIoService007, TestSize.Level0)
+{
+ struct HdfIoServiceGroup *group = HdfIoServiceGroupObtain();
+ ASSERT_NE(group, nullptr);
+
+ struct HdfIoService *serv = HdfIoServiceBind(testSvcName);
+ ASSERT_NE(serv, nullptr);
+ serv->priv = (void *)"serv";
+
+ int ret = HdfIoServiceGroupAddService(group, serv);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = HdfIoServiceGroupRegisterListener(group, &listener0.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = SendEvent(serv, testSvcName);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ usleep(eventWaitTimeUs);
+ ASSERT_EQ(1, listener0.eventCount);
+
+ ret = HdfIoServiceGroupUnregisterListener(group, &listener0.listener);
+ EXPECT_EQ(ret, HDF_SUCCESS);
+
+ ret = HdfIoServiceGroupUnregisterListener(group, &listener0.listener);
+ EXPECT_NE(ret, HDF_SUCCESS);
+
+ HdfIoServiceGroupRecycle(group);
+ HdfIoServiceRecycle(serv);
+}
+
+/* *
+ * @tc.name: HdfIoService008
+ * @tc.desc: duplicate add group listener
+ * @tc.type: FUNC
+ * @tc.require: AR000F869B
+ */
+HWTEST_F(IoServiceTest, HdfIoService008, TestSize.Level0)
+{
+ struct HdfIoServiceGroup *group = HdfIoServiceGroupObtain();
+ ASSERT_NE(group, nullptr);
+
+ struct HdfIoService *serv = HdfIoServiceBind(testSvcName);
+ ASSERT_NE(serv, nullptr);
+ serv->priv = (void *)"serv";
+
+ int ret = HdfIoServiceGroupAddService(group, serv);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = HdfIoServiceGroupRegisterListener(group, &listener0.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = SendEvent(serv, testSvcName);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ usleep(eventWaitTimeUs);
+ ASSERT_EQ(1, listener0.eventCount);
+
+ ret = HdfIoServiceGroupRegisterListener(group, &listener0.listener);
+ EXPECT_NE(ret, HDF_SUCCESS);
+
+ ret = HdfIoServiceGroupUnregisterListener(group, &listener0.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ HdfIoServiceGroupRecycle(group);
+ HdfIoServiceRecycle(serv);
+}
+
+/* *
+ * @tc.name: HdfIoService008
+ * @tc.desc: duplicate add service
+ * @tc.type: FUNC
+ * @tc.require: AR000F869B
+ */
+HWTEST_F(IoServiceTest, HdfIoService009, TestSize.Level0)
+{
+ struct HdfIoServiceGroup *group = HdfIoServiceGroupObtain();
+ ASSERT_NE(group, nullptr);
+
+ struct HdfIoService *serv = HdfIoServiceBind(testSvcName);
+ ASSERT_NE(serv, nullptr);
+ serv->priv = (void *)"serv";
+
+ int ret = HdfIoServiceGroupAddService(group, serv);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = HdfIoServiceGroupAddService(group, serv);
+ EXPECT_NE(ret, HDF_SUCCESS);
+
+ ret = HdfIoServiceGroupRegisterListener(group, &listener0.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = SendEvent(serv, testSvcName);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ usleep(eventWaitTimeUs);
+ ASSERT_EQ(1, listener0.eventCount);
+
+ ret = HdfIoServiceGroupUnregisterListener(group, &listener0.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ HdfIoServiceGroupRecycle(group);
+ HdfIoServiceRecycle(serv);
+}
+
+/* *
+ * @tc.name: HdfIoService010
+ * @tc.desc: duplicate remove service
+ * @tc.type: FUNC
+ * @tc.require: AR000F869B
+ */
+HWTEST_F(IoServiceTest, HdfIoService010, TestSize.Level0)
+{
+ struct HdfIoServiceGroup *group = HdfIoServiceGroupObtain();
+ ASSERT_NE(group, nullptr);
+
+ struct HdfIoService *serv = HdfIoServiceBind(testSvcName);
+ ASSERT_NE(serv, nullptr);
+ serv->priv = (void *)"serv";
+
+ int ret = HdfIoServiceGroupAddService(group, serv);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = HdfIoServiceGroupAddService(group, serv);
+ EXPECT_NE(ret, HDF_SUCCESS);
+
+ ret = HdfIoServiceGroupRegisterListener(group, &listener0.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = SendEvent(serv, testSvcName);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ usleep(eventWaitTimeUs);
+ ASSERT_EQ(1, listener0.eventCount);
+
+ HdfIoServiceGroupRemoveService(group, serv);
+ HdfIoServiceGroupRemoveService(group, serv);
+
+ ret = HdfIoServiceGroupUnregisterListener(group, &listener0.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ HdfIoServiceGroupRecycle(group);
+ HdfIoServiceRecycle(serv);
+}
+
+/* *
+ * @tc.name: HdfIoService011
+ * @tc.desc: duplicate add service listener
+ * @tc.type: FUNC
+ * @tc.require: AR000F869B
+ */
+HWTEST_F(IoServiceTest, HdfIoService011, TestSize.Level0)
+{
+ struct HdfIoService *serv = HdfIoServiceBind(testSvcName);
+ ASSERT_NE(serv, nullptr);
+ serv->priv = (void *)"serv";
+
+ int ret = HdfDeviceRegisterEventListener(serv, &listener0.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = SendEvent(serv, testSvcName);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ usleep(eventWaitTimeUs);
+ ASSERT_EQ(1, listener0.eventCount);
+
+ ret = HdfDeviceRegisterEventListener(serv, &listener0.listener);
+ EXPECT_NE(ret, HDF_SUCCESS);
+
+ ret = HdfDeviceUnregisterEventListener(serv, &listener0.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+ HdfIoServiceRecycle(serv);
+}
+
+/* *
+ * @tc.name: HdfIoService012
+ * @tc.desc: duplicate remove service listener
+ * @tc.type: FUNC
+ * @tc.require: AR000F869B
+ */
+HWTEST_F(IoServiceTest, HdfIoService012, TestSize.Level0)
+{
+ struct HdfIoService *serv = HdfIoServiceBind(testSvcName);
+ ASSERT_NE(serv, nullptr);
+ serv->priv = (void *)"serv";
+
+ int ret = HdfDeviceRegisterEventListener(serv, &listener0.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = SendEvent(serv, testSvcName);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ usleep(eventWaitTimeUs);
+ ASSERT_EQ(1, listener0.eventCount);
+
+ ret = HdfDeviceUnregisterEventListener(serv, &listener0.listener);
+ ASSERT_EQ(ret, HDF_SUCCESS);
+
+ ret = HdfDeviceUnregisterEventListener(serv, &listener0.listener);
+ EXPECT_NE(ret, HDF_SUCCESS);
+
+ HdfIoServiceRecycle(serv);
+}
diff --git a/core/manager/test/unittest/common/hdf_lite_manager_test.cpp b/core/manager/test/unittest/common/hdf_lite_manager_test.cpp
new file mode 100644
index 00000000..8af642b1
--- /dev/null
+++ b/core/manager/test/unittest/common/hdf_lite_manager_test.cpp
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "hdf_uhdf_test.h"
+#include "hdf_io_service.h"
+#include "osal_time.h"
+#include "sample_driver_test.h"
+
+using namespace testing::ext;
+
+class HdfManagerTest : public testing::Test {
+public:
+ static void SetUpTestCase();
+ static void TearDownTestCase();
+ void SetUp();
+ void TearDown();
+};
+
+void HdfManagerTest::SetUpTestCase()
+{
+ HdfTestOpenService();
+}
+
+void HdfManagerTest::TearDownTestCase()
+{
+ HdfTestCloseService();
+}
+
+void HdfManagerTest::SetUp()
+{
+}
+
+void HdfManagerTest::TearDown()
+{
+}
+
+/**
+ * @tc.name: HdfIoServiceBind001
+ * @tc.desc: service bind test
+ * @tc.type: FUNC
+ * @tc.require: AR000F8698 AR000F8699 AR000F869A AR000F869B AR000F869C
+ */
+HWTEST_F(HdfManagerTest, HdfIoServiceBind001, TestSize.Level0)
+{
+ const char *svcName = "HDF_TEST";
+ struct HdfIoService *hdfSvc = HdfIoServiceBind(svcName);
+ EXPECT_TRUE(hdfSvc != NULL);
+ HdfIoServiceRecycle(hdfSvc);
+}
+
+/**
+ * @tc.name: HdfIoServiceBind002
+ * @tc.desc: service bind test
+ * @tc.type: FUNC
+ * @tc.require: AR000F8698 AR000F8699 AR000F869A AR000F869B AR000F869C
+ */
+HWTEST_F(HdfManagerTest, HdfIoServiceBind002, TestSize.Level0)
+{
+ struct HdfIoService *hdfSvc = HdfIoServiceBind(DEV_MGR_NODE);
+ EXPECT_TRUE(hdfSvc != NULL);
+ HdfIoServiceRecycle(hdfSvc);
+}
+
+/**
+ * @tc.name: HdfRegisterDevice001
+ * @tc.desc: register device
+ * @tc.type: FUNC
+ * @tc.require: SR000F8697
+ */
+HWTEST_F(HdfManagerTest, HdfRegisterDevice001, TestSize.Level0)
+{
+ int32_t ret = HDF_FAILURE;
+ struct HdfSBuf *data = NULL;
+ struct HdfIoService *ioService = HdfIoServiceBind(SAMPLE_SERVICE);
+ ASSERT_TRUE(ioService != NULL);
+ data = HdfSBufObtainDefaultSize();
+ ASSERT_TRUE(data != NULL);
+ EXPECT_TRUE(HdfSbufWriteString(data, "sample_driver"));
+ EXPECT_TRUE(HdfSbufWriteString(data, "sample_service1"));
+ int64_t timeBefore = OsalGetSysTimeMs();
+ ret = ioService->dispatcher->Dispatch(&ioService->object, SAMPLE_DRIVER_REGISTER_DEVICE, data, NULL);
+ EXPECT_TRUE(ret == HDF_SUCCESS);
+ int64_t timeAfter = OsalGetSysTimeMs();
+ EXPECT_TRUE((timeAfter - timeBefore) < 100);
+
+ struct HdfIoService *ioService1 = HdfIoServiceBind("sample_service1");
+ ASSERT_TRUE(ioService1 != NULL);
+ HdfIoServiceRecycle(ioService1);
+
+ ret = ioService->dispatcher->Dispatch(&ioService->object, SAMPLE_DRIVER_UNREGISTER_DEVICE, data, NULL);
+ EXPECT_TRUE(ret == HDF_SUCCESS);
+
+ ioService1 = HdfIoServiceBind("sample_service1");
+ EXPECT_TRUE(ioService1 == NULL);
+ HdfIoServiceRecycle(ioService);
+ HdfIoServiceRecycle(ioService1);
+ HdfSBufRecycle(data);
+}
+
+/**
+ * @tc.name: HdfGetServiceNameByDeviceClass001
+ * @tc.desc: get service test
+ * @tc.type: FUNC
+ * @tc.require: AR000F8698 AR000F8699 AR000F869A AR000F869B AR000F869C
+ */
+HWTEST_F(HdfManagerTest, HdfGetServiceNameByDeviceClass001, TestSize.Level0)
+{
+ struct HdfSBuf *data = HdfSBufObtain(1000);
+ EXPECT_TRUE(data != NULL);
+ int32_t ret = HdfGetServiceNameByDeviceClass(DEVICE_CLASS_DEFAULT, data);
+ EXPECT_TRUE(ret == HDF_SUCCESS);
+ bool flag = false;
+ const char *svcName = NULL;
+ while(true) {
+ svcName = HdfSbufReadString(data);
+ if (svcName == NULL) {
+ break;
+ }
+ if (strcmp(svcName, "sample_service") == 0) {
+ flag = true;
+ break;
+ }
+ }
+ HdfSBufRecycle(data);
+ EXPECT_TRUE(flag);
+}
+
diff --git a/core/manager/test/unittest/common/hdf_sbuf_test.cpp b/core/manager/test/unittest/common/hdf_sbuf_test.cpp
new file mode 100644
index 00000000..a1ebde55
--- /dev/null
+++ b/core/manager/test/unittest/common/hdf_sbuf_test.cpp
@@ -0,0 +1,811 @@
+/*
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
+ *
+ * HDF is dual licensed: you can use it either under the terms of
+ * the GPL, or the BSD license, at your option.
+ * See the LICENSE file in the root of this repository for complete details.
+ */
+
+
+#include
+#include