📄 megaco_test_mgc.erl
字号:
handle_megaco_request({handle_trans_request_abort, CH, PV, TI, Handler}, S) -> d("handle_megaco_request(handle_trans_request_abort) -> entry with" "~n CH: ~p" "~n PV: ~p" "~n TI: ~p" "~n Handler: ~p", [CH, PV, TI, Handler]), Reply = case S#mgc.abort_info of P when pid(P) -> P ! {abort_received, self(), TI}, ok; _ -> ok end, {Reply, S}.do_handle_trans_request(CH, PV, ARs, #mgc{req_action = Action, req_timeout = To} = S) -> d("do_handle_megaco_request(handle_trans_request) -> entry with" "~n Action: ~p" "~n To: ~p", [Action, To]), case handle_act_requests(CH, PV, ARs, Action) of {pending_ignore, ActReqs} -> {{pending, ActReqs}, S#mgc{req_action = ignore}}; Reply -> {{delay_reply, To, Reply}, S} end.handle_act_requests(_CH, _PV, _ActReqs, ignore) -> ignore;handle_act_requests(_CH, _PV, ActReqs, pending) -> {pending, ActReqs};handle_act_requests(_CH, _PV, ActReqs, pending_ignore) -> {pending_ignore, ActReqs};handle_act_requests(CH, PV, ActReqs, handle_ack) -> Reply = (catch do_handle_act_requests(CH, PV, ActReqs, [])), {{handle_ack, ActReqs}, Reply};handle_act_requests(CH, PV, ActReqs, handle_sloppy_ack) -> Reply = (catch do_handle_act_requests(CH, PV, ActReqs, [])), {{handle_sloppy_ack, ActReqs}, Reply};handle_act_requests(CH, PV, ActReqs, _) -> Reply = (catch do_handle_act_requests(CH, PV, ActReqs, [])), {discard_ack, Reply}.do_handle_act_requests(_CH, _PV, [], ActReplies) -> lists:reverse(ActReplies);do_handle_act_requests(CH, PV, [ActReq|ActReqs], ActReplies) -> ActReply = handle_act_request(CH, PV, ActReq), do_handle_act_requests(CH, PV, ActReqs, [ActReply|ActReplies]). handle_act_request(CH, PV, ActReq) -> #'ActionRequest'{contextId = CtxId, commandRequests = Cmds} = ActReq, CmdReplies = handle_cmd_requests(CH, PV, CtxId, Cmds), #'ActionReply'{contextId = CtxId, commandReply = CmdReplies}.handle_cmd_requests(CH, PV, ?megaco_null_context_id, [#'CommandRequest'{command={serviceChangeReq,Req}}]) -> Rep = service_change(CH, PV, Req), [{serviceChangeReply, Rep}];handle_cmd_requests(CH, PV, CtxId, Cmds) -> do_handle_cmd_requests(CH, PV, CtxId, Cmds, []).do_handle_cmd_requests(_CH, _PV, _CtxId, [], CmdReplies) -> lists:reverse(CmdReplies);do_handle_cmd_requests(CH, PV, CtxId, [Cmd|Cmds], CmdReplies) -> CmdReply = handle_cmd_request(CH, PV, CtxId, Cmd), do_handle_cmd_requests(CH, PV, CtxId, Cmds, [CmdReply|CmdReplies]).handle_cmd_request(CH, PV, CtxId, #'CommandRequest'{command = {Tag,Req}}) -> case Tag of notifyReq -> (catch handle_notify_req(CH,PV,CtxId,Req)); serviceChangeReq -> ED = cre_error_descr(?megaco_not_implemented, "Service change only allowed " "on null context handled"), throw(ED); _ -> Code = ?megaco_not_implemented, ED = cre_error_descr(Code,"Unknown command requst received:" "~n Tag: ~p~n Req: ~p",[Tag,Req]), throw(ED) end.handle_notify_req(CH, PV, CtxId, #'NotifyRequest'{terminationID = [Tid], observedEventsDescriptor = EvDesc}) -> handle_event(CH, PV, CtxId, Tid, EvDesc).handle_event(_CH, _PV, _Cid, Tid, EvDesc) -> d("handle_event -> received" "~n EvDesc: ~p" "~n Tid: ~p", [EvDesc, Tid]), {notifyReply, cre_notifyRep(Tid)}. service_change(CH, _PV, SCR) -> SCP = SCR#'ServiceChangeRequest'.serviceChangeParms, #'ServiceChangeParm'{serviceChangeAddress = Address, serviceChangeProfile = Profile, serviceChangeReason = [_Reason]} = SCP, TermId = SCR#'ServiceChangeRequest'.terminationID, if TermId == [?megaco_root_termination_id] -> MyMid = CH#megaco_conn_handle.local_mid, Res = {serviceChangeResParms, cre_serviceChangeResParms(MyMid, Address, Profile)}, cre_serviceChangeReply(TermId, Res); true -> Res = {errorDescriptor, cre_error_descr(?megaco_not_implemented, "Only handled for root")}, cre_serviceChangeReply(TermId, Res) end. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% cre_serviceChangeReply(TermId, Result) -> #'ServiceChangeReply'{terminationID = TermId, serviceChangeResult = Result}.cre_serviceChangeResParms(Mid, Addr, Prof) -> #'ServiceChangeResParm'{serviceChangeMgcId = Mid, serviceChangeAddress = Addr, serviceChangeProfile = Prof}.cre_notifyRep(Tid) -> #'NotifyReply'{terminationID = [Tid]}.% cre_notifyRep(Tid,Err) ->% #'NotifyReply'{terminationID = [Tid], errorDescriptor = Err}.cre_error_descr(Code,Text) -> #'ErrorDescriptor'{errorCode = Code, errorText = Text}.cre_error_descr(Code,FormatString,Args) -> Text = lists:flatten(io_lib:format(FormatString,Args)), cre_error_descr(Code,Text).%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%notify_started(Parent) -> Parent ! {started, self()}.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% The megaco user callback interface handle_connect(CH, PV, Pid) -> case CH#megaco_conn_handle.remote_mid of preliminary_mid -> %% Avoids deadlock ok; _ -> Reply = request(Pid, {handle_connect, CH, PV}), Reply end.handle_disconnect(_CH, _PV, {user_disconnect, {Pid, ignore}}, Pid) -> ok;handle_disconnect(CH, _PV, {user_disconnect, {Pid, cancel}}, Pid) -> megaco:cancel(CH, disconnected), ok;handle_disconnect(CH, PV, R, Pid) -> request(Pid, {handle_disconnect, CH, PV, R}).handle_syntax_error(ReceiveHandle, ProtocolVersion, ErrorDescriptor, Pid) -> Req = {handle_syntax_error, ReceiveHandle, ProtocolVersion, ErrorDescriptor}, request(Pid, Req). handle_message_error(ConnHandle, ProtocolVersion, ErrorDescriptor, Pid) -> Req = {handle_message_error, ConnHandle, ProtocolVersion, ErrorDescriptor}, request(Pid, Req).handle_trans_request(CH, PV, AR, Pid) -> Reply = request(Pid, {handle_trans_request, CH, PV, AR}), Reply.handle_trans_long_request(ConnHandle, ProtocolVersion, ReqData, Pid) -> Req = {handle_trans_long_request, ConnHandle, ProtocolVersion, ReqData}, request(Pid, Req).handle_trans_reply(ConnHandle, ProtocolVersion, ActualReply, ReplyData, Pid) -> Req = {handle_trans_reply, ConnHandle, ProtocolVersion, ActualReply, ReplyData}, request(Pid, Req).handle_trans_ack(ConnHandle, ProtocolVersion, AckStatus, AckData, Pid) -> Req = {handle_trans_ack, ConnHandle, ProtocolVersion, AckStatus, AckData}, request(Pid, Req).handle_unexpected_trans(ConnHandle, ProtocolVersion, Trans, Pid) -> Req = {handle_unexpected_trans, ConnHandle, ProtocolVersion, Trans}, request(Pid, Req).handle_trans_request_abort(ConnHandle, ProtocolVersion, TransId, Handler, Pid) -> Req = {handle_trans_request_abort, ConnHandle, ProtocolVersion, TransId, Handler}, request(Pid, Req).request(Pid, Request) -> Pid ! {request, Request, self()}, receive {reply, {delay_reply, To, Reply}, Pid} -> megaco:report_event(ignore, self(), Pid, "reply: delay_reply", [To, Reply]), sleep(To), megaco:report_event(ignore, self(), Pid, "reply: delay done now return", []), Reply; {reply, {exit, To, Reason}, Pid} -> megaco:report_event(ignore, self(), Pid, "reply: exit", [To, Reason]), sleep(To), megaco:report_event(ignore, self(), Pid, "reply: sleep done now exit", []), exit(Reason); {reply, Reply, Pid} -> megaco:report_event(ignore, self(), Pid, "reply", [Reply]), Reply end.reply(To, Reply) -> To ! {reply, Reply, self()}.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%sleep(X) -> d("sleep -> ~w", [X]), receive after X -> ok end.error_msg(F,A) -> error_logger:error_msg("MGC: " ++ F ++ "~n",A).get_encoding_module(RI) -> case (catch get_conf(encoding_module, RI)) of {error, _} -> undefined; Val -> Val end.get_encoding_config(RI, EM) -> case text_codec(EM) of true -> case megaco:system_info(text_config) of [Conf] when list(Conf) -> Conf; _ -> [] end; false -> get_conf(encoding_config, RI) end.text_codec(megaco_compact_text_encoder) -> true;text_codec(megaco_pretty_text_encoder) -> true;text_codec(_) -> false.get_transport_module(RI) -> get_conf(transport_module, RI).get_transport_port(RI) -> get_conf(port, RI).get_conf(Key, Config) -> case lists:keysearch(Key, 1, Config) of {value, {Key, Val}} -> Val; _ -> exit({error, {not_found, Key, Config}}) end.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%i(F) -> i(F, []).i(F, A) -> print(info, get(verbosity), "", F, A).d(F) -> d(F, []).d(F, A) -> print(debug, get(verbosity), "DBG: ", F, A).printable(_, debug) -> true;printable(info, info) -> true;printable(_,_) -> false.print(Severity, Verbosity, P, F, A) -> print(printable(Severity,Verbosity), P, F, A).print(true, P, F, A) -> print(P, F, A);print(_, _, _, _) -> ok.print(P, F, A) -> io:format("*** [~s] ~s ~p ~s ***" "~n " ++ F ++ "~n~n", [format_timestamp(now()), P, self(), get(sname) | A]).format_timestamp({_N1, _N2, N3} = Now) -> {Date, Time} = calendar:now_to_datetime(Now), {YYYY,MM,DD} = Date, {Hour,Min,Sec} = Time, FormatDate = io_lib:format("~.4w:~.2.0w:~.2.0w ~.2.0w:~.2.0w:~.2.0w 4~w", [YYYY,MM,DD,Hour,Min,Sec,round(N3/1000)]), lists:flatten(FormatDate).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -