4G_module/include/cmiot/cm_eloop.h

155 lines
3.7 KiB
C
Raw Permalink Normal View History

2024-09-02 17:54:29 +08:00
/**
* @file cm_eloop.h
* @brief Event Loop模块接口定义
* @copyright Copyright © 2021 China Mobile IOT. All rights reserved.
* @author By wangk
* @date 2021/08/06
*
* @defgroup eloop eloop
* @ingroup SYS
* @{
*/
#ifndef __CM_ELOOP_H__
#define __CM_ELOOP_H__
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdint.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/** 表示timeout不超时 */
#define CM_ELOOP_WAIT_FOREVER 0xFFFFFFFF
/****************************************************************************
* Public Types
****************************************************************************/
/** Event Loop对象句柄 */
struct cm_eloop_t;
typedef struct cm_eloop_t *cm_eloop_handle_t;
/** Event对象句柄 */
struct cm_eloop_event_t;
typedef struct cm_eloop_event_t *cm_eloop_event_handle_t;
/**
Event Loop回调函数类型
@param event [in]
@param cb_param [in]
*/
typedef void (*cm_eloop_event_cb)(cm_eloop_event_handle_t event, void *cb_param);
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C" {
#else
#define EXTERN extern
#endif
/**
* @brief Event Loop对象
*
* @return
* Event Loop对象
*
* @details Event Loop对象
*/
cm_eloop_handle_t cm_eloop_default(void);
/**
* @brief Event Loop对象
*
* @param [in] max_num
*
* @return
* Event Loop对象或NULL
*
* @details Event Loop对象()
*/
cm_eloop_handle_t cm_eloop_create(uint32_t max_num);
/**
* @brief Event Loop对象
*
* @param [in] eloop Event Loop对象
*
* @details Event Loop对象()
*/
void cm_eloop_delete(cm_eloop_handle_t eloop);
/**
* @brief Event触发或者超时时间到达
*
* @param [in] eloop Event Loop对象
* @param [in] timeout (ms), CM_ELOOP_WAIT_FOREVER表示不超时
*
* @return
* > 0 - \n
* = 0 - \n
* < 0 -
*
* @details
* 线, Event触发或者超时时间到达 \n
* Event触发,
*/
int32_t cm_eloop_wait_event(cm_eloop_handle_t eloop, uint32_t timeout);
/**
* @brief Event Loop
*
* @param [in] eloop Event Loop对象
* @param [in] event_cb
* @param [in] cb_param
*
* @return
* Event NULL
*
* @details
*/
cm_eloop_event_handle_t cm_eloop_register_event(cm_eloop_handle_t eloop, cm_eloop_event_cb event_cb, void *cb_param);
/**
* @brief Event Loop注销事件
*
* @param [in] event
*
* @details
*/
void cm_eloop_unregister_event(cm_eloop_event_handle_t event);
/**
* @brief Event Loop
*
* @param [in] event
*
* @return
* = 0 - \n
* < 0 -
*
* @details
*/
int32_t cm_eloop_post_event(cm_eloop_event_handle_t event);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __CM_ELOOP_H__ */
/** @}*/