13d8536b4Sopenharmony_ci/*
23d8536b4Sopenharmony_ci * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
33d8536b4Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
43d8536b4Sopenharmony_ci *
53d8536b4Sopenharmony_ci * Redistribution and use in source and binary forms, with or without modification,
63d8536b4Sopenharmony_ci * are permitted provided that the following conditions are met:
73d8536b4Sopenharmony_ci *
83d8536b4Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice, this list of
93d8536b4Sopenharmony_ci *    conditions and the following disclaimer.
103d8536b4Sopenharmony_ci *
113d8536b4Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice, this list
123d8536b4Sopenharmony_ci *    of conditions and the following disclaimer in the documentation and/or other materials
133d8536b4Sopenharmony_ci *    provided with the distribution.
143d8536b4Sopenharmony_ci *
153d8536b4Sopenharmony_ci * 3. Neither the name of the copyright holder nor the names of its contributors may be used
163d8536b4Sopenharmony_ci *    to endorse or promote products derived from this software without specific prior written
173d8536b4Sopenharmony_ci *    permission.
183d8536b4Sopenharmony_ci *
193d8536b4Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
203d8536b4Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
213d8536b4Sopenharmony_ci * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
223d8536b4Sopenharmony_ci * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
233d8536b4Sopenharmony_ci * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
243d8536b4Sopenharmony_ci * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
253d8536b4Sopenharmony_ci * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
263d8536b4Sopenharmony_ci * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
273d8536b4Sopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
283d8536b4Sopenharmony_ci * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
293d8536b4Sopenharmony_ci * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
303d8536b4Sopenharmony_ci */
313d8536b4Sopenharmony_ci
323d8536b4Sopenharmony_ci#ifndef _LOS_HOOK_H
333d8536b4Sopenharmony_ci#define _LOS_HOOK_H
343d8536b4Sopenharmony_ci
353d8536b4Sopenharmony_ci#include "internal/los_hook_types.h"
363d8536b4Sopenharmony_ci#include "los_config.h"
373d8536b4Sopenharmony_ci#include "los_error.h"
383d8536b4Sopenharmony_ci
393d8536b4Sopenharmony_ci#ifdef __cplusplus
403d8536b4Sopenharmony_ci#if __cplusplus
413d8536b4Sopenharmony_ciextern "C" {
423d8536b4Sopenharmony_ci#endif /* __cplusplus */
433d8536b4Sopenharmony_ci#endif /* __cplusplus */
443d8536b4Sopenharmony_ci
453d8536b4Sopenharmony_ci#if (LOSCFG_DEBUG_HOOK == 1)
463d8536b4Sopenharmony_ci/**
473d8536b4Sopenharmony_ci * @ingroup los_hook
483d8536b4Sopenharmony_ci * Hook error code: The hook pool is insufficient.
493d8536b4Sopenharmony_ci *
503d8536b4Sopenharmony_ci * Value: 0x02001f00
513d8536b4Sopenharmony_ci *
523d8536b4Sopenharmony_ci * Solution: Deregister the registered hook.
533d8536b4Sopenharmony_ci */
543d8536b4Sopenharmony_ci#define LOS_ERRNO_HOOK_POOL_IS_FULL             LOS_ERRNO_OS_ERROR(LOS_MOD_HOOK, 0x00)
553d8536b4Sopenharmony_ci
563d8536b4Sopenharmony_ci/**
573d8536b4Sopenharmony_ci * @ingroup los_hook
583d8536b4Sopenharmony_ci * Hook error code: Invalid parameter.
593d8536b4Sopenharmony_ci *
603d8536b4Sopenharmony_ci * Value: 0x02001f01
613d8536b4Sopenharmony_ci *
623d8536b4Sopenharmony_ci * Solution: Check the input parameters of LOS_HookReg.
633d8536b4Sopenharmony_ci */
643d8536b4Sopenharmony_ci#define LOS_ERRNO_HOOK_REG_INVALID              LOS_ERRNO_OS_ERROR(LOS_MOD_HOOK, 0x01)
653d8536b4Sopenharmony_ci
663d8536b4Sopenharmony_ci/**
673d8536b4Sopenharmony_ci * @ingroup los_hook
683d8536b4Sopenharmony_ci * Hook error code: Invalid parameter.
693d8536b4Sopenharmony_ci *
703d8536b4Sopenharmony_ci * Value: 0x02001f02
713d8536b4Sopenharmony_ci *
723d8536b4Sopenharmony_ci * Solution: Check the input parameters of LOS_HookUnReg.
733d8536b4Sopenharmony_ci */
743d8536b4Sopenharmony_ci#define LOS_ERRNO_HOOK_UNREG_INVALID            LOS_ERRNO_OS_ERROR(LOS_MOD_HOOK, 0x02)
753d8536b4Sopenharmony_ci
763d8536b4Sopenharmony_ci/**
773d8536b4Sopenharmony_ci * @ingroup los_hook
783d8536b4Sopenharmony_ci * @brief Registration of hook function.
793d8536b4Sopenharmony_ci *
803d8536b4Sopenharmony_ci * @par Description:
813d8536b4Sopenharmony_ci * This API is used to register hook function.
823d8536b4Sopenharmony_ci *
833d8536b4Sopenharmony_ci * @attention
843d8536b4Sopenharmony_ci * <ul>
853d8536b4Sopenharmony_ci * <li> None.</li>
863d8536b4Sopenharmony_ci * </ul>
873d8536b4Sopenharmony_ci *
883d8536b4Sopenharmony_ci * @param hookType  [IN] Register the type of the hook.
893d8536b4Sopenharmony_ci * @param hookFn  [IN] The function to be registered.
903d8536b4Sopenharmony_ci *
913d8536b4Sopenharmony_ci * @retval None.
923d8536b4Sopenharmony_ci * @par Dependency:
933d8536b4Sopenharmony_ci * <ul><li>los_hook.h: the header file that contains the API declaration.</li></ul>
943d8536b4Sopenharmony_ci * @see
953d8536b4Sopenharmony_ci */
963d8536b4Sopenharmony_ci#define LOS_HookReg(hookType, hookFn)           hookType##_RegHook(hookFn)
973d8536b4Sopenharmony_ci
983d8536b4Sopenharmony_ci/**
993d8536b4Sopenharmony_ci * @ingroup los_hook
1003d8536b4Sopenharmony_ci * @brief Deregistration of hook function.
1013d8536b4Sopenharmony_ci *
1023d8536b4Sopenharmony_ci * @par Description:
1033d8536b4Sopenharmony_ci * This API is used to deregister hook function.
1043d8536b4Sopenharmony_ci *
1053d8536b4Sopenharmony_ci * @attention
1063d8536b4Sopenharmony_ci * <ul>
1073d8536b4Sopenharmony_ci * <li> None.</li>
1083d8536b4Sopenharmony_ci * </ul>
1093d8536b4Sopenharmony_ci *
1103d8536b4Sopenharmony_ci * @param hookType  [IN] Deregister the type of the hook.
1113d8536b4Sopenharmony_ci * @param hookFn  [IN] The function to be deregistered.
1123d8536b4Sopenharmony_ci *
1133d8536b4Sopenharmony_ci * @retval None.
1143d8536b4Sopenharmony_ci * @par Dependency:
1153d8536b4Sopenharmony_ci * <ul><li>los_hook.h: the header file that contains the API declaration.</li></ul>
1163d8536b4Sopenharmony_ci * @see
1173d8536b4Sopenharmony_ci */
1183d8536b4Sopenharmony_ci#define LOS_HookUnReg(hookType, hookFn)         hookType##_UnRegHook(hookFn)
1193d8536b4Sopenharmony_ci
1203d8536b4Sopenharmony_ci/**
1213d8536b4Sopenharmony_ci * Call hook functions.
1223d8536b4Sopenharmony_ci */
1233d8536b4Sopenharmony_ci#define OsHookCall(hookType, ...)               hookType##_CallHook(__VA_ARGS__)
1243d8536b4Sopenharmony_ci
1253d8536b4Sopenharmony_ci#else
1263d8536b4Sopenharmony_ci#define LOS_HookReg(hookType, hookFn)
1273d8536b4Sopenharmony_ci#define LOS_HookUnReg(hookType, hookFn)
1283d8536b4Sopenharmony_ci#define OsHookCall(hookType, ...)
1293d8536b4Sopenharmony_ci#endif
1303d8536b4Sopenharmony_ci
1313d8536b4Sopenharmony_ci#ifdef __cplusplus
1323d8536b4Sopenharmony_ci#if __cplusplus
1333d8536b4Sopenharmony_ci}
1343d8536b4Sopenharmony_ci#endif /* __cplusplus */
1353d8536b4Sopenharmony_ci#endif /* __cplusplus */
1363d8536b4Sopenharmony_ci
1373d8536b4Sopenharmony_ci#endif /* _LOS_HOOK_H */
138