From 9deb294328bb3f9eb6bd2c0e7cd500732e9b5830 Mon Sep 17 00:00:00 2001 From: Badlop Date: Thu, 14 Mar 2013 10:33:02 +0100 Subject: Accumulated patch to binarize and indent code --- src/ejabberd_hooks.erl | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'src/ejabberd_hooks.erl') diff --git a/src/ejabberd_hooks.erl b/src/ejabberd_hooks.erl index 26573aa7d..e4f9f597b 100644 --- a/src/ejabberd_hooks.erl +++ b/src/ejabberd_hooks.erl @@ -67,58 +67,76 @@ start_link() -> gen_server:start_link({local, ejabberd_hooks}, ejabberd_hooks, [], []). -%% @spec (Hook::atom(), Function::function(), Seq::integer()) -> ok +-spec add(atom(), fun(), number()) -> any(). + %% @doc See add/4. add(Hook, Function, Seq) when is_function(Function) -> add(Hook, global, undefined, Function, Seq). +-spec add(atom(), binary() | atom(), fun() | atom() , number()) -> any(). add(Hook, Host, Function, Seq) when is_function(Function) -> add(Hook, Host, undefined, Function, Seq); -%% @spec (Hook::atom(), Module::atom(), Function::atom(), Seq::integer()) -> ok %% @doc Add a module and function to this hook. %% The integer sequence is used to sort the calls: low number is called before high number. add(Hook, Module, Function, Seq) -> add(Hook, global, Module, Function, Seq). +-spec add(atom(), binary() | global, atom(), atom() | fun(), number()) -> any(). + 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()) -> any(). + 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()) -> any(). + add_dist(Hook, Host, Node, Module, Function, Seq) -> gen_server:call(ejabberd_hooks, {add, Hook, Host, Node, Module, Function, Seq}). -%% @spec (Hook::atom(), Function::function(), Seq::integer()) -> ok +-spec delete(atom(), fun(), number()) -> ok. + %% @doc See del/4. delete(Hook, Function, Seq) when is_function(Function) -> delete(Hook, global, undefined, Function, Seq). +-spec delete(atom(), binary() | atom(), atom() | fun(), number()) -> ok. + delete(Hook, Host, Function, Seq) when is_function(Function) -> delete(Hook, Host, undefined, Function, Seq); -%% @spec (Hook::atom(), Module::atom(), Function::atom(), Seq::integer()) -> ok %% @doc Delete a module and function from this hook. %% It is important to indicate exactly the same information than when the call was added. delete(Hook, Module, Function, Seq) -> delete(Hook, global, Module, Function, Seq). +-spec delete(atom(), binary() | global, atom(), atom() | fun(), number()) -> ok. + delete(Hook, Host, Module, Function, Seq) -> gen_server:call(ejabberd_hooks, {delete, Hook, Host, Module, Function, Seq}). +-spec delete_dist(atom(), atom(), atom(), atom() | fun(), number()) -> ok. + delete_dist(Hook, Node, Module, Function, Seq) -> delete_dist(Hook, global, Node, Module, Function, Seq). +-spec delete_dist(atom(), binary() | global, atom(), atom(), atom() | fun(), number()) -> ok. + delete_dist(Hook, Host, Node, Module, Function, Seq) -> gen_server:call(ejabberd_hooks, {delete, Hook, Host, Node, Module, Function, Seq}). -%% @spec (Hook::atom(), Args) -> ok +-spec run(atom(), list()) -> ok. + %% @doc Run the calls of this hook in order, don't care about function results. %% If a call returns stop, no more calls are performed. run(Hook, Args) -> run(Hook, global, Args). +-spec run(atom(), binary() | global, list()) -> ok. + run(Hook, Host, Args) -> case ets:lookup(hooks, {Hook, Host}) of [{_, Ls}] -> @@ -127,7 +145,8 @@ run(Hook, Host, Args) -> ok end. -%% @spec (Hook::atom(), Val, Args) -> Val | stopped | NewVal +-spec run_fold(atom(), any(), list()) -> any(). + %% @doc Run the calls of this hook in order. %% The arguments passed to the function are: [Val | Args]. %% The result of a call is used as Val for the next call. @@ -136,6 +155,8 @@ run(Hook, Host, Args) -> run_fold(Hook, Val, Args) -> run_fold(Hook, global, Val, Args). +-spec run_fold(atom(), binary() | global, any(), list()) -> any(). + run_fold(Hook, Host, Val, Args) -> case ets:lookup(hooks, {Hook, Host}) of [{_, Ls}] -> -- cgit v1.2.3