1. New 一个SignalNode, 放入到全局数组中:g_signal_nodes
2. 创建 Class Closure:
1). 生成一个Closure
2). 指定Class member method 作为default handler
closure->notifiers[0].data = marshal_data; // default handler, 使用的是class的指针偏移
closure->notifiers[0].notify = (GClosureNotify) meta_marshal; //一般是g_type_class_meta_marshal 或者g_type_iface_meta_marshal
3. 指定SignalNode的C Marshaller:
node->c_marshaller = c_marshaller;
4. 把class closure放入SignalNode的成员数组中:
node->class_closure_bsa = g_bsearch_array_insert (node->class_closure_bsa, &g_class_closure_bconfig,
5. 指定这个class closure的C_Marshaller:
closure->marshal = node->c_marshaller
1. New 一个Handler
2. New 一个closure, 并让closure持有用户自己的callback: C Handler [User Handler]
3. 把handler放入全局的handler_list
4. 指定closure的marshaller:
handler->closure->marshal = node->marshaller;
1. 根据signal id, 找到signal node*
2. 对输入参数打包为GValue形式
3. 开始处理各种回调:
1)在class closure中,回调调用顺序:
meta_marshal --> C Marshaller --> Default Handler [call member method]
2) 在Handler list中
c_marsaller --> user callback
4. 返回数据再转回C语言形式
Signal New:
注册该信号的default handler + C_marshaller
Signal connect:
注册该信号的user handlers
Signal Emit:
分五个阶段:
阶段 | 标志 | 动作 |
1 | G_SIGNAL_RUN_FIRST | 调用class的default method handler |
2 | G_CONNECT_AFTER=FALSE | 调用user handlers |
3 | G_SIGNAL_RUN_LAST | 调用class的default method handler |
4 | G_CONNECT_AFTER=TRUE | 调用user handlers |
5 | G_SIGNAL_RUN_CLEANUP | 调用object method handler |