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

📄 megaco_session_impl.erl

📁 一个Megaco实现源代码
💻 ERL
📖 第 1 页 / 共 3 页
字号:
    {I, V} = ?INT(tr_user_item_value, ItemValue),    Res = megaco:update_user_info(M, I, V),    Status = ?EXT(tr_Status, Res),	        'Megaco_SessionUser':updateUserInfoResponse(ReplyTo, Ref, Status),    {noreply, State}.%% ----------------------------------------------------------------------connInfo(State, Ref, ReplyTo, ConnHandle, Item) ->    ?d("connInfo -> entry with"       "~n   Ref:        ~w"       "~n   ReplyTo:    ~w"       "~n   ConnHandle: ~w"       "~n   Item:       ~w", [Ref, ReplyTo, ConnHandle, Item]),    case catch conn_info_wrapper(ConnHandle, Item) of	{'EXIT', Reason} ->	    Status = ?EXT(tr_Status, {'EXIT', Reason}),	    	    Dummy = #'Megaco_ConnInfoValue'{label = 'ConnInfo_replyData', 					    value = []},	    'Megaco_SessionUser':connInfoResponse(ReplyTo, Ref, Status, Dummy),	    {noreply, State};	Value ->	    ?d("connInfo -> Value: ~w", [Value]),	    Status = ?EXT(tr_Status, ok),	    V = #'Megaco_ConnInfoValue'{label = Item, value = Value},	    'Megaco_SessionUser':connInfoResponse(ReplyTo, Ref, Status, V),	    {noreply, State}    end.conn_info_wrapper(ConnHandle, Item) ->    CH = ?INT(tr_conn_handle, ConnHandle),    %% Will exit at error    case Item of        'ConnInfo_controlPid' ->	    megaco:conn_info(CH, control_pid);        'ConnInfo_sendHandle' ->	    ?EXT(tr_send_handle, megaco:conn_info(CH, send_handle));        'ConnInfo_receiveHandle' ->	    ?EXT(tr_receive_handle, megaco:conn_info(CH, receive_handle));        'ConnInfo_transId' ->	    case megaco:conn_info(CH, trans_id) of		TransId when integer(TransId) ->		    TransId;		_ -> 		    -1	    end;        'ConnInfo_maxTransId' ->	    megaco:conn_info(CH, max_trans_id);         'ConnInfo_requestTimer' ->	    ?EXT(tr_timer, megaco:conn_info(CH, request_timer));         'ConnInfo_longRequestTimer' ->	    ?EXT(tr_timer, megaco:conn_info(CH, long_request_timer));         'ConnInfo_autoAck' ->	    megaco:conn_info(CH, auto_ack);         'ConnInfo_replyTimer' ->	    ?EXT(tr_timer, megaco:conn_info(CH, reply_timer));         'ConnInfo_pendingTimer' ->	    ?EXT(tr_timer, megaco:conn_info(CH, pending_timer));         'ConnInfo_sendMod' ->	    ?EXT(tr_atom, megaco:conn_info(CH, send_mod));         'ConnInfo_encodingMod' ->	    ?EXT(tr_atom, megaco:conn_info(CH, encoding_mod));         'ConnInfo_encodingConfig' ->	    ?EXT(tr_term, megaco:conn_info(CH, encoding_config));         'ConnInfo_protocolVersion' ->	    megaco:conn_info(CH, protocol_version);         'ConnInfo_replyData' ->	    ?EXT(tr_term, megaco:conn_info(CH, reply_data))    end.%% ----------------------------------------------------------------------updateConnInfo(State, Ref, ReplyTo, ConnHandle, ItemValue) ->    ?d("updateConnInfo -> entry with"       "~n   Ref:        ~w"       "~n   ReplyTo:    ~w"       "~n   ConnHandle: ~w"       "~n   ItemValue:  ~w", [Ref, ReplyTo, ConnHandle, ItemValue]),    CH = ?INT(tr_conn_handle, ConnHandle),    {I, V} = ?INT(tr_conn_info_value, ItemValue),    Res = megaco:update_conn_info(CH, I, V),    Status = ?EXT(tr_Status, Res),	        'Megaco_SessionUser':updateConnInfoResponse(ReplyTo, Ref, Status),    {noreply, State}.%% ----------------------------------------------------------------------connect(State, Ref, ReplyTo, ReceiveHandle, RemoteMid, SendHandle, ControlPid) ->    ?d("connect -> entry with"       "~n   Ref:           ~w"       "~n   ReplyTo:       ~w"       "~n   ReceiveHandle: ~w"       "~n   RemoteMid:     ~w"       "~n   SendHandle:    ~w"       "~n   ControlPid:    ~w", 	[Ref, ReplyTo, ReceiveHandle, RemoteMid, SendHandle, ControlPid]),    RH = ?INT(tr_receive_handle, ReceiveHandle),    RM = ?INT(tr_MId, RemoteMid),    SH = ?INT(tr_send_handle, SendHandle),    ?d("connect -> call megaco:connect with"	"~n   RH: ~w"	"~n   RM: ~w"	"~n   SH: ~w", [RH, RM, SH]),    %% Res = megaco:connect(RH, RM, SH, ControlPid),    {Status0, CH0} = 	case megaco:connect(RH, RM, SH, ControlPid) of	    {ok, ConnHandle} ->		?d("connect -> connected: ~p", [ConnHandle]),		{ok, ConnHandle};	    Error ->		?d("connect -> connection faild: ~p", [Error]),		%% BUGBUG		%% Don't really know what to reply with here,		%% so i send a dummy megaco conn handle for now!!		%% BUGBUG		{Error, #megaco_conn_handle{}}    end,    Status = ?EXT(tr_Status, Status0),    CH     = ?EXT(tr_conn_handle, CH0),    ?d("connect -> send connectResponse", []),    'Megaco_SessionUser':connectResponse(ReplyTo, Ref, Status, CH),    {noreply, State}.%% ----------------------------------------------------------------------disconnect(State, Ref, ReplyTo, ConnHandle, DiscoReason) ->    ?d("disconnect -> entry with"       "~n   Ref:         ~w"       "~n   ReplyTo:     ~w"       "~n   ConnHandle:  ~w"       "~n   DiscoReason: ~p", [Ref, ReplyTo, ConnHandle, DiscoReason]),    CH     = ?INT(tr_conn_handle, ConnHandle),    Res    = megaco:disconnect(CH, DiscoReason),    Status = ?EXT(tr_Status, Res),	        'Megaco_SessionUser':disconnectResponse(ReplyTo, Ref, Status),    {noreply, State}.%% ----------------------------------------------------------------------sendTransRequest(State, Ref, ReplyTo, ConnHandle, ActionRequests, Options) ->    ?d("sendTransRequest -> entry with"       "~n   Ref:            ~w"       "~n   ReplyTo:        ~w"       "~n   ConnHandle:     ~w"       "~n   ActionRequests: ~w"       "~n   Options:        ~w", 	[Ref, ReplyTo, ConnHandle, ActionRequests, Options]),    CH = ?INT(tr_conn_handle, ConnHandle),    A  = [?INT(tr_ActionRequest, Req) || Req <- ActionRequests],    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 with"	"~n   CH: ~p"	"~n   A:  ~p", [CH, A]),    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':handleTransReply(ReplyTo, Ref, self(), 						  ConnHandle, PV, Status, 						  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),	    ?d("handle_disconnect -> done", []),	    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 ->

⌨️ 快捷键说明

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