更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
los_hook.h
浏览该文件的文档.
1/*
2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this list of
9 * conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 * of conditions and the following disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16 * to endorse or promote products derived from this software without specific prior written
17 * permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef _LOS_HOOK_H
33#define _LOS_HOOK_H
34
35#include "los_config.h"
36#include "los_err.h"
37#include "los_errno.h"
38
39#ifdef LOSCFG_KERNEL_HOOK
40#include "los_hook_types.h"
41#endif
42
43#ifdef __cplusplus
44#if __cplusplus
45extern "C" {
46#endif /* __cplusplus */
47#endif /* __cplusplus */
48
49#ifdef LOSCFG_KERNEL_HOOK
50/**
51 * @ingroup los_hook
52 * Hook error code: The hook pool is insufficient.
53 *
54 * Value: 0x02001f00
55 *
56 * Solution: Deregister the registered hook.
57 */
58#define LOS_ERRNO_HOOK_POOL_IS_FULL LOS_ERRNO_OS_ERROR(LOS_MOD_HOOK, 0x00) ///< 钩子池满了
59
60/**
61 * @ingroup los_hook
62 * Hook error code: Invalid parameter.
63 *
64 * Value: 0x02001f01
65 *
66 * Solution: Check the input parameters of LOS_HookReg.
67 */
68#define LOS_ERRNO_HOOK_REG_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HOOK, 0x01) ///< 钩子函数参数无效
69
70/**
71 * @ingroup los_hook
72 * Hook error code: Invalid parameter.
73 *
74 * Value: 0x02001f02
75 *
76 * Solution: Check the input parameters of LOS_HookUnReg.
77 */
78#define LOS_ERRNO_HOOK_UNREG_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HOOK, 0x02)
79
80/**
81 * @ingroup los_hook
82 * @brief Registration of hook function.
83 *
84 * @par Description:
85 * This API is used to register hook function.
86 *
87 * @attention
88 * <ul>
89 * <li> None.</li>
90 * </ul>
91 *
92 * @param hookType [IN] Register the type of the hook.
93 * @param hookFn [IN] The function to be registered.
94 *
95 * @retval None.
96 * @par Dependency:
97 * <ul><li>los_hook.h: the header file that contains the API declaration.</li></ul>
98 * @see
99 */
100#define LOS_HookReg(hookType, hookFn) hookType##_RegHook(hookFn) ///< 注册钩子函数
101
102/**
103 * @ingroup los_hook
104 * @brief Deregistration of hook function.
105 *
106 * @par Description:
107 * This API is used to deregister hook function.
108 *
109 * @attention
110 * <ul>
111 * <li> None.</li>
112 * </ul>
113 *
114 * @param hookType [IN] Deregister the type of the hook.
115 * @param hookFn [IN] The function to be deregistered.
116 *
117 * @retval None.
118 * @par Dependency:
119 * <ul><li>los_hook.h: the header file that contains the API declaration.</li></ul>
120 * @see
121 */
122#define LOS_HookUnReg(hookType, hookFn) hookType##_UnRegHook(hookFn) ///< 注销钩子函数
123
124/**
125 * Call hook functions.
126 */
127#define OsHookCall(hookType, ...) hookType##_CallHook(__VA_ARGS__) ///< 回调钩子函数
128
129#else
130#define LOS_HookReg(hookType, hookFn)
131#define LOS_HookUnReg(hookType, hookFn)
132#define OsHookCall(hookType, ...)
133#endif
134
135#ifdef __cplusplus
136#if __cplusplus
137}
138#endif /* __cplusplus */
139#endif /* __cplusplus */
140
141#endif /* _LOS_HOOK_H */