1%% 2%% %CopyrightBegin% 3%% 4%% Copyright Ericsson AB 1996-2017. All Rights Reserved. 5%% 6%% Licensed under the Apache License, Version 2.0 (the "License"); 7%% you may not use this file except in compliance with the License. 8%% You may obtain a copy of the License at 9%% 10%% http://www.apache.org/licenses/LICENSE-2.0 11%% 12%% Unless required by applicable law or agreed to in writing, software 13%% distributed under the License is distributed on an "AS IS" BASIS, 14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15%% See the License for the specific language governing permissions and 16%% limitations under the License. 17%% 18%% %CopyrightEnd% 19%% 20-module(dummy_h). 21 22%% Test event handler for gen_event_SUITE.erl 23 24-export([init/1, handle_event/2, handle_call/2, handle_info/2, 25 terminate/2]). 26 27init(make_error) -> 28 {error, my_error}; 29init({state, State}) -> 30 {ok, State}; 31init([Parent]) -> 32 {ok, Parent}; %% We will send special responses for every handled event. 33init([Parent,hibernate]) -> 34 {ok, Parent, hibernate}. %% We will send special responses for every handled event. 35 36handle_event({swap_event,Mod,Args}, State) -> 37 {swap_handler, swap, State, Mod, Args}; 38handle_event(error_event, _State) -> 39 {return, faulty}; 40handle_event(do_crash, _State) -> 41 erlang:error({badmatch,4}); 42handle_event(hibernate, _State) -> 43 {ok,[],hibernate}; 44handle_event(wakeup, _State) -> 45 {ok,[]}; 46handle_event({From, handle_event}, _State) -> 47 From ! handled_event, 48 {ok,[]}; 49handle_event(Event, Parent) -> 50 Parent ! {dummy_h, Event}, 51 {ok, Parent}. 52 53handle_call(hejsan, State) -> 54 {ok, {ok, hejhopp}, State}; 55handle_call({swap_call,Mod,Args}, State) -> 56 {swap_handler, {ok, swapped}, swap, State, Mod, Args}; 57handle_call(error_call, _State) -> 58 {return, faulty}; 59handle_call(exit_call, _State) -> 60 erlang:error({badmatch,4}); 61handle_call(hibernate, _State) -> 62 {ok,true,[],hibernate}; 63handle_call(hibernate_later, _State) -> 64 timer:send_after(1000,sleep), 65 {ok,later,[]}; 66handle_call(_Query, State) -> 67 {ok, ok, State}. 68 69handle_info({swap_info,Mod,Args}, State) -> 70 {swap_handler, swap, State, Mod, Args}; 71handle_info(error_info, _State) -> 72 {return, faulty}; 73handle_info(do_crash, _State) -> 74 erlang:error({badmatch,4}); 75handle_info(sleep, _State) -> 76 {ok, [], hibernate}; 77handle_info(wake, _State) -> 78 {ok, []}; 79handle_info(gnurf, _State) -> 80 {ok, []}; 81handle_info({From, handle_info}, _State) -> 82 From ! handled_info, 83 {ok, []}; 84handle_info(Info, Parent) -> 85 Parent ! {dummy_h, Info}, 86 {ok, Parent}. 87 88terminate(return_hej, _State) -> 89 return_hej; 90terminate(swap, State) -> 91 {ok, State}; 92terminate({error, {return, faulty}}, Parent) -> 93 Parent ! {dummy_h, returned_error}; 94terminate(_Reason, {undef_in_terminate, {Mod, Fun}}) -> 95 Mod:Fun(), 96 ok; 97terminate(_Reason, _State) -> 98 ok. 99 100