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

📄 megaco_session_impl.erl.tmp

📁 一个Megaco实现源代码
💻 TMP
📖 第 1 页 / 共 2 页
字号:
    O  = [?INT(tr_conn_info_value, V) || V <- Options], %    %% BUGBUG: Look out for explicit reply_data    ReplyData = #reply_data{request_ref = Ref, reply_to = ReplyTo},    ?d("sendTransRequest -> call megaco:cast", []),    case megaco:cast(CH, A, [{reply_data, ReplyData} | O]) of	ok ->	    %% The reply will be delivered later by handle_trans_reply	    ?d("sendTransRequest -> message sent", []),	    {noreply, State};	{error, Reason} ->	    ?d("sendTransRequest -> send failed: ~n~w", [Reason]),	    Status = ?EXT(tr_Status, {error, Reason}),	    PV = megaco:conn_info(CH, protocol_version),	    Dummy = [],	    'Megaco_SessionUser':sendTransReply(ReplyTo, Ref, self(), ConnHandle, PV, Dummy),	    {noreply, State}    end.%% ----------------------------------------------------------------------cancel(State, Ref, ReplyTo, ConnHandle, CancelReason) ->    ?d("sendTransRequest -> entry with"       "~n   Ref:          ~w"       "~n   ReplyTo:      ~w"       "~n   ConnHandle:   ~w"       "~n   CancelReason: ~w", [Ref, ReplyTo, ConnHandle, CancelReason]),    CH = ?INT(tr_conn_handle, ConnHandle),    Res = megaco:cancel(CH, CancelReason),    Status = ?EXT(tr_Status, Res),	        'Megaco_SessionUser':cancelResponse(ReplyTo, Ref, Status),    {noreply, State}.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Response from the (C-) user:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% handleConnectResponse(State, Ref, Result) ->%%     %% Is handled by temporary user callback processes%%     {noreply, State}.%% %% %% ----------------------------------------------------------------------%% %% handleDisconnectResponse(State, Ref, Result) ->%%     %% Is handled by temporary user callback processes%%     {noreply, State}.%% %% %% ----------------------------------------------------------------------%% %% handleSyntaxErrorResponse(State, Ref, Result, SendReply, ActualDesc) ->%%     %% Is handled by temporary user callback processes%%     {noreply, State}.%% %% %% ----------------------------------------------------------------------%% %% handleMessageErrorResponse(State, Ref, Result) ->%%     %% Is handled by temporary user callback processes%%     {noreply, State}.%% %% %% ----------------------------------------------------------------------%% %% handleTransRequestPending(State, Request) ->%%     ?NYI(),%%     %% Is handled by temporary user callback processes%%     {noreply, State}.%% %% %% ----------------------------------------------------------------------%% handleTransRequestResponse(State, Ref, Result, RequireAck, UserReply) ->%%     %% Is handled by temporary user callback processes%%     {noreply, State}.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Megaco protocol stack callback functions:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%handle_connect(ConnHandle, PV, SessionPid) ->    ?d("handle_connect -> entry with"       "~n   ConnHandle: ~w"       "~n   PV:         ~w"       "~n   SessionPid: ~w", [ConnHandle, PV, SessionPid]),    case 'Megaco_SessionFactory_impl':select_session(ConnHandle, SessionPid) of	no_session ->	    ?d("handle_connect -> no session", []),	    {error, #'ErrorDescriptor'{errorCode = ?megaco_not_ready,				       errorText = "Waiting for remote control"}};	{a_session, RemotePid, Ref} ->	    ?d("handle_connect -> session found: "	       "~n   RemotePid: ~w"	       "~n   Ref:       ~w", [RemotePid, Ref]),	    MonRef = erlang:monitor(process, SessionPid),	    CH = ?EXT(tr_conn_handle, ConnHandle),	    ?d("handle_connect -> 'send' handleConnect", []),	    'Megaco_SessionUser':handleConnect(RemotePid, Ref, self(), CH, PV),	    ?d("handle_connect -> await response from C-side", []),	    receive		{'$gen_cast', {'Megaco_Session_handleConnectResponse', Ref, Status}} ->		    ?d("handle_connect -> received connect response:"		       "~n   Status: ~p", [Status]),		    erlang:demonitor(MonRef),		    case ?INT(tr_Status, Status) of			ok ->			    ok;			{error, Desc} when record(Desc, 'ErrorDescriptor') ->			    {error, Desc};			    			{error, String} ->			    Desc = #'ErrorDescriptor'{errorCode = ?megaco_internal_gateway_error,						      errorText = String},			    {error, Desc}		    end;		{'DOWN', MonRef, process, SessionPid, _} ->		    Desc = #'ErrorDescriptor'{errorCode = ?megaco_not_ready,					      errorText = "Waiting for remote control"},		    {error, Desc}	    end    end.%%----------------------------------------------------------------------handle_disconnect(ConnHandle, PV, Reason, SessionPid) ->    ?d("handle_disconnect -> entry with"       "~n   ConnHandle: ~w"       "~n   PV:         ~w"       "~n   Reason:     ~w"       "~n   SessionPid: ~w", [ConnHandle, PV, Reason, SessionPid]),    case 'Megaco_SessionFactory_impl':select_session(ConnHandle, SessionPid) of	no_session ->	    ?d("handle_disconnect -> no session", []),	    ok;	{a_session, RemotePid, Ref} ->	    ?d("handle_disconnect -> session found: "	       "~n   RemotePid: ~w"	       "~n   Ref:       ~w", [RemotePid, Ref]),	    CH = ?EXT(tr_conn_handle, ConnHandle),	    R  = ?EXT(tr_term, Reason),	    'Megaco_SessionUser':handleDisconnect(RemotePid, Ref, self(), CH, PV, R),	    ok    end.%%----------------------------------------------------------------------handle_syntax_error(ReceiveHandle, PV, ErrorDescriptor, SessionPid) ->    ?d("handle_syntax_error -> entry with"       "~n   ReceiveHandle:   ~w"       "~n   PV:              ~w"       "~n   ErrorDescriptor: ~p"       "~n   SessionPid:      ~w", [ReceiveHandle, PV, ErrorDescriptor, SessionPid]),    case 'Megaco_SessionFactory_impl':select_session(ReceiveHandle, SessionPid) of	no_session ->	    ?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~n", [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, _} ->		    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%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-ifdef(debug).dbg(F, A) ->    io:format("MSI-DBG:~w: " ++ F ++ "~n", [self()|A]).-endif.

⌨️ 快捷键说明

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