coseventdomainadmin_eventdomain_impl.erl

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

ERL
1,415
字号
%%--------------------------------------------------------------------%% ``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        : CosEventDomainAdmin_EventDomain_impl.erl%% Description : %%%% Created     : 14 Aug 2001%%-----------------------------------------------------------------------module('CosEventDomainAdmin_EventDomain_impl').%%----------------------------------------------------------------------%% Include files%%-----------------------------------------------------------------------include_lib("orber/include/corba.hrl").-include_lib("orber/include/ifr_types.hrl").-include_lib("cosNotification/include/CosNotifyChannelAdmin.hrl").-include_lib("cosNotification/include/CosNotification.hrl").-include("cosEventDomainApp.hrl").-include("CosEventDomainAdmin.hrl").%%----------------------------------------------------------------------%% External exports%%-----------------------------------------------------------------------export([init/1,	 terminate/2,	 code_change/3,	 handle_info/2]).%%------------------ CosEventDomainAdmin::EventDomain -------------------export([add_channel/3, 	 get_all_channels/2, 	 get_channel/3,	 remove_channel/3,	 add_connection/3,	 get_all_connections/2,	 get_connection/3,	 remove_connection/3,	 get_offer_channels/3,	 get_subscription_channels/3,	 destroy/2,	 get_cycles/2,	 get_diamonds/2,	 set_default_consumer_channel/3,	 set_default_supplier_channel/3,	 connect_push_consumer/3,	 connect_pull_consumer/3,	 connect_push_supplier/3,	 connect_pull_supplier/3,	 connect_structured_push_consumer/3,	 connect_structured_pull_consumer/3,	 connect_structured_push_supplier/3,	 connect_structured_pull_supplier/3,	 connect_sequence_push_consumer/3,	 connect_sequence_pull_consumer/3,	 connect_sequence_push_supplier/3,	 connect_sequence_pull_supplier/3,	 connect_push_consumer_with_id/4,	 connect_pull_consumer_with_id/4,	 connect_push_supplier_with_id/4,	 connect_pull_supplier_with_id/4,	 connect_structured_push_consumer_with_id/4,	 connect_structured_pull_consumer_with_id/4,	 connect_structured_push_supplier_with_id/4,	 connect_structured_pull_supplier_with_id/4,	 connect_sequence_push_consumer_with_id/4,	 connect_sequence_pull_consumer_with_id/4,	 connect_sequence_push_supplier_with_id/4,	 connect_sequence_pull_supplier_with_id/4]).%%------------------ CosNotification::QoSAdmin --------------------------export([get_qos/2, 	 set_qos/3, 	 validate_qos/3]).%%------------------ CosNotification::AdminPropertiesAdmin --------------export([get_admin/2, 	 set_admin/3]).%%----------------------------------------------------------------------%% Internal exports%%-----------------------------------------------------------------------export([]).%%----------------------------------------------------------------------%% Records%%-----------------------------------------------------------------------record(state, {parent_pid, id, graph, ch_counter=-1, 		co_counter=-1, def_supplier, def_consumer, diamonds, cyclic}).-record(connection, {supplier, consumer, data}).%%----------------------------------------------------------------------%% Macros%%----------------------------------------------------------------------%%======================================================================%% External functions%%======================================================================%%----------------------------------------------------------------------%% Function   : init/1%% Returns    : {ok, State}          |%%              {ok, State, Timeout} |%%              ignore               |%%              {stop, Reason}%% Description: Initiates the server%%----------------------------------------------------------------------init([ParentPid, MyId, QoS, _Admin]) ->    process_flag(trap_exit, true),    Diamonds = case lists:keysearch(?DiamondDetection, 1, QoS) of		   false ->		       ?ForbidDiamonds;		   {value, {_, Value}} ->		       Value	       end,    case lists:keysearch(?CycleDetection, 1, QoS) of	{value, {_, ?AuthorizeCycles}} ->	    {ok, #state{parent_pid = ParentPid, id = MyId, 			graph = digraph:new([private]),			diamonds = Diamonds, cyclic = ?AuthorizeCycles}};	_ ->	    {ok, #state{parent_pid = ParentPid, id = MyId, 			graph = digraph:new([acyclic, private]),			diamonds = Diamonds, cyclic = ?ForbidCycles}}    end.%%----------------------------------------------------------------------%% Function   : terminate/2%% Returns    : any (ignored by gen_server)%% Description: Shutdown the server%%----------------------------------------------------------------------terminate(_Reason, #state{graph = DG} = _State) ->    Connections = digraph:edges(DG),    close_connections(DG, Connections),    digraph:delete(DG),    ok.%%----------------------------------------------------------------------%% Function   : code_change/3%% Returns    : {ok, NewState}%% Description: Convert process state when code is changed%%----------------------------------------------------------------------code_change(_OldVsn, State, _Extra) ->    {ok, State}.%%----------------------------------------------------------------------%% Function   : handle_info/2%% Returns    : {noreply, State}   |%%              {stop, Reason, State}  %% Description: Handle, for example, exit signals.%%----------------------------------------------------------------------handle_info({'EXIT', Pid, Reason}, #state{parent_pid = Pid} = State) ->    {stop, Reason, State};handle_info(_Info, State) ->    {noreply, State}.%%----------------------------------------------------------------------%%------------------ CosEventDomainAdmin::EventDomain ------------------%%---------------------------------------------------------------------%%% Function   : add_channel%% Arguments  : Channel - CosNotifyChannelAdmin::EventChannel%% Returns    : MemberId - long()%% Description: %%----------------------------------------------------------------------add_channel(_OE_This, #state{ch_counter=C, graph = DG} = State, Channel) ->    type_check(Channel, 'CosNotifyChannelAdmin_EventChannel'),    Id = cosEventDomainApp:create_id(C),    digraph:add_vertex(DG, Id, Channel),    {reply, Id, State#state{ch_counter=Id}}.%%---------------------------------------------------------------------%%% Function   : get_all_channels%% Arguments  : -%% Returns    : CosEventDomainAdmin::MemberIDSeq ([long()])%% Description: %%----------------------------------------------------------------------get_all_channels(_OE_This, #state{graph = DG} = State) ->    {reply, digraph:vertices(DG), State}.%%---------------------------------------------------------------------%%% Function   : get_channel%% Arguments  : Id - CosEventDomainAdmin::MemberID (long())%% Returns    : CosNotifyChannelAdmin::EventChannel |%%              {'EXCEPTION', #'CosNotifyChannelAdmin_ChannelNotFound'{}}%% Description: %%----------------------------------------------------------------------get_channel(_OE_This, #state{graph = DG} = State, Id) ->    {reply, lookup_channel(DG, Id), State}.%%---------------------------------------------------------------------%%% Function   : remove_channel%% Arguments  : Id - CosEventDomainAdmin::MemberID (long())%% Returns    : ok |%%              {'EXCEPTION', #'CosNotifyChannelAdmin_ChannelNotFound'{}}%% Description: %%----------------------------------------------------------------------remove_channel(_OE_This, #state{graph = DG} = State, Id) ->    lookup_channel(DG, Id),    close_connections(DG, digraph:edges(DG, Id)),    digraph:del_vertex(DG, Id),    {reply, ok, State}.	    %%---------------------------------------------------------------------%%% Function   : add_connection%% Arguments  : Connection - CosEventDomainAdmin::Connection%% Returns    : ConnectionID |%%              {'EXCEPTION', #'CosNotifyChannelAdmin_ChannelNotFound'{}} |%%              {'EXCEPTION', #'CosNotifyChannelAdmin_TypeError'{}} |%%              {'EXCEPTION', #'CosEventDomainAdmin_AlreadyExists'{}} |%%              {'EXCEPTION', #'CosEventDomainAdmin_CycleCreationForbidden'{cyc}} |%%              {'EXCEPTION', #'CosEventDomainAdmin_DiamondCreationForbidden'{diam}}%% Description: %%----------------------------------------------------------------------add_connection(_OE_This, #state{graph = DG, co_counter = C} = State, 	       Connection) when record(Connection, 				       'CosEventDomainAdmin_Connection') ->    SId = Connection#'CosEventDomainAdmin_Connection'.supplier_id,    SChannel = lookup_channel(DG, SId),    CId = Connection#'CosEventDomainAdmin_Connection'.consumer_id,    CChannel = lookup_channel(DG, CId),    case lists:member(CId, digraph:out_neighbours(DG, SId)) of	false ->	    Id = cosEventDomainApp:create_id(C),	    %% Try to insert the new connection before we actually setup a connection.	    %% Note that #connection is NOT complete, hence, we must update it later.	    case digraph:add_edge(DG, Id, SId, CId, #connection{data=Connection}) of		{error, {bad_edge, Path}} ->		    corba:raise(#'CosEventDomainAdmin_CycleCreationForbidden'{cyc=Path});		Id when State#state.diamonds == ?AuthorizeDiamonds ->		    case catch setup_connection(Connection, SChannel, CChannel) of			{ok, SProxy, CProxy} ->			    %% Now we can update the connection with complete data.			    digraph:add_edge(DG, Id, SId, CId, #connection{supplier=SProxy,									   consumer=CProxy,									   data=Connection}),			    {reply, Id, State#state{co_counter = Id}};			{'EXCEPTION', E} ->			    digraph:del_edge(DG, Id),			    corba:raise(E);			What ->			    digraph:del_edge(DG, Id),			    orber:dbg("[~p] CosEventDomainAdmin_EventDomain:"				      "add_connection(~p);~nFailed setting up"				      " connection due to: ~p", 				      [?LINE, Connection, What], ?DEBUG_LEVEL),			    corba:raise(#'INTERNAL'{completion_status=?COMPLETED_MAYBE})		    end;		Id ->		    case get_diamonds_helper(State, false, SId) of			[] ->			    case catch setup_connection(Connection, SChannel, CChannel) of				{ok, SProxy, CProxy} ->				    %% Now we can update the connection with complete data.				    digraph:add_edge(DG, Id, SId, CId, #connection{supplier=SProxy,										   consumer=CProxy,										   data=Connection}),				    {reply, Id, State#state{co_counter = Id}};				{'EXCEPTION', E} ->				    digraph:del_edge(DG, Id),				    corba:raise(E);				What ->				    digraph:del_edge(DG, Id),				    orber:dbg("[~p] CosEventDomainAdmin_EventDomain:"					      "add_connection(~p);~nFailed setting"					      " up connection due to: ~p", 

⌨️ 快捷键说明

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