Permalink
Browse files

Update the return from init/2 to be {ok, NewState} or {ok,NewState,Pr…

…iority} instead of NewState.

NewState can still be returned, but is only kept for backward compatability reasons.
  • Loading branch information...
1 parent 6b9f8b5 commit 187cf0a2a5cb5cc5f94e2b9bb07b03955ad6eb4d @garazdawi garazdawi committed Jul 29, 2011
@@ -135,10 +135,19 @@ call_id(#ct_hook_config{ module = Mod, opts = Opts} = Hook, Config, Scope) ->
Id = catch_apply(Mod,id,[Opts], make_ref()),
{Config, Hook#ct_hook_config{ id = Id, scope = scope(Scope)}}.
-call_init(#ct_hook_config{ module = Mod, opts = Opts, id = Id} = Hook,
+call_init(#ct_hook_config{ module = Mod, opts = Opts, id = Id, prio = P} = Hook,
Config,_Meta) ->
- NewState = Mod:init(Id, Opts),
- {Config, Hook#ct_hook_config{ state = NewState } }.
+ case Mod:init(Id, Opts) of
+ {ok, NewState} ->
+ {Config, Hook#ct_hook_config{ state = NewState } };
+ {ok, NewState, Prio} when P =:= undefined ->
+ %% Only set prio if not already set when installing hook
+ {Config, Hook#ct_hook_config{ state = NewState, prio = Prio } };
+ {ok, NewState, _} ->
+ {Config, Hook#ct_hook_config{ state = NewState } };
+ NewState -> %% Keep for backward compatability reasons
+ {Config, Hook#ct_hook_config{ state = NewState } }
+ end.
call_terminate(#ct_hook_config{ module = Mod, state = State} = Hook, _, _) ->
catch_apply(Mod,terminate,[State], ok),
@@ -71,11 +71,11 @@
%% @doc Always called before any other callback function. Use this to initiate
%% any common state. It should return an state for this CTH.
-spec init(Id :: term(), Opts :: proplists:proplist()) ->
- State :: #state{}.
+ {ok, State :: #state{}}.
init(Id, Opts) ->
gen_event:notify(?CT_EVMGR_REF, #event{ name = cth, node = node(),
data = {?MODULE, init, [Id, Opts]}}),
- Opts.
+ {ok,Opts}.
%% @doc The ID is used to uniquly identify an CTH instance, if two CTH's
%% return the same ID the seconds CTH is ignored. This function should NOT
@@ -29,7 +29,7 @@
init(Id, Opts) ->
State = empty_cth:init(Id, Opts),
- [init|State].
+ {ok, [init|State]}.
pre_init_per_suite(Suite, Config, State) ->
empty_cth:pre_init_per_suite(Suite,Config,State),

0 comments on commit 187cf0a

Please sign in to comment.