obs源码分析 - signal
简介
Signals用于所有基于事件得回调
API
#include<callback/signal.h>
signal_handler_create
创建新的信号处理程序对象
signal_handler_t *signal_handler_create(void);
signal_handler_destroy
销毁信号处理程序。
void signal_handler_destroy(signal_handler_t* handler);
signal_handler_add
相信信号处理程序添加多个信号
- handler: 信号处理程序对象
- signal_decl: 信号声明字符串
bool signal_handler_add(signal_handler_t *handler, const char *signal_decl)
{
struct decl_info func = {0};
struct signal_info *sig, *last;
bool success = true;
if (!parse_decl_string(&func, signal_decl)) {
blog(LOG_ERROR, "Signal declaration invalid: %s", signal_decl);
return false;
}
pthread_mutex_lock(&handler->mutex);
sig = getsignal(handler, func.name, &last);
if (sig) {
blog(LOG_WARNING, "Signal declaration '%s' exists", func.name);
decl_info_free(&func);
success = false;
} else {
sig = signal_info_create(&func);
if (!last)
handler->first = sig;
else
last->next = sig;
}
pthread_mutex_unlock(&handler->mutex);
return success;
}
signal_handler_add_array
相信信号处理程序添加多个信号
- handler: 信号处理程序对象
- signal_decls: 信号声明字符串数组
static inline bool signal_handler_add_array(signal_handler_t *handler,
const char **signal_decls)
{
bool success = true;
if (!signal_decls)
return false;
while (*signal_decls)
if (!signal_handler_add(handler, *(signal_decls++)))
success = false;
return success;
}
signal_handler_connect
将回调连接到信号处理程序上的信号, 如果已经绑定,则不进行任何操作.
- handler: 信号处理程序对象
- signal: 要处理的信号名称
- callback: 信号回调
- data: 传递给回调的私有数据
void signal_handler_connect(signal_handler_t* handler,
const char* signal,
signal_callback_t callback,
void* data);
void signal_handler_connect_ref(signal_handler_t* handler,
const char* signal,
signal_callback_t callback,
void* data);
signal_handler_disconnect
断开回调与信号处理程序上的信号的连接。
- handler: 信号处理程序对象
- signal: 要处理的信号名称
- callback: 信号回调
- data: 传递给回调的私有数据
void signal_handler_disconnect(signal_handler_t* handler,
const char* signal,
signal_callback_t callback,
void* data);
signal_handler_signal
触发信号, 调用所有连接的回调
- handler: 信号处理程序对象
- signal: 要处理的信号名称
- params: 要传给信号的参数
void signal_handler_signal(signal_handler_t* handler, const char* signal, calldata_t* params);