cosnotifychanneladmin_supplieradmin_impl.erl

来自「OTP是开放电信平台的简称」· ERL 代码 · 共 579 行 · 第 1/2 页

ERL
579
字号
%%--------------------------------------------------------------------%% ``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    : CosNotifyChannelAdmin_SupplierAdmin_impl.erl%% Purpose : %% Created : 28 Sep 1999%%--------------------------------------------------------------------module('CosNotifyChannelAdmin_SupplierAdmin_impl').%%--------------- INCLUDES ------------------------------------include_lib("orber/include/corba.hrl").-include_lib("orber/include/ifr_types.hrl").%% Application files-include("CosNotification.hrl").-include("CosNotifyChannelAdmin.hrl").-include("CosNotifyComm.hrl").-include("CosNotifyFilter.hrl").-include("CosNotification_Definitions.hrl").%%--------------- EXPORTS ------------------------------------%%--------------- External -----------------------------------%%----- CosNotifyChannelAdmin::SupplierAdmin ------------------export([get_proxy_consumer/4,	 obtain_notification_pull_consumer/4, 	 obtain_notification_push_consumer/4,	 destroy/3]).%%----- Inherit from CosNotification::QoSAdmin ----------------export([get_qos/3,	 set_qos/4,	 validate_qos/4]).%%----- Inherit from CosNotifyComm::NotifyPublish -------------export([offer_change/5]).%%----- Inherit from CosNotifyFilter::FilterAdmin -------------export([add_filter/4, 	 remove_filter/4, 	 get_filter/4,	 get_all_filters/3, 	 remove_all_filters/3]).%%----- Inherit from CosEventChannelAdmin::SupplierAdmin ------export([obtain_push_consumer/3, 	 obtain_pull_consumer/3]).%% Attributes (external)-export(['_get_MyID'/3, 	 '_get_MyChannel'/3, 	 '_get_MyOperator'/3,	 '_get_pull_consumers'/3, 	 '_get_push_consumers'/3]).%%--------------- Internal -----------------------------------%%----- Inherit from cosNotificationComm ----------------------export([callAny/5,	 callSeq/5]).%%--------------- gen_server specific exports -----------------export([handle_info/2, code_change/3]).-export([init/1, terminate/2]).%%--------------- LOCAL DEFINITIONS --------------------------%% Data structures-record(state, {myId,	        myChannel,		myChannelPid,		myOperator,		myFilters = [],		idCounter = 0,		etsR,		qosGlobal,		qosLocal,		options}).%% Data structures constructors-define(get_InitState(_MyID, _MyCh, _MyChP, _MyOp, _QoS, _LQS, _O), 	#state{myId           = _MyID,	       myChannel      = _MyCh,	       myChannelPid   = _MyChP,	       myOperator     = _MyOp,	       qosGlobal      = _QoS,	       qosLocal       = _LQS,	       options        = _O,	       etsR = ets:new(oe_ets, [set, protected])}).%% Data structures selectors-define(get_PushConsumers(S),     lists:flatten(ets:match(S#state.etsR, 							  {'_','$1','_',pusher}))).-define(get_PullConsumers(S),     lists:flatten(ets:match(S#state.etsR, 							  {'_','$1','_',puller}))).-define(get_AllConsumers(S),      lists:flatten(ets:match(S#state.etsR, 							  {'_','$1','_','_'}))).-define(get_PushConsumerIDs(S),   lists:flatten(ets:match(S#state.etsR, 							  {'$1','_','_',pusher}))).-define(get_PullConsumerIDs(S),   lists:flatten(ets:match(S#state.etsR, 							  {'$1','_','_',puller}))).-define(get_Consumer(S, I),       find_obj(ets:lookup(S#state.etsR, I), consumer)).-define(get_MyID(S),              S#state.myId).-define(get_MyChannel(S),         S#state.myChannel).-define(get_MyChannelPid(S),      S#state.myChannelPid).-define(get_MyOperator(S),        S#state.myOperator).-define(get_GlobalQoS(S),         S#state.qosGlobal).-define(get_LocalQoS(S),          S#state.qosLocal).-define(get_BothQoS(S),           {S#state.qosGlobal, S#state.qosLocal}).-define(get_Filter(S, I),         find_obj(lists:keysearch(I, 1, S#state.myFilters), 					   filter)).-define(get_AllFilter(S),         S#state.myFilters).-define(get_AllFilterID(S),       find_ids(S#state.myFilters)).-define(get_Options(S),           S#state.options).-define(get_IdCounter(S),         S#state.idCounter).%% Data structures modifiers-define(set_LocalQoS(S,D),        S#state{qosLocal=D}).-define(set_GlobalQoS(S,D),       S#state{qosGlobal=D}).-define(set_BothQoS(S,GD,LD),     S#state{qosGlobal=GD, qosLocal=LD}).-define(add_PushConsumer(S,I,R,P),ets:insert(State#state.etsR, {I,R,P,pusher})).-define(add_PullConsumer(S,I,R,P),ets:insert(State#state.etsR, {I,R,P,puller})).-define(del_Consumer(S,I),        ets:delete(S#state.etsR, I)).-define(del_ConsumerPid(S,P),     ets:match_delete(S#state.etsR, {'_','_',P,'_'})).-define(add_Filter(S,I,O),        S#state{myFilters=[{I,O}|S#state.myFilters]}).-define(del_Filter(S,I),          S#state{myFilters=					  delete_filter(lists:keydelete(I, 1, 									S#state.myFilters),							S#state.myFilters)}).-define(del_AllFilter(S),         S#state{myFilters=[]}).-define(set_IdCounter(S,V),       S#state{idCounter=V}).-define(new_Id(S),                'CosNotification_Common':create_id(S#state.idCounter)).%% MISC-define(is_PersistentEvent(S),	?not_GetEventReliability((S#state.qosLocal)) == ?not_Persistent).-define(is_PersistentConnection(S),	?not_GetConnectionReliability((S#state.qosLocal)) == ?not_Persistent).%%----------------------------------------------------------%%% function : handle_info, code_change%% Arguments: %% Returns  : %% Effect   : Functions demanded by the gen_server module. %%-----------------------------------------------------------code_change(_OldVsn, State, _Extra) ->    {ok, State}.handle_info(Info, State) ->    case Info of        {'EXIT', Pid, Reason} when ?get_MyChannelPid(State) == Pid ->            ?DBG("PARENT CHANNEL: ~p  TERMINATED.~n",[Reason]),	    {stop, Reason, State};        {'EXIT', Pid, normal} ->	    ?del_ConsumerPid(State, Pid),            {noreply, State};        _Other ->            {noreply, State}    end.%%----------------------------------------------------------%%% function : init, terminate%% Arguments: %%-----------------------------------------------------------init([MyId, MyChannel, MyChannelPid, MyOperator, InitQoS, LQS, Options]) ->    process_flag(trap_exit, true),    {ok, ?get_InitState(MyId, MyChannel, MyChannelPid, MyOperator, InitQoS, LQS, Options)}.terminate(_Reason, _State) ->    ok.%%-----------------------------------------------------------%%----- CosNotifyChannelAdmin_ConsumerAdmin attributes ------%%-----------------------------------------------------------%%----------------------------------------------------------%%% Attribute: '_get_MyID'%% Type     : readonly%% Returns  : %%-----------------------------------------------------------'_get_MyID'(_OE_THIS, _OE_FROM, State) ->    {reply, ?get_MyID(State), State}.%%----------------------------------------------------------%%% Attribute: '_get_MyChannel'%% Type     : readonly%% Returns  : %%-----------------------------------------------------------'_get_MyChannel'(_OE_THIS, _OE_FROM, State) ->    {reply, ?get_MyChannel(State), State}.%%----------------------------------------------------------%%% Attribute: '_get_MyOperator'%% Type     : readonly%% Returns  : %%-----------------------------------------------------------'_get_MyOperator'(_OE_THIS, _OE_FROM, State) ->    {reply, ?get_MyOperator(State), State}.%%----------------------------------------------------------%%% Attribute: '_get_pull_consumers'%% Type     : readonly%% Returns  : ProxyIDSeq%%-----------------------------------------------------------'_get_pull_consumers'(_OE_THIS, _OE_FROM, State) ->    {reply, ?get_PullConsumerIDs(State), State}.%%----------------------------------------------------------%%% Attribute: '_get_push_consumers'%% Type     : readonly%% Returns  : ProxyIDSeq%%-----------------------------------------------------------'_get_push_consumers'(_OE_THIS, _OE_FROM, State) ->    {reply, ?get_PushConsumerIDs(State), State}.%%-----------------------------------------------------------%%------- Exported external functions -----------------------%%-----------------------------------------------------------%%----------------------------------------------------------%%% function : get_proxy_consumer%% Arguments: ProxyId - unique identifier (long)%% Returns  : ObjRef | {'EXCEPTION', #'ProxyNotFound'{}}%%-----------------------------------------------------------get_proxy_consumer(_OE_THIS, _OE_FROM, State, ProxyId) ->    {reply, ?get_Consumer(State, ProxyId), State}.    %%----------------------------------------------------------%%% function : obtain_notification_pull_consumer%% Arguments: %% Returns  : %%-----------------------------------------------------------obtain_notification_pull_consumer(OE_THIS, _OE_FROM, State, Ctype) ->    %% Choose which module to use.    {Mod, Type} = 	case Ctype of	    'ANY_EVENT' ->		{'CosNotifyChannelAdmin_ProxyPullConsumer', 'PULL_ANY'};	    'STRUCTURED_EVENT' ->		{'CosNotifyChannelAdmin_StructuredProxyPullConsumer', 'PULL_STRUCTURED'};	    'SEQUENCE_EVENT' ->		{'CosNotifyChannelAdmin_SequenceProxyPullConsumer', 'PULL_SEQUENCE'};	    _ ->		orber:dbg("[~p] CosNotifyChannelAdmin_SupplierAdmin:"			  "obtain_notification_pull_consumer(~p);~n"			  "Incorrect enumerant", 			  [?LINE, Ctype], ?DEBUG_LEVEL),		corba:raise(#'BAD_PARAM'{completion_status=?COMPLETED_NO})	end,    SO = 'CosNotification_Common':get_option(server_options, ?get_Options(State), 					     ?not_DEFAULT_SETTINGS),    case catch Mod:oe_create_link([Type, OE_THIS, self(), ?get_GlobalQoS(State), 				   ?get_LocalQoS(State), ?get_MyChannel(State),				   ?get_Options(State), ?get_MyOperator(State)], 				  [{sup_child, true}|SO]) of	{ok, Pid, Proxy} ->	    ProxyID = ?new_Id(State),	    ?add_PullConsumer(State, ProxyID, Proxy, Pid),	    {reply, {Proxy, ProxyID}, ?set_IdCounter(State, ProxyID)};	What ->	    orber:dbg("[~p] CosNotifyChannelAdmin_SupplierAdmin:"		      "obtain_notification_pull_consumer();~n"		      "Unable to create: ~p/~p~n"		      "Reason: ~p", [?LINE, Mod, Type, What], ?DEBUG_LEVEL),	    corba:raise(#'INTERNAL'{completion_status=?COMPLETED_NO})    end.%%----------------------------------------------------------%%% function : obtain_notification_push_supplier%% Arguments: %% Returns  : %%-----------------------------------------------------------obtain_notification_push_consumer(OE_THIS, _OE_FROM, State, Ctype) ->    %% Choose which module to use.    {Mod, Type} = 

⌨️ 快捷键说明

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