1%% 2%% %CopyrightBegin% 3%% 4%% Copyright Ericsson AB 2003-2016. 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 21%% 22%%---------------------------------------------------------------------- 23%% Purpose: Used when performing testing appup tests 24%% 25%% {ok, P} = megaco_appup_mgc:start(). 26%% megaco_appup_mgc:stop(P). 27%% megaco_appup_mgc:verbosity(P,silence). 28%% megaco_appup_mgc:verbosity(P,debug). 29%% 30%%---------------------------------------------------------------------- 31 32-module(megaco_appup_mgc). 33 34-export([start/0, start/1, stop/1]). 35-export([verbosity/2]). 36 37-export([main/2]). 38 39-define(START(Mid, ET, Verb), 40 megaco_test_mgc:start(node(), Mid, ET, Verb)). 41-define(STOP(Pid), megaco_test_mgc:stop(Pid)). 42-define(REQ_HANDS(Pid), megaco_test_mgc:request_handle_sloppy(Pid)). 43-define(VERBOSITY(Pid,V), megaco_test_mgc:verbosity(Pid,V)). 44 45 46%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 47 48start() -> 49 start(silence). 50start(V) -> 51 proc_lib:start_link(?MODULE, main, [self(), V]). 52 53stop(Pid) -> 54 Pid ! stop. 55 56verbosity(Pid, V) -> 57 Pid ! {verbosity, V}. 58 59 60%% ------------------------------------------------------------------------ 61 62main(Parent, V) -> 63 d("starting"), 64 Mgc = init(V), 65 proc_lib:init_ack(Parent, {ok, self()}), 66 d("started"), 67 loop(Mgc). 68 69init(V) -> 70 Mid = {deviceName, "mgc"}, 71 ET = [{text,tcp}, {text,udp}, {binary,tcp}, {binary,udp}], 72 73 d("start MGC"), 74 {ok, Mgc} = ?START(Mid, ET, debug), 75 76 ?VERBOSITY(Mgc, V), 77 78 Mgc. 79 80loop(Mgc) -> 81 d("awaiting request..."), 82 receive 83 84 stop -> 85 d("stopping"), 86 ?STOP(Mgc), 87 exit(normal); 88 89 {verbosity, V} -> 90 d("verbosity: ~p", [V]), 91 ?VERBOSITY(Mgc, V); 92 93 Any -> 94 error("received unknown request: ~n~p", [Any]) 95 96 end, 97 loop(Mgc). 98 99%% ------------------------------------------------------------------------ 100 101error(F, A) -> 102 io:format("AMGC-ERROR: " ++ F, A). 103 104d(F) -> 105 d(F, []). 106 107d(F, A) -> 108 io:format("AMGC: " ++ F ++ "~n", A). 109