aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ssh/test/ssh_eqc_event_handler.erl
blob: 233965012a30031a70f916e6b11bb92361073b53 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
-module(ssh_eqc_event_handler).

-compile(export_all).

-behaviour(gen_event).

add_report_handler() ->
    error_logger:add_report_handler(?MODULE, [self(),Ref=make_ref()]),
    receive
	{event_handler_started,HandlerPid,Ref} ->
	    {ok,HandlerPid}
    end.

get_reports(Pid) ->
    Pid ! {get_reports,self(),Ref=make_ref()},
    receive
	{reports,Reports,Ref} ->
	    {ok,Reports}
    end.

%%%================================================================

-record(state, {
	  reports = []
	 }).

%% error_logger:add_report_handler(ssh_eqc_event_handler, [self()]).

init([CallerPid,Ref]) -> 
    CallerPid ! {event_handler_started,self(),Ref},
    {ok, #state{}}.

handle_event(Event, State) ->
    {ok, State#state{reports = [Event|State#state.reports]}}.

handle_info({get_reports,From,Ref}, State) -> 
    From ! {reports, lists:reverse(State#state.reports), Ref},
    {ok, State#state{reports=[]}}.

handle_call(_Request, State) -> {ok,reply,State}.
terminate(_Arg, _State) -> stop.

code_change(_OldVsn, State, _Extra) -> {ok, State}.