⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 megaco_session_impl.erl

📁 一个Megaco实现源代码
💻 ERL
📖 第 1 页 / 共 3 页
字号:
	    ?d("handle_syntax_error -> no session", []),	    reply;	{a_session, RemotePid, Ref} ->	    ?d("handle_syntax_error -> session found: "	       "~n   RemotePid: ~w"	       "~n   Ref:       ~w", [RemotePid, Ref]),	    MonRef = erlang:monitor(process, SessionPid),	    RH = ?EXT(tr_receive_handle, ReceiveHandle),	    ED = ?EXT(tr_ErrorDescriptor, ErrorDescriptor),	    ?d("handle_syntax_error -> send syntax error", []),	    'Megaco_SessionUser':handleSyntaxError(RemotePid, Ref, self(), RH, PV, ED),	    receive		{'$gen_cast', {'Megaco_Session_handleSyntaxErrorResponse', Ref, Status, RequireAck}} ->		    ?d("handle_syntax_error -> syntax error response: "		       "~n   Status: ~p", [Status]),		    erlang:demonitor(MonRef),		    case ?INT(tr_Status, Status) of			ok ->			    case RequireAck of				true  -> reply;				false -> no_reply			    end;			{error, Desc} when record(Desc, 'ErrorDescriptor') ->			    case RequireAck of				true  -> {reply, Desc};				false -> {no_reply, Desc}			    end;			{error, String} ->			    Desc = #'ErrorDescriptor'{errorCode = ?megaco_internal_gateway_error,						      errorText = String},			    case RequireAck of				true  -> {reply, Desc};				false -> {no_reply, Desc}			    end		    end;		{'DOWN', MonRef, process, SessionPid, _} ->		    reply	    end    end.%%----------------------------------------------------------------------handle_message_error(ConnHandle, PV, ErrorDescriptor, SessionPid) ->    ?d("handle_message_error -> entry with"       "~n   ConnHandle:      ~w"       "~n   PV:              ~w"       "~n   ErrorDescriptor: ~p"       "~n   SessionPid:      ~w", [ConnHandle, PV, ErrorDescriptor, SessionPid]),    case 'Megaco_SessionFactory_impl':select_session(ConnHandle, SessionPid) of	no_session ->	    ?d("handle_message_error -> no session", []),	    no_reply;	{a_session, RemotePid, Ref} ->	    ?d("handle_message_error -> session found: "	       "~n   RemotePid: ~w"	       "~n   Ref:       ~w", [RemotePid, Ref]),	    CH = ?EXT(tr_conn_handle, ConnHandle),	    ED = ?EXT(tr_ErrorDescriptor, ErrorDescriptor),	    ?d("handle_message_error -> send message error", []),	    'Megaco_SessionUser':handleMessageError(RemotePid, Ref, self(), CH, PV, ED),	    no_reply    end.%%----------------------------------------------------------------------handle_trans_request(ConnHandle, PV, ActionRequests, SessionPid) ->    ?d("handle_trans_request -> entry with"       "~n   ConnHandle:     ~p"       "~n   PV:             ~w"       "~n   ActionRequests: ~p"       "~n   SessionPid:     ~p", [ConnHandle, PV, ActionRequests, SessionPid]),    case 'Megaco_SessionFactory_impl':select_session(ConnHandle, SessionPid) of	no_session ->	    ?d("handle_trans_request -> no session", []),	    {discard_ack, #'ErrorDescriptor'{errorCode = ?megaco_not_ready,					     errorText = "Waiting for remote control"}};	{a_session, RemotePid, Ref} ->	    ?d("handle_trans_request -> session found: "	       "~n   RemotePid: ~w"	       "~n   Ref:       ~w", [RemotePid, Ref]),	    MonRef = erlang:monitor(process, SessionPid),	    CH = ?EXT(tr_conn_handle, ConnHandle),	    Requests = [?EXT(tr_ActionRequest, Req) || Req <- ActionRequests],	    ?d("handle_trans_request -> send handleTransRequest", []),	    'Megaco_SessionUser':handleTransRequest(RemotePid, Ref, self(), CH, PV, Requests),	    ?d("handle_trans_request -> await handleTransRequest response", []),	    receive		{'$gen_cast', {'Megaco_Session_handleTransRequestPending', 			       Ref}} ->		    ?d("handle_trans_request -> received pending", []),		    Data = #pending_data{local_pid   = SessionPid,					 remote_pid  = RemotePid,					 request_ref = Ref,					 mon_ref     = MonRef},		    {pending, Data};		{'$gen_cast', {'Megaco_Session_handleTransRequestResponse', 			       Ref, Status, RequireAck, ActionReplies}} ->		    ?d("handle_trans_request -> received trans response:"			"~n   Status:        ~p"			"~n   ActionReplies: ~p", [Status, ActionReplies]),		    erlang:demonitor(MonRef),		    case ?INT(tr_Status, Status) of			ok ->			    ?d("handle_trans_request -> response ok", []),			    AckAction = 				case RequireAck of				    true -> 					{handle_ack, #ack_data{local_pid   = SessionPid,							       remote_pid  = RemotePid,							       request_ref = Ref}};				    false -> discard_ack				end,			    Replies = [?INT(tr_ActionReply, Rep) || Rep <- ActionReplies],			    ?d("handle_trans_request -> internalized:"				"~n   AckAction: ~p"				"~n   Replies:   ~p", [AckAction, Replies]),			    {AckAction, Replies};			{error, Desc} when record(Desc, 'ErrorDescriptor') ->			    ?d("handle_trans_request -> response error: ~p", 				[Desc]),			    {discard_ack, Desc};			{error, String} ->			    ?d("handle_trans_request -> response error: ~s", 				[String]),			    Desc = #'ErrorDescriptor'{errorCode = ?megaco_internal_gateway_error,						      errorText = String},			    {discard_ack, Desc}		    end;		{'DOWN', MonRef, process, SessionPid, _} ->		    ?d("handle_trans_request -> process down:"			"~n   MonRef:     ~p"			"~n   SessionPid: ~p", [MonRef, SessionPid]),		    Desc = #'ErrorDescriptor'{errorCode = ?megaco_not_ready,					      errorText = "Waiting for remote control"},		    {discard_ack, Desc}	    end    end.%%----------------------------------------------------------------------handle_trans_long_request(ConnHandle, PV, Data, SessionPid) ->    #pending_data{local_pid   = LocalPid,		  remote_pid  = RemotePid,		  request_ref = Ref,		  mon_ref     = MonRef} = Data,    receive	{'$gen_cast', {'Megaco_Session_handleTransRequestResponse', Ref, Status, RequireAck, ActionReplies}} ->	    erlang:demonitor(MonRef),	    AckAction = 		case RequireAck of		    true -> {handle_ack, #ack_data{local_pid   = LocalPid,						   remote_pid  = RemotePid,						   request_ref = Ref}};		    false -> discard_ack		end,	    case ?INT(tr_Status, Status) of		ok ->		    Replies = [?EXT(tr_ActionReply, Rep) || Rep <- ActionReplies],		    {AckAction, Replies};		{error, Desc} when record(Desc, 'ErrorDescriptor') ->		    {discard_ack, Desc};		{error, String} ->			Desc = #'ErrorDescriptor'{errorCode = ?megaco_internal_gateway_error,						  errorText = String},			{discard_ack, Desc}	    end;	{'DOWN', MonRef, process, LocalPid, _} ->	    Desc = #'ErrorDescriptor'{errorCode = ?megaco_not_ready,				      errorText = "Waiting for remote control"},	    {discard_ack, Desc}    end.%%----------------------------------------------------------------------handle_trans_reply(ConnHandle, PV, ActualReply, ReplyData, SessionPid) ->    ?d("handle_trans_reply -> entry with"       "~n   ConnHandle:  ~p"       "~n   PV:          ~w"       "~n   ActualReply: ~p"       "~n   ReplyData:   ~p"       "~n   SessionPid:  ~p", [ConnHandle, PV, ActualReply, ReplyData, SessionPid]),    #reply_data{request_ref = Ref, reply_to = ReplyTo} = ReplyData,    CH = ?EXT(tr_conn_handle, ConnHandle),    case ActualReply of	{ok, ActionReplies} ->	    Status = ?EXT(tr_Status, ok),	    Replies = [?EXT(tr_ActionReply, Rep) || Rep <- ActionReplies],	    'Megaco_SessionUser':handleTransReply(ReplyTo, Ref, self(), CH, 						  PV, Status, Replies),	    ok;	{error, Reason} ->	    Status = ?EXT(tr_Status, {error, Reason}),	    Dummy = [],	    'Megaco_SessionUser':handleTransReply(ReplyTo, Ref, self(), CH, 						  PV, Status, Dummy),	    ok    end.%%----------------------------------------------------------------------handle_trans_ack(ConnHandle, PV, AckStatus, Data, SessionPid) ->    ?d("handle_trans_ack -> entry with"       "~n   ConnHandle:  ~p"       "~n   PV:          ~w"       "~n   AckStatus:   ~p"       "~n   Data:        ~p"       "~n   SessionPid:  ~p", [ConnHandle, PV, AckStatus, Data, SessionPid]),    #ack_data{local_pid   = LocalPid,	      remote_pid  = RemotePid,	      request_ref = Ref} = Data,    CH     = ?EXT(tr_conn_handle, ConnHandle),    Status = ?EXT(tr_Status, AckStatus),    'Megaco_SessionUser':handleTransAck(RemotePid, Ref, self(), CH, 					PV, Status),    ok.%%----------------------------------------------------------------------handle_unexpected_trans(ConnHandle, PV, Trans, SessionPid) ->    ?d("handle_unexpected_trans -> entry with"       "~n   ConnHandle: ~p"       "~n   PV:         ~w"       "~n   Trans:      ~p"       "~n   SessionPid: ~p", [ConnHandle, PV, Trans, SessionPid]),    case 'Megaco_SessionFactory_impl':select_session(ConnHandle, SessionPid) of	no_session ->	    ?d("handle_unexpected_trans -> no session", []),	    ok;	{a_session, RemotePid, Ref} ->	    ?d("handle_unexpected_trans -> session found: "	       "~n   RemotePid: ~w"	       "~n   Ref:       ~w", [RemotePid, Ref]),	    CH = ?EXT(tr_conn_handle, ConnHandle),	    Tag = 		if		    record(Trans, 'TransactionPending') ->			transactionPending;		    record(Trans, 'TransactionReply') ->			transactionReply;		    record(Trans, 'TransactionAck') ->			transactionResponseAck		end,	    T = ?EXT(tr_Transaction, {Tag, Trans}),	    'Megaco_SessionUser':handleUnexpectedTrans(RemotePid, Ref, self(), 						       CH, PV, T),	    ok    end.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Internal functions%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%get_debug() ->    app_get_env(session_debug, false).app_get_env(Key, Default) ->    case application:get_env(megaco_session, Key) of	{ok, Value} ->	    Value;	_ ->	    Default    end.get_parent_pid(Env) ->    case get_env(parent_pid, Env) of	Pid when pid(Pid) ->	    Pid;	Else ->	    throw({error, {bad_env, Else, Env}})    end.get_auto_stop_user(Env) ->    case get_env(auto_stop_user, Env) of	AutoStopUser when AutoStopUser == true; AutoStopUser == false ->	    AutoStopUser;	Else ->	    throw({error, {bad_env, Else, Env}})    end.get_env(Key, Env) ->    case lists:keysearch(Key, 1, Env) of	{value, {Key, Value}} ->	    Value;	false ->	    throw({error, {bad_env, Key, Env}})    end.dbg(F, A) ->    dbg(get(debug), F, A).dbg(true, F, A) ->    io:format("MSI-DBG:~w: " ++ F ++ "~n", [self()|A]);dbg(_, _, _) ->    ok.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -