Skip to content

githubChenchi/lib_callback

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

API说明手册


1. 概述

  实现了同一事件的发生支持多次回调函数的注册,这样可以在不同的程序文件中,对同一事件的发生进行不同的处理,以满足应用的需求。

  该库使用GCC编译,亲测OK。test文件夹内附有测试例程,如果在其它编译器下,编译出现问题,或不能正常运行,请根据所使用的编译器,优化代码。

  如果有需要优化的地方,或因为需要支持其它编译器而改变了代码,请新建分支,并提pull request,一起为开源做出贡献,谢谢!

2. 事件枚举、函数型指针、回调注册控制块结构 及 常量

2.1 事件枚举

typedef enum {
	EVENT_0,
	EVENT_1,
	EVENT_2,
	EVENT_3,
	EVENT_4,
	EVENT_5,
	EVENT_6,
	EVENT_7,
	EVENT_8,
	EVENT_9,
	EVENT_MAX	/* the max number of the event to be registered */
} event_t;

  根据不同的应用自行定义。

2.2 函数型指针

typedef int (* callback_t)(void * arg);

  定义callback_t函数指针数据类型,指向(输入参数为void * arg,返回值为int类型)的函数。

2.3 回调注册控制块结构

typedef struct {
	callback_t cb[REGISTER_NUM_MAX];	/* save the callback functions that have been registered */
	unsigned int count;					/* save the number of the callback functions that have been registered */
} callback_s;  

  成员cb保存同一事件每一个被注册的回调函数的入口地址。
  成员count保存同一事件被注册的回调函数的数目。

2.4 常量

#define REGISTER_NUM_MAX	10	/* the max number that is allowed to be registered of every single event */  

  指明每个事件最多被允许注册的回调函数的最大的数目。

3. API

  3.1 void callback_register( event_t event, callback_t cb_fn )

  参数

	event : 事件  
	cb_fn : 传递待注册的回调函数入口  

  返回值

  3.2 void callback_execute( event_t event )

  参数

	event : 事件  

  返回值

  3.2 void callback_unregister( event_t event, callback_t cb_fn )

  参数

	event : 事件  
	cb_fn : 传递待删除的回调函数入口  

  返回值

About

lib_callback

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy