标签:
ejabberd_hooks作为ejabberd_sup的子进程以gen_server启动
首先初始化创建hooks(ets)表,
ejabberd_hooks作为系统的钩子server,注册一系列的方法到hooks里面,方便程序调用
注册方法为:
add(Hook, Host, Module, Function, Seq) ->
gen_server:call(ejabberd_hooks, {add, Hook, Host, Module, Function, Seq}).
-spec add_dist(atom(), atom(), atom(), atom() | fun(), number()) -> ok.
add_dist(Hook, Node, Module, Function, Seq) ->
gen_server:call(ejabberd_hooks, {add, Hook, global, Node, Module, Function, Seq}).
-spec add_dist(atom(), binary() | global, atom(), atom(), atom() | fun(), number()) -> ok.
add_dist(Hook, Host, Node, Module, Function, Seq) ->
gen_server:call(ejabberd_hooks, {add, Hook, Host, Node, Module, Function, Seq}).
删除方法为:
delete(Hook, Host, Module, Function, Seq) -> gen_server:call(ejabberd_hooks, {delete, Hook, Host, Module, Function, Seq}). delete_dist(Hook, Host, Node, Module, Function, Seq) -> gen_server:call(ejabberd_hooks, {delete, Hook, Host, Node, Module, Function, Seq}).
delete_all_hooks() ->
gen_server:call(ejabberd_hooks, {delete_all}).
调用为两个函数:
1、run(Hook, Host, Args) 根据hook名字依次调用,不管每次的调用结果
2、run_fold(Hook, Host, Val, Args) 根据hook名字依次调用,每次的调用结果下次继续使用
标签:
原文地址:http://www.cnblogs.com/lawen/p/5049668.html