update openharmony 1.0.1

This commit is contained in:
mamingshuai
2021-03-11 18:45:38 +08:00
parent 749e1fc82f
commit 18be8c8b60
392 changed files with 42515 additions and 7610 deletions
-13
View File
@@ -1,13 +0,0 @@
### 该问题是怎么引起的?
### 重现步骤
### 报错信息
-15
View File
@@ -1,15 +0,0 @@
### 相关的Issue
### 原因(目的、解决的问题等)
### 描述(做了什么,变更了什么)
### 测试用例(新增、改动、可能影响的功能)
+51 -28
View File
@@ -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.
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.
+164
View File
@@ -0,0 +1,164 @@
# HDF<a name="EN-US_TOPIC_0000001078041442"></a>
- [Introduction](#section11660541593)
- [Directory Structure](#section161941989596)
- [Usage](#section1312121216216)
- [HDF](#section129654513264)
- [Sensor](#section188637474417)
- [Display](#section161502341317)
- [Input](#section12629164020115)
- [WLAN](#section11408103183114)
- [Repositories Involved](#section1371113476307)
## Introduction<a name="section11660541593"></a>
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<a name="fig19330181162816"></a>
![](figures/architecture-of-the-hdf.png)
## Directory Structure<a name="section161941989596"></a>
```
/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<a name="section1312121216216"></a>
### HDF<a name="section129654513264"></a>
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<a name="section188637474417"></a>
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<a name="section161502341317"></a>
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<a name="section12629164020115"></a>
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<a name="section11408103183114"></a>
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<a name="section1371113476307"></a>
Driver subsystem
hmf/drivers/framework
hmf/drivers/adapter\_uhdf
hmf/drivers/adapter\_khdf\_linux
hmf/drivers/adapter\_khdf\_liteos
+168
View File
@@ -0,0 +1,168 @@
# Hdf Framework<a name="ZH-CN_TOPIC_0000001078041442"></a>
- [简介](#section11660541593)
- [目录](#section161941989596)
- [说明](#section1312121216216)
- [驱动框架使用说明](#section129654513264)
- [Sensor框架模型说明](#section188637474417)
- [Display框架模型说明](#section161502341317)
- [Input框架模型说明](#section12629164020115)
- [WLAN框架模型说明](#section11408103183114)
- [相关仓](#section1371113476307)
## 简介<a name="section11660541593"></a>
该仓主要存放OpenHarmony驱动子系统核心源码信息(包括驱动框架、配置管理、配置解析、驱动通用框架模型、硬件通用平台能力接口等),旨在为开发者提供更精准、更高效的开发环境,力求做到一次开发,多系统部署。
**图 1** 驱动框架的架构图<a name="fig1181155517618"></a>
![](figures/architecture-of-the-hdf.png)
## 目录<a name="section161941989596"></a>
```
/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 #提供基础数据结构和算法等
```
## 说明<a name="section1312121216216"></a>
### 驱动框架使用说明<a name="section129654513264"></a>
基于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框架模型说明<a name="section188637474417"></a>
基于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框架模型说明<a name="section161502341317"></a>
基于OpenHarmony驱动框架的Display驱动模型,对上屏蔽了芯片平台差异,方便操作系统跨平台迁移;向下抽象外设驱动公共业务逻辑,通过配置或差异化适配接口,实现一套驱动模型可兼容不同的外设器件,使得三方厂商可以高效、便捷的切入鸿蒙驱动生态。
- Display驱动模型基础能力部分:包括HDI**H**ardware **D**river **I**nterfaces)接口的定义及其实现框架,以及芯片平台对HDI接口的适配实现;内核驱动部分抽象了Panel驱动的公共业务,提供基础的Panel初始化、器件配置信息获取、上下电、背光设置等公共流程。
- 驱动开发者实现的部分:需要完成板级的HCS配置及Panel私有数据配置,或者实现部分器件差异化接口,保证显示屏驱动开发高效便捷。
基于Display驱动模型开发LCD器件驱动请参考[LCD驱动开发指南](zh-cn_topic_0000001052857284.md)。
### Input框架模型说明<a name="section12629164020115"></a>
基于OpenHarmony驱动框架的Input驱动模型,不依赖于芯片平台,对上层输入服务提供统一的驱动接口;在具体的驱动模型实现中,针对不同类别的输入设备,抽象出几类公共的平台驱动,通过配置及差异化的适配接口,使得驱动模型可兼容不同的输入设备。
- Input驱动模型基础能力部分:包括Input HDI层的接口定义及公共实现,对上层输入服务提供设备管理、业务控制、数据上报等驱动能力接口;而Input驱动模型提供不同类型Input设备的归一化驱动, 包括输入设备的注册和注销、event数据的上报通道、配置信息的解析、公共驱动的加载等能力。
- 开发者实现的部分:根据驱动模型提供的平台驱动,需要完成设备描述配置及器件私有配置,以及实现预留的器件差异化接口,借由此驱动模型,可大幅缩减Input设备驱动的开发周期。
基于Input驱动模型开发Touchscreen器件驱动请参考[Touchscreen驱动开发指南](zh-cn_topic_0000001052857350.md)。
### WLAN框架模型说明<a name="section11408103183114"></a>
基于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)。
## 相关仓<a name="section1371113476307"></a>
驱动子系统
hmf/drivers/framework
hmf/drivers/adapter\_uhdf
hmf/drivers/adapter\_khdf\_linux
hmf/drivers/adapter\_khdf\_liteos
<a name="table19581927144220"></a>
<table><tbody></tbody>
</table>
+4 -27
View File
@@ -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"
+4 -28
View File
@@ -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 <string.h>
#include "hdf_base.h"
#define CONFIG_NODE 0x1
+4 -27
View File
@@ -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
+4 -27
View File
@@ -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
+4 -27
View File
@@ -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
+12 -31
View File
@@ -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;
+4 -27
View File
@@ -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"
+4 -27
View File
@@ -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"
+29 -43
View File
@@ -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;
@@ -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 <cstdint>
#include <cstdio>
#include <cstdlib>
#include <fcntl.h>
#include <gtest/gtest.h>
#include <string>
#include <unistd.h>
#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 <b>BOOL</b> 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 <b>BOOL</b> 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 <b>Uint8</b> 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 <b>Uint8</b> 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 <b>Unit8</b> 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 <b>Unit8</b> 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 <b>Uint8</b> 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 <b>Uint8</b> 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 <b>Uint16</b> 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 <b>Uint16</b> 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 <b>Uint16</b> array attribute numbered <b>index</b> 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 <b>Uint16</b> array attribute numbered <b>index</b> 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 <b>Uint16</b> 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 <b>Uint16</b> 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 <b>Uint32</b> 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 <b>Uint32</b> 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 <b>Uint32</b> array attribute numbered <b>index</b> 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 <b>Uint32</b> array attribute numbered <b>index</b> 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 <b>Uint32</b> 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 <b>Uint32</b> 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 <b>Uint64</b> 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 <b>Uint64</b> 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 <b>Uint64</b> array attribute numbered <b>index</b> 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 <b>Uint64</b> array attribute numbered <b>index</b> 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 <b>Uint64</b> 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 <b>Uint64</b> 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 <b>String</b> 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 <b>String</b> 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 <b>String</b> array attribute numbered <b>index</b> 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 <b>String</b> array attribute numbered <b>index</b> 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));
}
};
Executable → Regular
+5 -30
View File
@@ -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 <stdio.h>
#include <stdbool.h>
#include "hdf_cstring.h"
#include "hdf_base.h"
#ifdef __cplusplus
extern "C" {
Executable → Regular
+28 -38
View File
@@ -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 <securec.h>
#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) {
@@ -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 <fcntl.h>
#include <poll.h>
#include <osal_mutex.h>
#include <osal_thread.h>
#include <hdf_dlist.h>
#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 */
@@ -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;
}
File diff suppressed because it is too large Load Diff
@@ -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 */
+662
View File
@@ -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 <osal_cdev.h>
#include <osal_mem.h>
#include <osal_sem.h>
#include <osal_uaccess.h>
#include <securec.h>
#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);
}
@@ -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 */
@@ -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 */
@@ -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 */
+69
View File
@@ -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;
}
+141
View File
@@ -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);
}
+369
View File
@@ -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;
}
}
}
}
+125
View File
@@ -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);
}
}
+67
View File
@@ -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;
}
+7 -27
View File
@@ -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);
+4 -27
View File
@@ -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
+8 -28
View File
@@ -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 */
Executable → Regular
+6 -28
View File
@@ -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);
+4 -27
View File
@@ -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
+4 -27
View File
@@ -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
+4 -27
View File
@@ -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
+6 -27
View File
@@ -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 */
+4 -27
View File
@@ -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
+4 -27
View File
@@ -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
+4 -27
View File
@@ -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
+26 -49
View File
@@ -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 */
Executable → Regular
+27 -33
View File
@@ -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);
+4 -27
View File
@@ -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"
+38 -33
View File
@@ -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;
}
Executable → Regular
+6 -29
View File
@@ -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);
}
Executable → Regular
+6 -28
View File
@@ -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)
+15 -27
View File
@@ -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;
}
}
Executable → Regular
+4 -27
View File
@@ -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"
+7 -29
View File
@@ -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);
}
+4 -27
View File
@@ -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"
+4 -27
View File
@@ -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"
+4 -27
View File
@@ -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"
+136 -159
View File
@@ -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);
}
}
+5 -27
View File
@@ -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;
+4 -27
View File
@@ -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
+6 -27
View File
@@ -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);
+5 -27
View File
@@ -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);
@@ -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 */
+4 -27
View File
@@ -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
+4 -27
View File
@@ -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
+24 -47
View File
@@ -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 */
+24 -47
View File
@@ -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 */
+11 -28
View File
@@ -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;
+4 -27
View File
@@ -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"
+46 -37
View File
@@ -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 <string.h>
#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);
+11 -49
View File
@@ -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;
+4 -27
View File
@@ -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"
Executable → Regular
+4 -27
View File
@@ -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"
+84 -107
View File
@@ -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;
}
+34 -57
View File
@@ -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);
}
}
@@ -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 <cstdint>
#include <cstdio>
#include <cstdlib>
#include <fcntl.h>
#include <string>
#include <unistd.h>
#include <gtest/gtest.h>
#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);
}
@@ -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 <cstdint>
#include <cstdio>
#include <cstdlib>
#include <fcntl.h>
#include <string>
#include <unistd.h>
#include <gtest/gtest.h>
#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);
}
@@ -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 <iostream>
#include <map>
#include <memory>
#include <random>
#include <cstring>
#include <gtest/gtest.h>
#include <hdf_sbuf.h>
using namespace testing::ext;
static const int DEFAULT_SBUF_SIZE = 256;
static const int DEFAULT_LOOP_COUNT = 500;
static const int DEFAULT_BIG_LOOP_COUNT = 1000;
static const int DATA_MOD = 26;
class SBufTest : public ::testing::Test {
protected:
void SetUp() override {}
void TearDown() override
{
dataTable.clear();
}
void GenDataTable()
{
dataTable[UINT8] = std::unique_ptr<SbufData>(new SbufData(sizeof(uint8_t)));
dataTable[UINT16] = std::unique_ptr<SbufData>(new SbufData(sizeof(uint16_t)));
dataTable[UINT32] = std::unique_ptr<SbufData>(new SbufData(sizeof(uint32_t)));
dataTable[UINT64] = std::unique_ptr<SbufData>(new SbufData(sizeof(uint64_t)));
dataTable[INT8] = std::unique_ptr<SbufData>(new SbufData(sizeof(uint8_t)));
dataTable[INT16] = std::unique_ptr<SbufData>(new SbufData(sizeof(uint16_t)));
dataTable[INT32] = std::unique_ptr<SbufData>(new SbufData(sizeof(uint32_t)));
dataTable[INT64] = std::unique_ptr<SbufData>(new SbufData(sizeof(uint64_t)));
dataTable[BUFFER] = std::unique_ptr<SbufData>(new SbufData((rd() % UINT8_MAX) + 1));
dataTable[STRING] = std::unique_ptr<SbufData>(new SbufData((rd() % UINT8_MAX) + 1));
dataTable[STRING]->data[dataTable[STRING]->size - 1] = '\0';
}
void GenDataSequence(int seqSize)
{
dataSequence.clear();
std::random_device rnd;
for (int i = 0; i < seqSize; ++i) {
dataSequence.push_back(rnd() % TYPE_MAX);
}
}
bool PushDataSequence(HdfSBuf *sbuf)
{
for (auto type : dataSequence) {
bool ret = false;
switch (type) {
case UINT8:
ret = HdfSbufWriteUint8(sbuf, *(uint8_t *)dataTable[type]->data);
break;
case UINT16:
ret = HdfSbufWriteUint16(sbuf, *(uint16_t *)dataTable[type]->data);
break;
case UINT32:
ret = HdfSbufWriteUint32(sbuf, *(uint32_t *)dataTable[type]->data);
break;
case UINT64:
ret = HdfSbufWriteUint64(sbuf, *(uint64_t *)dataTable[type]->data);
break;
case INT8:
ret = HdfSbufWriteUint8(sbuf, *(int8_t *)dataTable[type]->data);
break;
case INT16:
ret = HdfSbufWriteUint16(sbuf, *(uint16_t *)dataTable[type]->data);
break;
case INT32:
ret = HdfSbufWriteUint32(sbuf, *(uint32_t *)dataTable[type]->data);
break;
case INT64:
ret = HdfSbufWriteUint64(sbuf, *(uint64_t *)dataTable[type]->data);
break;
case BUFFER:
ret = HdfSbufWriteBuffer(sbuf, (uint8_t *)dataTable[type]->data, dataTable[type]->size);
break;
case STRING:
ret = HdfSbufWriteString(sbuf, (char *)dataTable[type]->data);
break;
default:
break;
}
if (!ret) {
std::cout << "write type " << type << " fail" << std::endl;
return ret;
}
}
return true;
}
static bool DataCompare(const void *s, const void *t, uint32_t size)
{
return memcmp(s, t, size) == 0;
}
bool PullDataSequence(HdfSBuf *sbuf)
{
for (auto type : dataSequence) {
bool ret = false;
switch (type) {
case UINT8: {
uint8_t val = 0;
ret = HdfSbufReadUint8(sbuf, &val);
EXPECT_EQ(true, DataCompare(&val, dataTable[type]->data, dataTable[type]->size));
EXPECT_EQ(true, ret);
break;
}
case UINT16: {
uint16_t val = 0;
ret = HdfSbufReadUint16(sbuf, &val);
EXPECT_EQ(true, DataCompare(&val, dataTable[type]->data, dataTable[type]->size));
EXPECT_EQ(true, ret);
break;
}
case UINT32: {
uint32_t val = 0;
ret = HdfSbufReadUint32(sbuf, &val);
EXPECT_EQ(true, DataCompare(&val, dataTable[type]->data, dataTable[type]->size));
EXPECT_EQ(true, ret);
break;
}
case UINT64: {
uint64_t val = 0;
ret = HdfSbufReadUint64(sbuf, &val);
EXPECT_EQ(true, DataCompare(&val, dataTable[type]->data, dataTable[type]->size));
EXPECT_EQ(true, ret);
break;
}
case INT8: {
int8_t val = 0;
ret = HdfSbufReadInt8(sbuf, &val);
EXPECT_EQ(true, ret);
ret = DataCompare(&val, dataTable[type]->data, dataTable[type]->size);
EXPECT_EQ(true, ret);
break;
}
case INT16: {
int16_t val = 0;
ret = HdfSbufReadInt16(sbuf, &val);
EXPECT_EQ(true, DataCompare(&val, dataTable[type]->data, dataTable[type]->size));
EXPECT_EQ(true, ret);
break;
}
case INT32: {
int32_t val = 0;
ret = HdfSbufReadInt32(sbuf, &val);
EXPECT_EQ(true, DataCompare(&val, dataTable[type]->data, dataTable[type]->size));
EXPECT_EQ(true, ret);
break;
}
case INT64: {
int64_t val = 0;
ret = HdfSbufReadInt64(sbuf, &val);
EXPECT_EQ(true, DataCompare(&val, dataTable[type]->data, dataTable[type]->size));
EXPECT_EQ(true, ret);
break;
}
case BUFFER: {
const char *buf = nullptr;
uint32_t readSize = 0;
ret = HdfSbufReadBuffer(sbuf, reinterpret_cast<const void **>(&buf), &readSize);
EXPECT_EQ(true, DataCompare(buf, dataTable[type]->data, dataTable[type]->size));
EXPECT_EQ(true, ret);
break;
}
case STRING: {
auto val = HdfSbufReadString(sbuf);
EXPECT_NE(nullptr, val);
if (val == nullptr) {
return false;
}
EXPECT_EQ(strlen(val), dataTable[type]->size - 1);
EXPECT_EQ(true, DataCompare(val, dataTable[type]->data, dataTable[type]->size));
ret = true;
break;
}
default:
break;
}
if (!ret) {
std::cout << "write type " << type << " fail" << std::endl;
return ret;
}
}
return true;
}
enum SbufDataType {
UINT8,
UINT16,
UINT32,
UINT64,
INT8,
INT16,
INT32,
INT64,
BUFFER,
STRING,
TYPE_MAX,
};
class SbufData {
public:
explicit SbufData(uint32_t dataSize) : data(nullptr), size(dataSize)
{
std::random_device rnd;
data = new uint8_t[dataSize];
for (uint32_t i = 0; i < dataSize; ++i) {
data[i] = 'A' + rnd() % DATA_MOD;
}
}
~SbufData()
{
if (data != nullptr) {
delete[] data;
}
}
uint8_t *data;
uint32_t size;
};
std::map<int, std::unique_ptr<SbufData>> dataTable;
std::vector<int> dataSequence;
std::random_device rd;
};
/**
* @tc.name: SbufTestObtain001
* @tc.desc: obtain sbuf
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestObtain001, TestSize.Level0)
{
HdfSBuf *sBuf = HdfSBufObtain(DEFAULT_SBUF_SIZE);
ASSERT_NE(sBuf, nullptr);
HdfSBufRecycle(sBuf);
}
/**
* @tc.name: SbufTestWriteUint64002
* @tc.desc: write uint64 data
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestWriteUint64002, TestSize.Level0)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
auto ret = HdfSbufWriteInt64(sBuf, INT64_MAX);
ASSERT_EQ(ret, true);
HdfSBufRecycle(sBuf);
}
/**
* @tc.name: SbufTestWriteUint64Loop003
* @tc.desc: write uint64 data sequence
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestWriteUint64Loop003, TestSize.Level0)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
for (int i = 0; i < DEFAULT_BIG_LOOP_COUNT; ++i) {
auto ret = HdfSbufWriteInt64(sBuf, INT64_MAX);
ASSERT_EQ(ret, true);
}
HdfSBufRecycle(sBuf);
}
/**
* @tc.name: SbufTestReadUint64Loop004
* @tc.desc: read after write uint64 data sequence
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestReadUint64Loop004, TestSize.Level0)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
int loop = DEFAULT_BIG_LOOP_COUNT;
for (int i = 0; i < loop; ++i) {
auto ret = HdfSbufWriteInt64(sBuf, INT64_MAX);
ASSERT_EQ(ret, true);
}
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
ASSERT_NE(readBuf, nullptr);
uint64_t val = 0;
for (int j = 0; j < loop; ++j) {
val = 0;
auto ret = HdfSbufReadUint64(readBuf, &val);
ASSERT_EQ(ret, true);
ASSERT_EQ(val, (uint64_t)INT64_MAX);
}
auto ret = HdfSbufReadUint64(readBuf, &val);
ASSERT_EQ(ret, false);
HdfSBufRecycle(readBuf);
HdfSBufRecycle(sBuf);
}
/**
* @tc.name: SbufTestInt8005
* @tc.desc: read write int8 data
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestInt8005, TestSize.Level0)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
bool ret;
int loop = DEFAULT_LOOP_COUNT;
for (int i = 0; i < loop; ++i) {
ret = HdfSbufWriteInt8(sBuf, INT8_MAX);
ASSERT_EQ(ret, true);
}
size_t dataSize = HdfSbufGetDataSize(sBuf);
ASSERT_EQ(dataSize, loop * sizeof(uint32_t));
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
ASSERT_NE(readBuf, nullptr);
int8_t val = 0;
for (int j = 0; j < loop; ++j) {
val = 0;
ret = HdfSbufReadInt8(readBuf, &val);
ASSERT_EQ(ret, true);
ASSERT_EQ(val, INT8_MAX);
}
HdfSBufRecycle(readBuf);
HdfSBufRecycle(sBuf);
}
/**
* @tc.name: SbufTestInt16006
* @tc.desc: read write int16 data
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestInt16006, TestSize.Level0)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
bool ret;
int loop = DEFAULT_LOOP_COUNT;
for (int i = 0; i < loop; ++i) {
ret = HdfSbufWriteInt16(sBuf, INT16_MAX);
ASSERT_EQ(ret, true);
}
size_t dataSize = HdfSbufGetDataSize(sBuf);
ASSERT_EQ(dataSize, loop * sizeof(uint32_t));
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
ASSERT_NE(readBuf, nullptr);
int16_t val = 0;
for (int j = 0; j < loop; ++j) {
val = 0;
ret = HdfSbufReadInt16(readBuf, &val);
ASSERT_EQ(ret, true);
ASSERT_EQ(val, INT16_MAX);
}
HdfSBufRecycle(readBuf);
HdfSBufRecycle(sBuf);
}
/**
* @tc.name: SbufTestInt32007
* @tc.desc: read write int32 data
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestInt32007, TestSize.Level0)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
bool ret;
int loop = DEFAULT_LOOP_COUNT;
for (int i = 0; i < loop; ++i) {
ret = HdfSbufWriteInt32(sBuf, INT32_MAX);
ASSERT_EQ(ret, true);
}
size_t dataSize = HdfSbufGetDataSize(sBuf);
ASSERT_EQ(dataSize, loop * sizeof(uint32_t));
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
ASSERT_NE(readBuf, nullptr);
int32_t val = 0;
for (int j = 0; j < loop; ++j) {
val = 0;
ret = HdfSbufReadInt32(readBuf, &val);
ASSERT_EQ(ret, true);
ASSERT_EQ(val, INT32_MAX);
}
HdfSBufRecycle(readBuf);
HdfSBufRecycle(sBuf);
}
/**
* @tc.name: SbufTestInt64008
* @tc.desc: read write int64 data
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestInt64008, TestSize.Level0)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
bool ret;
int loop = DEFAULT_LOOP_COUNT;
for (int i = 0; i < loop; ++i) {
ret = HdfSbufWriteInt64(sBuf, INT64_MAX);
ASSERT_EQ(ret, true);
}
size_t dataSize = HdfSbufGetDataSize(sBuf);
ASSERT_EQ(dataSize, loop * sizeof(uint64_t));
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
ASSERT_NE(readBuf, nullptr);
int64_t val = 0;
for (int j = 0; j < loop; ++j) {
val = 0;
ret = HdfSbufReadInt64(readBuf, &val);
ASSERT_EQ(ret, true);
ASSERT_EQ(val, INT64_MAX);
}
HdfSBufRecycle(readBuf);
HdfSBufRecycle(sBuf);
}
/**
* @tc.name: SbufTestUInt32009
* @tc.desc: read write uint32 data
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestUInt32009, TestSize.Level0)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
bool ret;
int loop = DEFAULT_LOOP_COUNT;
for (int i = 0; i < loop; ++i) {
ret = HdfSbufWriteUint32(sBuf, UINT32_MAX);
ASSERT_EQ(ret, true);
}
size_t dataSize = HdfSbufGetDataSize(sBuf);
ASSERT_EQ(dataSize, loop * sizeof(uint32_t));
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
ASSERT_NE(readBuf, nullptr);
uint32_t val = 0;
for (int j = 0; j < loop; ++j) {
val = 0;
ret = HdfSbufReadUint32(readBuf, &val);
ASSERT_EQ(ret, true);
ASSERT_EQ(val, UINT32_MAX);
}
HdfSBufRecycle(readBuf);
HdfSBufRecycle(sBuf);
}
/**
* @tc.name: SbufTestUInt16010
* @tc.desc: read write uint16 data
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestUInt16010, TestSize.Level0)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
bool ret;
int loop = DEFAULT_LOOP_COUNT;
for (int i = 0; i < loop; ++i) {
ret = HdfSbufWriteUint16(sBuf, UINT16_MAX);
ASSERT_EQ(ret, true);
}
size_t dataSize = HdfSbufGetDataSize(sBuf);
ASSERT_EQ(dataSize, loop * sizeof(uint32_t));
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
ASSERT_NE(readBuf, nullptr);
uint16_t val = 0;
for (int j = 0; j < loop; ++j) {
val = 0;
ret = HdfSbufReadUint16(readBuf, &val);
ASSERT_EQ(ret, true);
ASSERT_EQ(val, UINT16_MAX);
}
HdfSBufRecycle(readBuf);
HdfSBufRecycle(sBuf);
}
/**
* @tc.name: SbufTestUInt8011
* @tc.desc: read write uint8 data
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestUInt8011, TestSize.Level0)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
bool ret;
int loop = DEFAULT_LOOP_COUNT;
for (int i = 0; i < loop; ++i) {
ret = HdfSbufWriteUint8(sBuf, UINT8_MAX);
ASSERT_EQ(ret, true);
}
size_t dataSize = HdfSbufGetDataSize(sBuf);
ASSERT_EQ(dataSize, loop * sizeof(uint32_t));
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
ASSERT_NE(readBuf, nullptr);
uint8_t val = 0;
for (int j = 0; j < loop; ++j) {
val = 0;
ret = HdfSbufReadUint8(readBuf, &val);
ASSERT_EQ(ret, true);
ASSERT_EQ(val, UINT8_MAX);
}
HdfSBufRecycle(readBuf);
HdfSBufRecycle(sBuf);
}
/**
* @tc.name: SbufTestString012
* @tc.desc: read write string data
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestString012, TestSize.Level0)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
bool ret;
int loop = DEFAULT_LOOP_COUNT;
std::string str("test");
for (int i = 0; i < loop; ++i) {
ret = HdfSbufWriteString(sBuf, str.data());
ASSERT_EQ(ret, true);
}
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
ASSERT_NE(readBuf, nullptr);
for (int j = 0; j < loop; ++j) {
const char *readStr = HdfSbufReadString(readBuf);
ASSERT_NE(readStr, nullptr);
ASSERT_EQ(std::string(readStr), str);
}
HdfSBufRecycle(readBuf);
HdfSBufRecycle(sBuf);
}
/**
* @tc.name: SbufTestNullString013
* @tc.desc: read write bullptr string data test
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestNullString013, TestSize.Level0)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
auto ret = HdfSbufWriteString(sBuf, nullptr);
ASSERT_EQ(true, ret);
ret = HdfSbufWriteInt32(sBuf, INT32_MIN);
ASSERT_EQ(true, ret);
size_t dataSize = HdfSbufGetDataSize(sBuf);
ASSERT_NE((size_t)0, dataSize);
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
ASSERT_NE(readBuf, nullptr);
auto val = HdfSbufReadString(readBuf);
ASSERT_EQ(nullptr, val);
int32_t intVal = 0;
ret = HdfSbufReadInt32(readBuf, &intVal);
ASSERT_EQ(true, ret);
ASSERT_EQ(INT32_MIN, intVal);
HdfSBufRecycle(readBuf);
HdfSBufRecycle(sBuf);
}
/**
* @tc.name: SbufTestBuffer014
* @tc.desc: read write buffer test
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestBuffer014, TestSize.Level0)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
bool ret;
int loop = 1;
std::string str("test");
for (int i = 0; i < loop; ++i) {
ret = HdfSbufWriteBuffer(sBuf, str.data(), str.size() + 1);
ASSERT_EQ(ret, true);
}
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
ASSERT_NE(readBuf, nullptr);
for (int j = 0; j < loop; ++j) {
const char *data = nullptr;
uint32_t readSize = 0;
ret = HdfSbufReadBuffer(readBuf, (const void **)(&data), &readSize);
ASSERT_EQ(ret, true);
ASSERT_EQ(readSize, str.size() + 1);
ASSERT_EQ(std::string(data), str);
}
HdfSBufRecycle(readBuf);
HdfSBufRecycle(sBuf);
}
/**
* @tc.name: SbufTestNullBuffer015
* @tc.desc: read write nullptr buffer data
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestNullBuffer015, TestSize.Level0)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
auto ret = HdfSbufWriteBuffer(sBuf, nullptr, 0);
ASSERT_EQ(true, ret);
ret = HdfSbufWriteInt16(sBuf, INT16_MIN);
ASSERT_EQ(true, ret);
size_t dataSize = HdfSbufGetDataSize(sBuf);
ASSERT_NE((size_t)0, dataSize);
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
ASSERT_NE(readBuf, nullptr);
const uint8_t *buffVal = nullptr;
uint32_t buffLen = 0;
ret = HdfSbufReadBuffer(readBuf, (const void **)(&buffVal), &buffLen);
ASSERT_EQ(true, ret);
ASSERT_EQ((uint32_t)0, buffLen);
dataSize = HdfSbufGetDataSize(sBuf);
ASSERT_NE((size_t)0, dataSize);
int16_t intVal = 0;
ret = HdfSbufReadInt16(readBuf, &intVal);
ASSERT_EQ(true, ret);
ASSERT_EQ(INT16_MIN, intVal);
HdfSBufRecycle(sBuf);
HdfSBufRecycle(readBuf);
}
/**
* @tc.name: SbufTestRandomDataSeq016
* @tc.desc: read write random data test
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestRandomDataSeq016, TestSize.Level0)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
GenDataTable();
GenDataSequence(100);
bool ret = PushDataSequence(sBuf);
ASSERT_EQ(true, ret);
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
ASSERT_NE(readBuf, nullptr);
ret = PullDataSequence(readBuf);
ASSERT_EQ(true, ret);
HdfSBufRecycle(sBuf);
HdfSBufRecycle(readBuf);
}
/**
* @tc.name: SbufTestRandomRWDataSeq017
* @tc.desc: read write random data sequence test
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestRandomRWDataSeq017, TestSize.Level0)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
GenDataTable();
GenDataSequence(100);
bool ret = PushDataSequence(sBuf);
ASSERT_EQ(true, ret);
ret = PullDataSequence(sBuf);
ASSERT_EQ(true, ret);
ret = PushDataSequence(sBuf);
ASSERT_EQ(true, ret);
ret = PullDataSequence(sBuf);
ASSERT_EQ(true, ret);
uint8_t val = 0;
ret = HdfSbufReadUint8(sBuf, &val);
ASSERT_EQ(false, ret);
ASSERT_EQ(0, val);
HdfSBufRecycle(sBuf);
}
/**
* @tc.name: SbufTestSbufMove018
* @tc.desc: move sbuf test
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestSbufMove018, TestSize.Level0)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
GenDataTable();
GenDataSequence(100);
bool ret;
int loop = 1;
std::string str("test");
for (int i = 0; i < loop; ++i) {
ret = HdfSbufWriteBuffer(sBuf, str.data(), str.size() + 1);
ASSERT_EQ(ret, true);
}
HdfSBuf *readBuf = HdfSBufMove(sBuf);
ASSERT_NE(readBuf, nullptr);
for (int j = 0; j < loop; ++j) {
const char *data = nullptr;
uint32_t readSize = 0;
ret = HdfSbufReadBuffer(readBuf, (const void **)(&data), &readSize);
ASSERT_EQ(ret, true);
ASSERT_EQ(readSize, str.size() + 1);
ASSERT_EQ(std::string(data), str);
}
HdfSBufRecycle(sBuf);
HdfSBufRecycle(readBuf);
}
/**
* @tc.name: SbufTestSbufMoveHalf019
* @tc.desc: move sbuf after read test
* @tc.type: FUNC
* @tc.require: AR000F869B
*/
HWTEST_F(SBufTest, SbufTestSbufMoveHalf019, TestSize.Level0)
{
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
ASSERT_NE(sBuf, nullptr);
bool ret;
int loop = 1;
std::string str("test");
for (int i = 0; i < loop; ++i) {
ret = HdfSbufWriteBuffer(sBuf, str.data(), str.size() + 1);
ASSERT_EQ(ret, true);
}
for (int j = 0; j < loop/2; ++j) {
const char *data = nullptr;
uint32_t readSize = 0;
ret = HdfSbufReadBuffer(sBuf, (const void **)(&data), &readSize);
ASSERT_EQ(ret, true);
ASSERT_EQ(readSize, str.size() + 1);
ASSERT_EQ(std::string(data), str);
}
HdfSBuf *readBuf = HdfSBufMove(sBuf);
ASSERT_NE(readBuf, nullptr);
for (int j = 0; j < loop; ++j) {
const char *data = nullptr;
uint32_t readSize = 0;
ret = HdfSbufReadBuffer(readBuf, (const void **)(&data), &readSize);
ASSERT_EQ(ret, true);
ASSERT_EQ(readSize, str.size() + 1);
ASSERT_EQ(std::string(data), str);
}
const char *data = nullptr;
uint32_t readSize = 0;
ret = HdfSbufReadBuffer(readBuf, (const void **)(&data), &readSize);
ASSERT_EQ(ret, false);
HdfSBufRecycle(sBuf);
HdfSBufRecycle(readBuf);
}
+4 -27
View File
@@ -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_IF_H
+4 -27
View File
@@ -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_IF_H
+5 -27
View File
@@ -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_IF_H
@@ -38,6 +15,7 @@
#include "power_state_token_if.h"
struct IDevmgrService {
struct HdfObject base;
struct HdfDeviceObject object;
int (*AttachDeviceHost)(struct IDevmgrService *, uint16_t, struct IDevHostService *);
int (*AttachDevice)(struct IDevmgrService *, const struct HdfDeviceInfo *, struct IHdfDeviceToken *);
+4 -27
View File
@@ -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 DEVSVC_MANAGER_IF_H
+7 -28
View File
@@ -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_ATTRIBUTE_MANAGER_H
@@ -34,8 +11,10 @@
#include "hdf_slist.h"
const struct DeviceResourceNode *HdfGetRootNode(void);
bool HdfAttributeManagerGetHostList(struct HdfSList *hostList);
struct HdfSList *HdfAttributeManagerGetDeviceList(uint16_t hostId, const char *hostName);
void ReleaseHcsTree(void);
bool HdfDeviceListAdd(const char *moduleName, const char *serviceName);
void HdfDeviceListDel(const char *moduleName, const char *serviceName);
#endif /* HDF_ATTRIBUTE_MANAGER_H */
+6 -27
View File
@@ -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_INFO_H
@@ -37,6 +14,7 @@
struct HdfDeviceInfo {
struct HdfSListNode node;
bool isDynamic;
uint16_t hostId;
uint16_t deviceId;
uint16_t policy;
@@ -49,6 +27,7 @@ struct HdfDeviceInfo {
};
struct HdfDeviceInfo *HdfDeviceInfoNewInstance(void);
void HdfDeviceInfoConstruct(struct HdfDeviceInfo *deviceInfo);
void HdfDeviceInfoFreeInstance(struct HdfDeviceInfo *deviceInfo);
void HdfDeviceInfoDelete(struct HdfSListNode *listEntry);
+36 -31
View File
@@ -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_IO_SERVICE_H
@@ -38,14 +15,42 @@
extern "C" {
#endif /* __cplusplus */
#define DEV_NODE_PATH "/dev/"
#define DEV_NODE_PATH "/dev/hdf/"
#define DEV_PATH "/dev/"
#define DEV_MGR_NODE "dev_mgr"
#define MAX_MODE_SIZE 0777
#define DEV_NODE_PATH_MODE 0755
#define HDF_WRITE_READ _IOWR('b', 1, struct HdfSBuf)
#define HDF_READ_DEV_EVENT _IOR('b', 2, struct HdfSBuf)
#define HDF_LISTEN_EVENT_START _IO('b', 3)
#define HDF_LISTEN_EVENT_STOP _IO('b', 4)
#define HDF_LISTEN_EVENT_WAKEUP _IO('b', 5)
#define HDF_LISTEN_EVENT_EXIT _IO('b', 6)
struct HdfIoService *HdfIoServiceObtain(
struct HdfObject *object, struct HdfIoDispatcher *dispatcher);
struct HdfIoService *HdfIoServiceAdapterObtain(const char* serviceName, mode_t mode);
typedef enum {
DEVMGR_LOAD_SERVICE = 0,
DEVMGR_UNLOAD_SERVICE,
DEVMGR_GET_SERVICE,
} DevMgrCmd;
struct HdfWriteReadBuf {
int cmdCode;
size_t writeSize; // bytes to write
size_t writeConsumed; // bytes consumed by driver (for ERESTARTSYS)
uintptr_t writeBuffer;
size_t readSize; // bytes to read
size_t readConsumed; // bytes consumed by driver (for ERESTARTSYS)
uintptr_t readBuffer;
};
struct HdfIoService *HdfIoServicePublish(const char *serviceName, uint32_t mode);
void HdfIoServiceRemove(struct HdfIoService *service);
struct HdfIoService *HdfIoServiceAdapterObtain(const char *serviceName);
void HdfIoServiceAdapterRecycle(struct HdfIoService *service);
struct HdfIoService *HdfIoServiceAdapterPublish(const char *serviceName, uint32_t mode) __attribute__((weak));
void HdfIoServiceAdapterRemove(struct HdfIoService *service) __attribute__((weak));
int32_t HdfLoadDriverByServiceName(const char *serviceName);
#ifdef __cplusplus
}
+4 -28
View File
@@ -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 HDF_OBJECT_MANAGER_H
#define HDF_OBJECT_MANAGER_H
#include <stdio.h>
#include "hdf_object.h"
enum {
+4 -27
View File
@@ -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 DEVSVC_RECORD_H
+22 -45
View File
@@ -1,46 +1,23 @@
/*
* 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_IF_H
#define POWER_STATE_TOKEN_IF_H
typedef enum {
POWER_STATE_IDLE, /* Idle state */
POWER_STATE_ACTIVE, /* Activated state */
POWER_STATE_INACTIVE, /* Error state */
} HdfPowerState;
struct IPowerStateToken {
void (*AcquireWakeLock)(struct IPowerStateToken *);
void (*ReleaseWakeLock)(struct IPowerStateToken *);
};
/*
* 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_IF_H
#define POWER_STATE_TOKEN_IF_H
typedef enum {
POWER_STATE_IDLE, /* Idle state */
POWER_STATE_ACTIVE, /* Activated state */
POWER_STATE_INACTIVE, /* Error state */
} HdfPowerState;
struct IPowerStateToken {
void (*AcquireWakeLock)(struct IPowerStateToken *);
void (*ReleaseWakeLock)(struct IPowerStateToken *);
};
#endif /* POWER_STATE_TOKEN_IF_H */
+12 -28
View File
@@ -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_info.h"
@@ -35,8 +12,12 @@
#define HDF_LOG_TAG device_info
static void HdfDeviceInfoConstruct(struct HdfDeviceInfo *deviceInfo)
void HdfDeviceInfoConstruct(struct HdfDeviceInfo *deviceInfo)
{
if (deviceInfo == NULL) {
return;
}
deviceInfo->isDynamic = false;
deviceInfo->hostId = 0;
deviceInfo->deviceId = 0;
deviceInfo->policy = SERVICE_POLICY_INVALID;
@@ -63,6 +44,9 @@ struct HdfDeviceInfo *HdfDeviceInfoNewInstance()
void HdfDeviceInfoFreeInstance(struct HdfDeviceInfo *deviceInfo)
{
if (deviceInfo != NULL) {
if (deviceInfo->isDynamic && deviceInfo->svcName != NULL) {
OsalMemFree((void *)deviceInfo->svcName);
}
OsalMemFree(deviceInfo);
}
}
Executable → Regular
+21 -40
View File
@@ -1,51 +1,17 @@
/*
* 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_io_service.h"
#include "hdf_vnode_adapter.h"
struct HdfIoService *HdfIoServiceObtain(
struct HdfObject *object, struct HdfIoDispatcher *dispatcher)
struct HdfIoService *HdfIoServiceBind(const char *serviceName)
{
struct HdfIoService *service = HdfIoServiceAdapterObtain(NULL, 0);
if ((service != NULL) && (service->dispatcher == NULL)) {
service->dispatcher = dispatcher;
service->target = object;
}
return service;
}
struct HdfIoService *HdfIoServiceBind(const char *serviceName, mode_t permission)
{
return HdfIoServiceAdapterObtain(serviceName, permission);
return HdfIoServiceAdapterObtain(serviceName);
}
void HdfIoServiceRecycle(struct HdfIoService *service)
@@ -53,3 +19,18 @@ void HdfIoServiceRecycle(struct HdfIoService *service)
HdfIoServiceAdapterRecycle(service);
}
struct HdfIoService *HdfIoServicePublish(const char *serviceName, uint32_t mode)
{
if (HdfIoServiceAdapterPublish != NULL) {
return HdfIoServiceAdapterPublish(serviceName, mode);
}
return NULL;
}
void HdfIoServiceRemove(struct HdfIoService *service)
{
if (HdfIoServiceAdapterRemove != NULL) {
HdfIoServiceAdapterRemove(service);
}
}
+4 -27
View File
@@ -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_object_manager.h"
+4 -27
View File
@@ -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_record.h"
Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

+6 -29
View File
@@ -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.
*/
/**
@@ -127,8 +104,8 @@ struct DeviceResourceIface {
* @param node Indicates the pointer to the configuration tree node.
* @param attrName Indicates the pointer to the name of the attribute.
*
* @return Returns the value of the <b>BOOL</b> attribute if the operation is successful;
* returns <b>false</b> if <b>node</b> and <b>attrName</b> are null pointers.
* @return Returns <b>true</b> if the operation is successful and the value of the <b>BOOL</b> attribute is
* <b>true</b>; returns <b>false</b> otherwise.
* @since 1.0
* @version 1.0
*/
Executable → Regular
+24 -29
View File
@@ -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.
*/
/**
@@ -53,6 +30,7 @@
#define HDF_DEVICE_DESC_H
#include "hdf_device_section.h"
#include "hdf_io_service_if.h"
#include "hdf_object.h"
#include "hdf_sbuf.h"
@@ -95,6 +73,7 @@ typedef enum {
*/
typedef enum {
DEVICE_PRELOAD_ENABLE = 0, /**< The driver is loaded during system startup by default. */
DEVICE_PRELOAD_ENABLE_STEP2, /**< The driver is loaded after OS startup if quick start is enabled. */
DEVICE_PRELOAD_DISABLE, /**< The driver is not loaded during system startup by default. */
DEVICE_PRELOAD_INVALID /**< The loading policy is incorrect. */
} DevicePreload;
@@ -110,9 +89,12 @@ typedef enum {
struct HdfDeviceObject {
/** Pointer to the service interface object, which is registered with the HDF by the driver */
struct IDeviceIoService *service;
/** Pointer to the private data of the device, which is read by the HDF from the configuration file and
/** Pointer to the property of the device, which is read by the HDF from the configuration file and
transmitted to the driver. */
const struct DeviceResourceNode *property;
DeviceClass deviceClass;
/** Pointer to the private data of the device */
void *private;
};
/**
@@ -323,7 +305,6 @@ int32_t HdfDeviceSubscribeService(
*/
int32_t HdfDeviceSendEvent(const struct HdfDeviceObject *deviceObject, uint32_t id, const struct HdfSBuf *data);
/**
* @brief Sends an event message to a specified client object.
*
@@ -339,5 +320,19 @@ int32_t HdfDeviceSendEvent(const struct HdfDeviceObject *deviceObject, uint32_t
* @since 1.0 */
int32_t HdfDeviceSendEventToClient(const struct HdfDeviceIoClient *client, uint32_t id, const struct HdfSBuf *data);
/**
* @brief Sets the driver device class.
*
* After setting the driver device class, you can obtain the service name of this driver device type via
* {@link HdfGetServiceNameByDeviceClass}.
*
*
* @param deviceObject Indicates the pointer to the driver device object.
* @param deviceClass Indicates the device class defined by {@link DeviceClass}.
*
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
* @since 1.0 */
bool HdfDeviceSetClass(struct HdfDeviceObject *deviceObject, DeviceClass deviceClass);
#endif /* HDF_DEVICE_DESC_H */
/** @} */
Executable → Regular
+184 -41
View File
@@ -1,41 +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.
*/
/**
* @addtogroup Core
* @{
*
* @brief Provides OpenHarmony Driver Foundation (HDF) APIs.
* @brief Provides functions to use the Hardware Driver Foundation (HDF).
*
* The HDF implements driver framework capabilities such as driver loading, service management,
* and driver message model. You can develop drivers based on the HDF.
* The HDF implements driver framework capabilities such as driver loading, service management, driver message model,
* and power management. You can develop drivers based on the HDF.
*
* @since 1.0
*/
@@ -43,16 +20,16 @@
/**
* @file hdf_io_service_if.h
*
* @brief Declares the structures defining driver service objects and event listeners, as well as the functions for
* obtaining a driver service object, dispatching a driver service call, and registering or unregistering an
* event listener.
* @brief Declares the structures defining driver service objects and event listeners, as well as the functions
* for obtaining a driver service object, dispatching a driver service call, and registering or unregistering
* an event listener.
*
* @since 1.0
*/
#ifndef HDF_IO_SERVICE_IF_H
#define HDF_IO_SERVICE_IF_H
#include <sys/stat.h>
#include "hdf_dlist.h"
#include "hdf_object.h"
#include "hdf_sbuf.h"
@@ -61,6 +38,29 @@
extern "C" {
#endif /* __cplusplus */
struct HdfDevEventlistener;
struct HdfIoService;
/**
* @brief Enumerates different classes of driver devices.
*
* @since 1.0
*/
typedef enum {
/** Default device */
DEVICE_CLASS_DEFAULT = 0,
/** Platform device */
DEVICE_CLASS_PAL,
/** Sensor device */
DEVICE_CLASS_SENSOR,
/** Input device */
DEVICE_CLASS_INPUT,
/** Display device */
DEVICE_CLASS_DISPLAY,
/** Maximum value of a device class */
DEVICE_CLASS_MAX
} DeviceClass;
/**
* @brief Called when a driver event occurs.
*
@@ -75,17 +75,35 @@ extern "C" {
*/
typedef int (*OnEventReceived)(void *priv, uint32_t id, struct HdfSBuf *data);
/**
* @brief Called when a driver event occurs.
*
* You can implement this function and bind it to the custom {@link HdfDevEventlistener} object. \n
*
* @param listener Indicates the pointer to the listener that receives the driver event.
* @param service Indicates the pointer to the driver service object that generates the driver event.
* @param id Indicates the serial number of the driver event occurred.
* @param data Indicates the pointer to the content data of the driver event.
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
*
* @since 1.0
*/
typedef int (*OnDevEventReceive)(struct HdfDevEventlistener *listener,
struct HdfIoService *service, uint32_t id, struct HdfSBuf *data);
/**
* @brief Defines a driver event listener object.
*
* @since 1.0
*/
struct HdfDevEventlistener {
/** Callback invoked when the monitored device reports an event */
/** Deprecated. Use {@link onReceive} instead. */
OnEventReceived callBack;
/** Callback invoked when the monitored device reports an event */
OnDevEventReceive onReceive;
/** Intrusive list node used by the HDF to manage listeners. You can ignore this node. */
struct DListHead listNode;
/** Private data of the listener, which is passed as the first input parameter in <b>callback</b> */
/** Private data of the listener */
void *priv;
};
@@ -112,21 +130,102 @@ struct HdfIoService {
/** Pointer to the bound service entity, which is used for framework management. You can ignore it. */
struct HdfObject *target;
/** Service call dispatcher */
struct HdfIoDispatcher *dispatcher;
struct HdfIoDispatcher* dispatcher;
/** Private data of the service */
void* priv;
};
/**
* @brief Defines a driver service group object.
*
* @since 1.0
*/
struct HdfIoServiceGroup {
/** Base class object */
struct HdfObject object;
};
/**
* @brief Obtains an instance of the driver service group object.
*
* @return Returns the pointer to the driver service group object if the operation is successful;
* returns <b>NULL</b> otherwise.
*
* @since 1.0
*/
struct HdfIoServiceGroup *HdfIoServiceGroupObtain(void);
/**
* @brief Destroys a driver service group object.
*
* @param group Indicates the pointer to the driver service group object to destroy.
*
* @since 1.0
*/
void HdfIoServiceGroupRecycle(struct HdfIoServiceGroup *group);
/**
* @brief Adds a driver service object to a specified driver service group.
*
* @param group Indicates the pointer to the driver service group object to
* which the driver service object is to be added.
* @param service Indicates the pointer to the driver service object to add.
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
*
* @since 1.0
*/
int32_t HdfIoServiceGroupAddService(struct HdfIoServiceGroup *group, struct HdfIoService *service);
/**
* @brief Removes a driver service object from a specified driver service group.
*
* @param group Indicates the pointer to the driver service group object from
* which the driver service object is to be removed.
* @param service Indicates the pointer to the driver service object to remove.
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
*
* @since 1.0
*/
void HdfIoServiceGroupRemoveService(struct HdfIoServiceGroup *group, struct HdfIoService *service);
/**
* @brief Registers a custom {@link HdfDevEventlistener} for listening for events reported by driver services
* in a specified driver service group object.
*
* @param group Indicates the pointer to the driver service group object to listen to,
* which is obtained via {@link HdfIoServiceGroupObtain}.
* @param listener Indicates the pointer to the {@link HdfDevEventlistener} to register.
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
*
* @since 1.0
*/
int32_t HdfIoServiceGroupRegisterListener(struct HdfIoServiceGroup *group, struct HdfDevEventlistener *listener);
/**
* @brief Unregisters a previously registered {@link HdfDevEventlistener} that is used for listening for events
* reported by driver services in a specified driver service group object.
*
* @param group Indicates the pointer to the driver service group object that has been listened to.
* @param listener Indicates the pointer to the {@link HdfDevEventlistener} to unregister.
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
*
* @since 1.0
*/
int32_t HdfIoServiceGroupUnregisterListener(struct HdfIoServiceGroup *group, struct HdfDevEventlistener *listener);
/**
* @brief Obtains a driver service object.
*
*
*
* @param serviceName Indicates the pointer to the name of the service to obtain.
* @param permission Indicates the permission to create device nodes. The default value <b>0</b> can be used
* when this function is called from user space.
* @return Returns the pointer to the driver service object if the operation is successful;
* returns <b>NULL</b> otherwise.
*
* @since 1.0
*/
struct HdfIoService *HdfIoServiceBind(const char *serviceName, mode_t permission);
struct HdfIoService *HdfIoServiceBind(const char *serviceName);
/**
* @brief Destroys a specified driver service object to release resources if it is no longer required.
@@ -161,9 +260,53 @@ int HdfDeviceRegisterEventListener(struct HdfIoService *target, struct HdfDevEve
* @since 1.0
*/
int HdfDeviceUnregisterEventListener(struct HdfIoService *target, struct HdfDevEventlistener *listener);
/**
* @brief Obtains the number of event listeners that are registered for a specified driver service object.
*
* @param service Indicates the pointer to the driver service object for which the event listeners are registered.
* @return Returns the number of listeners if the operation is successful; returns a negative value otherwise.
*
* @since 1.0
*/
int HdfIoserviceGetListenerCount(const struct HdfIoService *service);
/**
* @brief Obtains the number of event listeners that are registered for a specified driver service group object.
*
* @param group Indicates the pointer to the driver service group object for which the event listeners are registered.
* @return Returns the number of listeners if the operation is successful; returns a negative value otherwise.
*
* @since 1.0
*/
int HdfIoserviceGroupGetListenerCount(const struct HdfIoServiceGroup *group);
/**
* @brief Obtains the number of driver services included in a specified driver service group.
*
* @param group Indicates the pointer to the driver service group object.
* @return Returns the number of services if the operation is successful; returns a negative value otherwise.
*
* @since 1.0
*/
int HdfIoserviceGroupGetServiceCount(const struct HdfIoServiceGroup *group);
/**
* @brief Obtains the names of device services of a specified device class defined by {@link DeviceClass}.
*
*
* @param deviceClass Indicates the device class to query.
* @param reply Indicates the pointer to the service name, which is stored as a string in an <b>HdfSBuf</b> structure.
* You can use {@link HdfSbufReadString} to continuously read the service names until a null pointer appears.
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
*
* @since 1.0
*/
int32_t HdfGetServiceNameByDeviceClass(DeviceClass deviceClass, struct HdfSBuf *reply);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* HDF_IO_SERVICE_IF_H */
/** @} */
Executable → Regular
+5 -28
View File
@@ -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.
*/
/**
@@ -52,7 +29,7 @@
#ifndef HDF_OBJECT_H
#define HDF_OBJECT_H
#include <stdint.h>
#include "hdf_base.h"
/**
* @brief Describes base class objects defined by the HDF.
Executable → Regular
+54 -181
View File
@@ -1,41 +1,20 @@
/*
* 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 WLAN
* @{
*
* @brief Defines a WLAN module that supports cross-OS migration, component adaptation, and modular assembly and
* compilation. Driver developers of WLAN vendors can adapt their driver code based on the unified APIs provided
* by the WLAN module.
* @brief Provides cross-OS migration, component adaptation, and modular assembly and compilation.
*
* Based on the unified APIs provided by the WLAN module, developers of the Hardware Driver Interface
* (HDI) are capable of creating, disabling, scanning for, and connecting to WLAN hotspots, managing WLAN chips,
* network devices, and power, and applying for, releasing, and moving network data buffers.
*
* @since 1.0
* @version 1.0
@@ -59,9 +38,7 @@
#ifndef HDF_NETBUF_H
#define HDF_NETBUF_H
#include "los_spinlock.h"
#include "hdf_dlist.h"
#include "lwip/pbuf.h"
#include "netbuf_adapter.h"
#ifdef __cplusplus
#if __cplusplus
@@ -69,82 +46,15 @@ extern "C" {
#endif
#endif /* __cplusplus */
/**
* @brief Enumerates the segments of a network data buffer.
*
* The entire network data buffer is divided into three segments: a header, data, and a tail.
* The header and tail are used to extend both ends of the data segment.
*
* @since 1.0
*/
enum {
E_HEAD_BUF, /**< Header buffer segment */
E_DATA_BUF, /**< Data segment */
E_TAIL_BUF, /**< Tail buffer segment */
MAX_BUF_NUM /**< Maximum number of buffer segments */
};
struct BufField {
uint32_t offset;
uint32_t len;
};
/**
* @brief Defines the reserved field of a network data buffer used to store private information.
*
* The length of the reserved field is <b>68</b> bytes.
*/
#define MAX_NETBUF_RESEVER_SIZE 68
/**
* @brief Records and saves a network data buffer.
*
* This structure is used to transmit network data between the protocol stack and network driver.
*
* @since 1.0
*/
struct NetBuf {
struct DListHead dlist; /**< Doubly linked list. Generally, multiple network data buffers are
linked by using a doubly linked list. */
struct BufField bufs[MAX_BUF_NUM]; /**< Defines buffer segments used to record the offset address
(based on the memory buffer address) and length of each buffer segment,
including the header buffer segment, data segment, and tail buffer segment.
For details, see {@link MAX_BUF_NUM}. */
uint8_t *mem; /**< Memory buffer address */
uint32_t len; /**< Length of the memory buffer */
uint32_t dataLen; /**< Actual data length of the network data buffer */
void *dev; /**< Network device that receives the network data */
uint32_t qmap; /**< Queue mappings of the network data buffer */
uint8_t rsv[MAX_NETBUF_RESEVER_SIZE]; /**< Reserved field. For details, see {@link MAX_NETBUF_RESEVER_SIZE}. */
};
/**
* @brief Indicates the queues for storing network data.
*
* Queues can be used to process multiple pieces of network data in a centralized manner, improving efficiency.
*
* @since 1.0
*/
struct NetBufQueue {
struct DListHead dlist; /**< Doubly linked list. Generally, multiple network data buffers are linked
by using a doubly linked list. */
uint32_t size; /**< Number of network data buffers in the queue */
struct Spinlock lock; /**< Queue operation lock */
};
/**
* @brief Initializes a network data buffer queue.
*
* @param q Indicates the pointer to the network data buffer queue.
*
* @since 1.0
* @version 1.0
*/
static inline void NetBufQueueInit(struct NetBufQueue *q)
{
DListHeadInit(&q->dlist);
LOS_SpinInit(&q->lock);
q->size = 0;
}
void NetBufQueueInit(NetBufQueue *q);
/**
* @brief Obtains the size of a network data buffer queue.
@@ -154,11 +64,9 @@ static inline void NetBufQueueInit(struct NetBufQueue *q)
* @return Returns the size of the network data buffer queue.
*
* @since 1.0
* @version 1.0
*/
static inline uint32_t NetBufQueueSize(const struct NetBufQueue *q)
{
return q->size;
}
uint32_t NetBufQueueSize(const NetBufQueue *q);
/**
* @brief Checks whether the network data buffer queue is empty.
@@ -168,11 +76,9 @@ static inline uint32_t NetBufQueueSize(const struct NetBufQueue *q)
* @return Returns <b>true</b> if the queue is empty; returns <b>false</b> otherwise.
*
* @since 1.0
* @version 1.0
*/
static inline bool NetBufQueueIsEmpty(const struct NetBufQueue *q)
{
return DListIsEmpty(&q->dlist);
}
bool NetBufQueueIsEmpty(const NetBufQueue *q);
/**
* @brief Adds a network data buffer to the tail of a queue.
@@ -181,8 +87,9 @@ static inline bool NetBufQueueIsEmpty(const struct NetBufQueue *q)
* @param nb Indicates the pointer to the network data buffer.
*
* @since 1.0
* @version 1.0
*/
void NetBufQueueEnqueue(struct NetBufQueue *q, struct NetBuf *nb);
void NetBufQueueEnqueue(NetBufQueue *q, NetBuf *nb);
/**
* @brief Adds a network data buffer to the header of a queue.
@@ -191,8 +98,9 @@ void NetBufQueueEnqueue(struct NetBufQueue *q, struct NetBuf *nb);
* @param nb Indicates the pointer to the network data buffer.
*
* @since 1.0
* @version 1.0
*/
void NetBufQueueEnqueueHead(struct NetBufQueue *q, struct NetBuf *nb);
void NetBufQueueEnqueueHead(NetBufQueue *q, NetBuf *nb);
/**
* @brief Obtains a network data buffer from the header of a queue and deletes it from the queue.
@@ -203,8 +111,9 @@ void NetBufQueueEnqueueHead(struct NetBufQueue *q, struct NetBuf *nb);
* returns <b>NULL</b> otherwise.
*
* @since 1.0
* @version 1.0
*/
struct NetBuf *NetBufQueueDequeue(struct NetBufQueue *q);
NetBuf *NetBufQueueDequeue(NetBufQueue *q);
/**
* @brief Obtains a network data buffer from the tail of a queue and deletes it from the queue.
@@ -215,8 +124,9 @@ struct NetBuf *NetBufQueueDequeue(struct NetBufQueue *q);
* returns <b>NULL</b> otherwise.
*
* @since 1.0
* @version 1.0
*/
struct NetBuf *NetBufQueueDequeueTail(struct NetBufQueue *q);
NetBuf *NetBufQueueDequeueTail(NetBufQueue *q);
/**
* @brief Obtains the network data buffer from the header of a queue, without deleting it from the queue.
@@ -227,11 +137,9 @@ struct NetBuf *NetBufQueueDequeueTail(struct NetBufQueue *q);
* returns <b>NULL</b> otherwise.
*
* @since 1.0
* @version 1.0
*/
static inline struct NetBuf *NetBufQueueAtHead(const struct NetBufQueue *q)
{
return (DListIsEmpty(&q->dlist)) ? NULL : DLIST_FIRST_ENTRY(&q->dlist, struct NetBuf, dlist);
}
NetBuf *NetBufQueueAtHead(const NetBufQueue *q);
/**
* @brief Obtains the network data buffer from the tail of a queue, without deleting it from the queue.
@@ -242,11 +150,9 @@ static inline struct NetBuf *NetBufQueueAtHead(const struct NetBufQueue *q)
* returns <b>NULL</b> otherwise.
*
* @since 1.0
* @version 1.0
*/
static inline struct NetBuf *NetBufQueueAtTail(const struct NetBufQueue *q)
{
return (DListIsEmpty(&q->dlist)) ? NULL : DLIST_LAST_ENTRY(&q->dlist, struct NetBuf, dlist);
}
NetBuf *NetBufQueueAtTail(const NetBufQueue *q);
/**
* @brief Clears a network data buffer queue and releases the network data buffer in the queue.
@@ -254,8 +160,9 @@ static inline struct NetBuf *NetBufQueueAtTail(const struct NetBufQueue *q)
* @param q Indicates the pointer to the network data buffer queue.
*
* @since 1.0
* @version 1.0
*/
void NetBufQueueClear(struct NetBufQueue *q);
void NetBufQueueClear(NetBufQueue *q);
/**
* @brief Moves all network data buffers from one queue to another and clears the source queue.
@@ -264,10 +171,9 @@ void NetBufQueueClear(struct NetBufQueue *q);
* @param add Indicates the pointer to the source network data buffer queue.
*
* @since 1.0
* @version 1.0
*/
void NetBufQueueConcat(struct NetBufQueue *q, struct NetBufQueue *add);
struct NetDevice;
void NetBufQueueConcat(NetBufQueue *q, NetBufQueue *add);
/**
* @brief Applies for a network data buffer.
@@ -278,8 +184,9 @@ struct NetDevice;
* returns <b>NULL</b> otherwise.
*
* @since 1.0
* @version 1.0
*/
struct NetBuf *NetBufAlloc(uint32_t size);
NetBuf *NetBufAlloc(uint32_t size);
/**
* @brief Releases a network data buffer.
@@ -287,9 +194,11 @@ struct NetBuf *NetBufAlloc(uint32_t size);
* @param nb Indicates the pointer to the network data buffer.
*
* @since 1.0
* @version 1.0
*/
void NetBufFree(struct NetBuf *nb);
void NetBufFree(NetBuf *nb);
struct NetDevice;
/**
* @brief Applies for a network data buffer based on the reserved space and requested size set by a network device.
*
@@ -300,8 +209,9 @@ void NetBufFree(struct NetBuf *nb);
* returns <b>NULL</b> otherwise.
*
* @since 1.0
* @version 1.0
*/
struct NetBuf *NetBufDevAlloc(const struct NetDevice *dev, uint32_t size);
NetBuf *NetBufDevAlloc(const struct NetDevice *dev, uint32_t size);
/**
* @brief Performs operations based on the segment ID of a network data buffer.
@@ -322,8 +232,9 @@ struct NetBuf *NetBufDevAlloc(const struct NetDevice *dev, uint32_t size);
* returns <b>NULL</b> if the operation length exceeds the space of a specified buffer segment.
*
* @since 1.0
* @version 1.0
*/
void *NetBufPush(struct NetBuf *nb, uint32_t id, uint32_t len);
void *NetBufPush(NetBuf *nb, uint32_t id, uint32_t len);
/**
* @brief Performs operations based on the segment ID of a network data buffer.
@@ -344,8 +255,9 @@ void *NetBufPush(struct NetBuf *nb, uint32_t id, uint32_t len);
* returns <b>NULL</b> if the operation length exceeds the space of a specified buffer segment.
*
* @since 1.0
* @version 1.0
*/
void *NetBufPop(struct NetBuf *nb, uint32_t id, uint32_t len);
void *NetBufPop(NetBuf *nb, uint32_t id, uint32_t len);
/**
* @brief Obtains the address of a specified buffer segment in a network data buffer.
@@ -357,15 +269,9 @@ void *NetBufPop(struct NetBuf *nb, uint32_t id, uint32_t len);
* returns <b>NULL</b> if the buffer segment ID is invalid.
*
* @since 1.0
* @version 1.0
*/
static inline uint8_t *NetBufGetAddress(const struct NetBuf *nb, uint32_t id)
{
if (id < MAX_BUF_NUM) {
return (nb->mem + nb->bufs[id].offset);
}
return NULL;
}
uint8_t *NetBufGetAddress(const NetBuf *nb, uint32_t id);
/**
* @brief Obtains the size of a specified buffer segment space in a network data buffer.
@@ -377,15 +283,9 @@ static inline uint8_t *NetBufGetAddress(const struct NetBuf *nb, uint32_t id)
* returns <b>NULL</b> if the buffer segment ID is invalid.
*
* @since 1.0
* @version 1.0
*/
static inline uint32_t NetBufGetRoom(const struct NetBuf *nb, uint32_t id)
{
if (id < MAX_BUF_NUM) {
return nb->bufs[id].len;
}
return 0;
}
uint32_t NetBufGetRoom(const NetBuf *nb, uint32_t id);
/**
* @brief Obtains the actual data length of the data segment of a network data buffer.
@@ -395,11 +295,9 @@ static inline uint32_t NetBufGetRoom(const struct NetBuf *nb, uint32_t id)
* @return Returns the actual data length of the data segment.
*
* @since 1.0
* @version 1.0
*/
static inline uint32_t NetBufGetDataLen(const struct NetBuf *nb)
{
return nb->dataLen;
}
uint32_t NetBufGetDataLen(const NetBuf *nb);
/**
* @brief Adjusts the size of a network data buffer space.
@@ -414,8 +312,9 @@ static inline uint32_t NetBufGetDataLen(const struct NetBuf *nb)
* @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
*
* @since 1.0
* @version 1.0
*/
int32_t NetBufResizeRoom(struct NetBuf *nb, uint32_t head, uint32_t tail);
int32_t NetBufResizeRoom(NetBuf *nb, uint32_t head, uint32_t tail);
/**
* @brief Copies data in a network data buffer to another network data buffer.
@@ -426,36 +325,9 @@ int32_t NetBufResizeRoom(struct NetBuf *nb, uint32_t head, uint32_t tail);
* @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
*
* @since 1.0
* @version 1.0
*/
uint32_t NetBufConcat(struct NetBuf *nb, struct NetBuf *cnb);
/**
* @brief Converts the <b>pbuf</b> structure of Lightweight TCP/IP Stack (lwIP) to a network data buffer.
*
* When a network device is specified, the reserved space of the network device will be added to
* the size of the converted network data buffer.
*
* @param netdev Indicates the pointer to the network device.
* @param lwip_buf Indicates the pointer to the data buffer of lwIP.
*
* @return Returns the pointer to the network data buffer if the operation is successful;
* returns <b>NULL</b> otherwise.
*
* @since 1.0
*/
struct NetBuf *Pbuf2NetBuf(const struct NetDevice *netdev, struct pbuf *lwipBuf);
/**
* @brief Converts a network data buffer to the <b>pbuf</b> structure of Lightweight TCP/IP Stack (lwIP).
*
* @param nb Indicates the pointer to the network data buffer.
*
* @return Returns the pointer to the <b>pbuf</b> structure if the operation is successful;
* returns <b>NULL</b> otherwise.
*
* @since 1.0
*/
struct pbuf *NetBuf2Pbuf(const struct NetBuf *nb);
int32_t NetBufConcat(NetBuf *nb, NetBuf *cnb);
#ifdef __cplusplus
#if __cplusplus
@@ -464,3 +336,4 @@ struct pbuf *NetBuf2Pbuf(const struct NetBuf *nb);
#endif /* __cplusplus */
#endif /* HDF_NETBUF_H */
/** @} */
Executable → Regular
+4 -27
View File
@@ -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 OSAL_H
Executable → Regular
+45 -37
View File
@@ -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.
*/
/**
@@ -35,7 +12,7 @@
*
* @brief Defines the structures and interfaces for the Operating System Abstraction Layer (OSAL) module.
*
* The OSAL module harmonizes OS interface differences and provides unified OS interfaces externally,
* The OSAL module OpenHarmony OS interface differences and provides unified OS interfaces externally,
* including the memory management, thread, mutex, spinlock, semaphore, timer, file, interrupt, time,
* atomic, firmware, and I/O operation modules.
*
@@ -60,7 +37,7 @@
#ifndef OSAL_ATOMIC_H
#define OSAL_ATOMIC_H
#include "hdf_base.h"
#include "osal_atomic_def.h"
#ifdef __cplusplus
extern "C" {
@@ -68,6 +45,9 @@ extern "C" {
/**
* @brief Describes an atomic.
*
* @since 1.0
* @version 1.0
*/
typedef struct {
volatile int32_t counter;/**< Counter (an atomic variable).
@@ -81,10 +61,11 @@ typedef struct {
* @param v Indicates the pointer to the atomic {@link OsalAtomic}.
*
* @return Returns the counter.
*
* @since 1.0
* @version 1.0
*/
int32_t OsalAtomicRead(const OsalAtomic *v);
#define OsalAtomicRead(v) OsalAtomicReadWrapper(v)
/**
* @brief Sets the counter for an atomic.
@@ -95,7 +76,7 @@ int32_t OsalAtomicRead(const OsalAtomic *v);
* @since 1.0
* @version 1.0
*/
void OsalAtomicSet(OsalAtomic *v, int32_t counter);
#define OsalAtomicSet(v, counter) OsalAtomicSetWrapper(v, counter)
/**
* @brief Increments the counter of an atomic by 1.
@@ -105,7 +86,19 @@ void OsalAtomicSet(OsalAtomic *v, int32_t counter);
* @since 1.0
* @version 1.0
*/
void OsalAtomicInc(OsalAtomic *v);
#define OsalAtomicInc(v) OsalAtomicIncWrapper(v)
/**
* @brief Increments the counter of an atomic by 1 and returns the new counter.
*
* @param v Indicates the pointer to the atomic {@link OsalAtomic}.
*
* @return Returns the new counter.
*
* @since 1.0
* @version 1.0
*/
#define OsalAtomicIncReturn(v) OsalAtomicIncRetWrapper(v)
/**
* @brief Decrements the counter of an atomic by 1.
@@ -115,7 +108,19 @@ void OsalAtomicInc(OsalAtomic *v);
* @since 1.0
* @version 1.0
*/
void OsalAtomicDec(OsalAtomic *v);
#define OsalAtomicDec(v) OsalAtomicDecWrapper(v)
/**
* @brief Decrements the counter of an atomic by 1 and returns the new counter.
*
* @param v Indicates the pointer to the atomic {@link OsalAtomic}.
*
* @return Returns the new counter.
*
* @since 1.0
* @version 1.0
*/
#define OsalAtomicDecReturn(v) OsalAtomicDecRetWrapper(v)
/**
* @brief Tests the value of a specified bit of a variable.
@@ -124,10 +129,11 @@ void OsalAtomicDec(OsalAtomic *v);
* @param addr Indicates the pointer to the variable.
*
* @return Returns the bit value.
*
* @since 1.0
* @version 1.0
*/
int32_t OsalTestBit(unsigned long nr, const volatile unsigned long *addr);
#define OsalTestBit(nr, addr) OsalTestBitWrapper(nr, addr)
/**
* @brief Sets the value of a specified bit of the variable and returns the bit value before the setting.
@@ -136,10 +142,11 @@ int32_t OsalTestBit(unsigned long nr, const volatile unsigned long *addr);
* @param addr Indicates the pointer to the variable.
*
* @return Returns the bit value before the setting.
*
* @since 1.0
* @version 1.0
*/
int32_t OsalTestSetBit(unsigned long nr, volatile unsigned long *addr);
#define OsalTestSetBit(nr, addr) OsalTestSetBitWrapper(nr, addr)
/**
* @brief Clears the value of a specified bit of the variable and returns the bit value before clearing.
@@ -148,10 +155,11 @@ int32_t OsalTestSetBit(unsigned long nr, volatile unsigned long *addr);
* @param addr Indicates the pointer to the variable.
*
* @return Returns the bit value before the bit is cleared.
*
* @since 1.0
* @version 1.0
*/
int32_t OsalTestClearBit(unsigned long nr, volatile unsigned long *addr);
#define OsalTestClearBit(nr, addr) OsalTestClearBitWrapper(nr, addr)
/**
* @brief Clears the value of a specified bit of the variable.
@@ -162,7 +170,7 @@ int32_t OsalTestClearBit(unsigned long nr, volatile unsigned long *addr);
* @since 1.0
* @version 1.0
*/
void OsalClearBit(unsigned long nr, volatile unsigned long *addr);
#define OsalClearBit(nr, addr) OsalClearBitWrapper(nr, addr)
#ifdef __cplusplus
}
+50
View File
@@ -0,0 +1,50 @@
/*
* 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 OSAL_CDEV_H
#define OSAL_CDEV_H
#include "osal_cdev_adapter.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#ifndef __user
#define __user
#endif
struct OsalCdev;
struct file;
struct OsalCdevOps {
int64_t (*seek)(struct file* filep, int64_t offset, int whence);
ssize_t (*read)(struct file* filep, char __user* buffer, size_t buflen, int64_t* offset);
ssize_t (*write)(struct file* filep, const char __user* buffer, size_t buflen, int64_t* offset);
unsigned int (*poll)(struct file* filep, poll_table* pollTable);
long (*ioctl)(struct file* filep, unsigned int cmd, unsigned long arg);
int (*open)(struct OsalCdev* cdev, struct file* filep);
int (*release)(struct OsalCdev* cdev, struct file* filep);
};
struct OsalCdev* OsalAllocCdev(const struct OsalCdevOps* fops);
int OsalRegisterCdev(struct OsalCdev* cdev, const char *name, unsigned int mode, void *priv);
void OsalUnregisterCdev(struct OsalCdev* cdev);
void OsalFreeCdev(struct OsalCdev* cdev);
void* OsalGetCdevPriv(struct OsalCdev* cdev);
void OsalSetFilePriv(struct file* filep, void *priv);
void* OsalGetFilePriv(struct file* filep);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* OSAL_CDEV_H */
/** @} */
Executable → Regular
+5 -29
View File
@@ -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.
*/
/**
@@ -35,7 +12,7 @@
*
* @brief Defines the structures and interfaces for the Operating System Abstraction Layer (OSAL) module.
*
* The OSAL module harmonizes OS interface differences and provides unified OS interfaces externally,
* The OSAL module OpenHarmony OS interface differences and provides unified OS interfaces externally,
* including the memory management, thread, mutex, spinlock, semaphore, timer, file, interrupt, time,
* atomic, firmware, and I/O operation modules.
*
@@ -58,7 +35,6 @@
#define OSAL_FILE_H
#include "hdf_base.h"
#include <fcntl.h>
#ifdef __cplusplus
extern "C" {
Executable → Regular
+5 -28
View File
@@ -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.
*/
/**
@@ -35,7 +12,7 @@
*
* @brief Defines the structures and interfaces for the Operating System Abstraction Layer (OSAL) module.
*
* The OSAL module harmonizes OS interface differences and provides unified OS interfaces externally,
* The OSAL module OpenHarmony OS interface differences and provides unified OS interfaces externally,
* including the memory management, thread, mutex, spinlock, semaphore, timer, file, interrupt, time,
* atomic, firmware, and I/O operation modules.
*
Executable → Regular
+6 -30
View File
@@ -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.
*/
/**
@@ -35,7 +12,7 @@
*
* @brief Defines the structures and interfaces for the Operating System Abstraction Layer (OSAL) module.
*
* The OSAL module harmonizes OS interface differences and provides unified OS interfaces externally,
* The OSAL module OpenHarmony OS interface differences and provides unified OS interfaces externally,
* including the memory management, thread, mutex, spinlock, semaphore, timer, file, interrupt, time,
* atomic, firmware, and I/O operation modules.
*
@@ -59,8 +36,7 @@
#ifndef OSAL_IO_H
#define OSAL_IO_H
#include <linux/io.h>
#include <linux/kernel.h>
#include "osal_io_adapter.h"
#ifdef __cplusplus
extern "C" {

Some files were not shown because too many files have changed in this diff Show More