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

📄 orber_pi.erl

📁 OTP是开放电信平台的简称
💻 ERL
📖 第 1 页 / 共 3 页
字号:
%%--------------------------------------------------------------------%% ``The contents of this file are subject to the Erlang Public License,%% Version 1.1, (the "License"); you may not use this file except in%% compliance with the License. You should have received a copy of the%% Erlang Public License along with this software. If not, it can be%% retrieved via the world wide web at http://www.erlang.org/.%% %% Software distributed under the License is distributed on an "AS IS"%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See%% the License for the specific language governing rights and limitations%% under the License.%% %% The Initial Developer of the Original Code is Ericsson Utvecklings AB.%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings%% AB. All Rights Reserved.''%% %%     $Id$%%%%----------------------------------------------------------------------%% File    : orber_pi.erl%% Purpose : %% Created : 20 Sep 2000%% Comments:%% * Each Interceptor is represented by Module where%%              Module - refers to a module which must export the functions:%%                       (1)  receive_request%%                       (2)  send_other%%                       (3)  receive_service_contexts%%                       (4)  send_reply%%                       (5)  send_exception%%                       (6)  send_request%%                       (7)  send_poll%%                       (8)  receive_reply%%                       (9)  receive_exception%%                       (10) receive_other %%                       or%%                       (11) new_out_connection%%                       (12) new_in_connection%%                       (13) in_request%%                       (14) out_reply%%                       (15) out_request%%                       (16) in_reply%%%%              Functions (1) - (10) for Portable and (11) - (16) for %%              Native Interceptors.%% %%-----------------------------------------------------------------------module(orber_pi).%%--------------- INCLUDES ------------------------------------include_lib("orber/include/corba.hrl").-include_lib("orber/include/ifr_types.hrl").-include_lib("orber/include/orber_pi.hrl").-include_lib("orber/src/orber_iiop.hrl").%%--------------- EXPORTS-------------------------------------%% API external-export([%% Native Intercepotors API	 new_out_connection/5,	 new_in_connection/5,	 closed_in_connection/2,	 closed_out_connection/2,	 in_request_enc/4,	 out_reply_enc/5,	 out_request_enc/6,	 in_reply_enc/6,	 in_request/4,	 out_reply/5,	 out_request/6,	 in_reply/6,	 %% Portable Interceptors	 server_start_receive/7, 	 server_start_send/2,	 client_receive/2, 	 client_send/2, 	 codefactory_create_codec/1,	 codec_encode/2, 	 codec_encode_value/2,	 codec_decode/2, 	 codec_decode_value/3,	 %% RequestInfo	 '_get_request_id'/1,	 '_get_operation'/1,	 '_get_arguments'/1,	 '_get_exceptions'/1,	 '_get_contexts'/1,	 '_get_operation_context'/1,	 '_get_result'/1,	 '_get_response_expected'/1,	 '_get_sync_scope'/1,	 '_get_reply_status'/1,	 '_get_forward_reference'/1,	 get_slot/2,	 get_request_service_context/2,	 get_reply_service_context/2,	 %% ClientRequestInfo (inherrits RequestInfo)	 '_get_target'/1,	 '_get_effective_target'/1,	 '_get_effective_profile'/1,	 '_get_received_exception'/1,	 '_get_received_exception_id'/1,	 get_effective_component/2,	 get_effective_components/2,	 get_request_policy/2,	 add_request_service_policy/3,	 %% ServerRequestInfo (inherrits RequestInfo)	 '_get_sending_exception'/1,	 '_get_object_id'/1,	 '_get_adapter_id'/1,	 '_get_target_most_derived_interface'/1,	 get_server_policy/2,	 set_slot/3,	 target_is_a/2,	 add_reply_service_context/3]).%%=============== DATA STRUCTURES ============================%%--------------- ClientRequestInfo ---------------------------record('ClientRequestInfo', 	{request_id,	 operation,	 arguments,	 exceptions,	 contexts,	 operation_context,	 result,	 response_expected,	 sync_scope = 'SYNC_NONE',	 reply_status,	 forward_reference,	 endian,	 target,	 effective_target,	 effective_profile,	 received_exception,	 received_exception_id}).-define(createInitCRI(_ReqID, _Op, _Args, _Ctxs, _OpCtx, _RespExp, _Target, 		      _ETarget, _EProf),	#'ClientRequestInfo'{request_id        = _ReqID,			     operation         = _Op,			     arguments         = _Args,			     contexts          = _Ctxs,			     operation_context = _OpCtx,			     response_expected = _RespExp,			     target            = _Target,			     effective_target  = _ETarget,			     effective_profile = _EProf}).%%--------------- ServerRequestInfo ---------------------------record('ServerRequestInfo',	{request_id,	 operation,	 arguments,	 exceptions,	 contexts,	 operation_context,	 result,	 response_expected,	 sync_scope = 'SYNC_NONE',	 reply_status,	 forward_reference,	 endian,	 sending_exception,	 object_id,	 adapter_id,	 target_most_derived_interface}).-define(createInitSRI(_ReqID, _Op, _RespExp),	#'ServerRequestInfo'{request_id        = _ReqID,			     operation         = _Op,			     response_expected = _RespExp}).%%--------------- DEFINES -------------------------------------define(DEBUG_LEVEL, 9).-define(EFORMAT(_F, _A), exit(lists:flatten(io_lib:format(_F, _A)))).%%------------------------------------------------------------%%------------- NATIVE INTERCEPTOR FUNCTIONS------------------%%------------------------------------------------------------%% function : new_in_connection%% Arguments: %% Returns  : %% Exception: %% Effect   : %%------------------------------------------------------------new_in_connection(PIs, Host, Port, SHost, SPort) ->    case catch new_in_connection(PIs, undefined, Host, Port, SHost, SPort) of	{'EXIT', R} ->	    orber:dbg("[~p] orber_pi:new_in_connection(~p); exit(~p)", 		      [?LINE, PIs, R], ?DEBUG_LEVEL),	    ?EFORMAT("Supplied Interceptors unable to create a valid new_in_connection"		     "Reason: ~p", [{'EXIT', R}]);	{'EXCEPTION', E} ->	    orber:dbg("[~p] orber_pi:new_in_connection(~p); exception(~p)", 		      [?LINE, PIs, E], ?DEBUG_LEVEL),	    ?EFORMAT("Supplied Interceptors unable to create a valid new_in_connection"		     "Reason: ~p", [{'EXCEPTION', E}]);	Ref ->	    Ref    end.new_in_connection([], Ref, _, _, _, _) ->    Ref;new_in_connection([Mod|T], Ref, Host, Port, SHost, SPort) ->    case get_arity(Mod, new_in_connection) of	5 ->	    NewRef = Mod:new_in_connection(Ref, Host, Port, SHost, SPort),	    new_in_connection(T, NewRef, Host, Port, SHost, SPort);	3 ->	    NewRef = Mod:new_in_connection(Ref, Host, Port),	    new_in_connection(T, NewRef, Host, Port, SHost, SPort)    end.get_arity(Mod, Func) ->    get_arity(Mod, Func, true).get_arity(Mod, Func, Retry) ->    case erlang:function_exported(Mod, Func, 5) of	true ->	    5;	false ->	    case erlang:function_exported(Mod, Func, 3) of		true ->		    3;		false when Retry == true ->		    {module, _} = code:ensure_loaded(Mod),		    get_arity(Mod, Func, false);		false ->		    exit("Unable to load interceptor")	    end    end.%%------------------------------------------------------------%% function : closed_in_connection%% Arguments: %% Returns  : %% Exception: %% Effect   : %%------------------------------------------------------------closed_in_connection(PIs, Ref) ->    case catch closed_in_connection_helper(PIs, Ref) of	{'EXIT', R} ->	    orber:dbg("[~p] orber_pi:closed_in_connection(~p, ~p); exit(~p)", 		      [?LINE, PIs, Ref, R], ?DEBUG_LEVEL),	    ok;	{'EXCEPTION', E} ->	    orber:dbg("[~p] orber_pi:closed_in_connection(~p, ~p); exception(~p)", 		      [?LINE, PIs, Ref, E], ?DEBUG_LEVEL),	    ok;	_ ->	    ok    end.closed_in_connection_helper([], _Ref) ->    ok;closed_in_connection_helper([Mod|T], Ref) ->    NewRef = Mod:closed_in_connection(Ref),    closed_in_connection_helper(T, NewRef).%%------------------------------------------------------------%% function : new_out_connection%% Arguments: %% Returns  : %% Exception: %% Effect   : %%------------------------------------------------------------new_out_connection(PIs, Host, Port, SHost, SPort) ->    case catch new_out_connection(PIs, undefined, Host, Port, SHost, SPort) of	{'EXIT', R} ->	    orber:dbg("[~p] orber_pi:new_out_connection(~p); exit(~p)", 		      [?LINE, PIs, R], ?DEBUG_LEVEL),	    ?EFORMAT("Supplied Interceptors unable to create a valid new_out_connection"		     "Reason: ~p", [{'EXIT', R}]);	{'EXCEPTION', E} ->	    orber:dbg("[~p] orber_pi:new_out_connection(~p); exception(~p)", 		      [?LINE, PIs, E], ?DEBUG_LEVEL),	    ?EFORMAT("Supplied Interceptors unable to create a valid new_out_connection"		     "Reason: ~p", [{'EXCEPTION', E}]);	Ref ->	    Ref    end.new_out_connection([], Ref, _, _, _, _) ->    Ref;new_out_connection([Mod|T], Ref, Host, Port, SHost, SPort) ->    case get_arity(Mod, new_out_connection) of	5 ->	    NewRef = Mod:new_out_connection(Ref, Host, Port, SHost, SPort),	    new_out_connection(T, NewRef, Host, Port, SHost, SPort);	3 ->	    NewRef = Mod:new_out_connection(Ref, Host, Port),	    new_out_connection(T, NewRef, Host, Port, SHost, SPort)    end.%%------------------------------------------------------------%% function : closed_out_connection%% Arguments: %% Returns  : %% Exception: %% Effect   : %%------------------------------------------------------------closed_out_connection(PIs, Ref) ->    case catch closed_out_connection_helper(PIs, Ref) of	{'EXIT', R} ->	    orber:dbg("[~p] orber_pi:closed_out_connection(~p); exit(~p)", 		      [?LINE, PIs, R], ?DEBUG_LEVEL),	    ok;	{'EXCEPTION', E} ->	    orber:dbg("[~p] orber_pi:closed_out_connection(~p); exception(~p)", 		      [?LINE, PIs, E], ?DEBUG_LEVEL),	    ok;	_ ->	    ok    end.closed_out_connection_helper([], _Ref) ->    ok;closed_out_connection_helper([Mod|T], Ref) ->    NewRef = Mod:closed_out_connection(Ref),    closed_out_connection_helper(T, NewRef).%%------------------------------------------------------------%% function : in_request_enc%% Arguments: %% Returns  : %% Exception: %% Effect   : Intercepts an incoming request (server-side).%%------------------------------------------------------------in_request_enc(PIs, ReqHdr, Ref, Msg) ->    case catch in_request_enc(PIs, ReqHdr, Ref, Msg, undefined) of	{'EXIT', R} ->	    orber:dbg("[~p] orber_pi:in_request_enc(~p, ~p, ~p); exit(~p)", 		      [?LINE, PIs, Ref, Msg, R], ?DEBUG_LEVEL),	    corba:raise(#'MARSHAL'{completion_status=?COMPLETED_NO});	{'EXCEPTION', E} ->	    orber:dbg("[~p] orber_pi:in_request_enc(~p, ~p, ~p); exception(~p)", 		      [?LINE, PIs, Ref, Msg, E], ?DEBUG_LEVEL),	    corba:raise(E);	NewMsg ->	    NewMsg    end.in_request_enc([], _, _, Msg, _) ->    Msg;in_request_enc([Mod|T], ReqHdr, Ref, Msg, Args) ->    {NewMsg, NewArgs} = Mod:in_request_encoded(Ref, ReqHdr#request_header.object_key,					       ReqHdr#request_header.service_context,					       ReqHdr#request_header.operation, 					       Msg, Args),    in_request_enc(T, ReqHdr, Ref, NewMsg, NewArgs).%%------------------------------------------------------------%% function : in_request%% Arguments: %% Returns  : %% Exception: %% Effect   : Intercepts an incoming request (server-side).%%------------------------------------------------------------in_request(PIs, ReqHdr, Ref, Msg) ->    case catch in_request(PIs, ReqHdr, Ref, Msg, undefined) of	{'EXIT', R} ->	    orber:dbg("[~p] orber_pi:in_request(~p, ~p, ~p); exit(~p)", 		      [?LINE, PIs, Ref, Msg, R], ?DEBUG_LEVEL),	    corba:raise(#'MARSHAL'{completion_status=?COMPLETED_NO});	{'EXCEPTION', E} ->	    orber:dbg("[~p] orber_pi:in_request(~p, ~p, ~p); exception(~p)", 		      [?LINE, PIs, Ref, Msg, E], ?DEBUG_LEVEL),	    corba:raise(E);	NewMsg ->	    NewMsg    end.in_request([], _, _, Msg, _) ->    Msg;in_request([Mod|T], ReqHdr, Ref, Msg, Args) ->    {NewMsg, NewArgs} = Mod:in_request(Ref, ReqHdr#request_header.object_key,				       ReqHdr#request_header.service_context,				       ReqHdr#request_header.operation, 				       Msg, Args),    in_request(T, ReqHdr, Ref, NewMsg, NewArgs).%%------------------------------------------------------------%% function : out_reply_enc%% Arguments: %% Returns  : %% Exception: %% Effect   : Intercept an outgoing reply (server-side).%%------------------------------------------------------------out_reply_enc(PIs, ReqHdr, Ref, Msg, Ctx) ->    case catch out_reply_enc(PIs, ReqHdr, Ref, Msg, undefined, Ctx) of	{'EXIT', R} ->	    orber:dbg("[~p] orber_pi:out_reply_enc(~p, ~p, ~p); exit(~p)", 		      [?LINE, PIs, Ref, Msg, R], ?DEBUG_LEVEL),	    corba:raise(#'MARSHAL'{completion_status=?COMPLETED_MAYBE});	{'EXCEPTION', E} ->	    orber:dbg("[~p] orber_pi:out_reply_enc(~p, ~p, ~p); exception(~p)", 		      [?LINE, PIs, Ref, Msg, E], ?DEBUG_LEVEL),	    corba:raise(E);	NewMsg ->	    NewMsg

⌨️ 快捷键说明

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