cosnotifyfilter_mappingfilter_impl.erl

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

ERL
578
字号
%%--------------------------------------------------------------------%% ``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    : CosNotifyFilter_MappingFilter_impl.erl%% Purpose : %% Created : 29 Dec 1999%%-----------------------------------------------------------------------module('CosNotifyFilter_MappingFilter_impl').%%--------------- INCLUDES -----------------------------------%% Application files-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").%%--------------- IMPORTS ------------------------------------%%--------------- EXPORTS ------------------------------------%% External Attributes-export(['_get_constraint_grammar'/2, 	 '_get_value_type'/2, 	 '_get_default_value'/2]).%% External Functions-export([add_mapping_constraints/3, 	 modify_mapping_constraints/4, 	 get_mapping_constraints/3,	 get_all_mapping_constraints/2, 	 remove_all_mapping_constraints/2, 	 destroy/2,	 match/3, 	 match_structured/3, 	 match_typed/3]).%%--------------- gen_server specific exports -----------------export([handle_info/2, code_change/3]).-export([init/1, terminate/2]).%%--------------- LOCAL DEFINITIONS --------------------------%%######### MISC ##########-define(create_MappingInfo(_Types, _Con, _ID, _A), 	#'CosNotifyFilter_MappingConstraintInfo'{				      constraint_expression = 				      #'CosNotifyFilter_ConstraintExp'{					event_types = _Types,					constraint_expr = _Con},				      constraint_id = _ID,				      value = _A				     }).%%#### Data structures ####-record(state, {constraint_grammar,		value,		typeC,		constraints = [],		filters = [],		idCounter = 0,		filterFactory,		factoryPid,		etsR}).%% Data structures constructors-define(get_InitState(Gr, DVal, FF, FP), 	#state{constraint_grammar=Gr,	       value = DVal,	       typeC = any:get_typecode(DVal),	       filterFactory = FF,	       factoryPid = FP,	       etsR = ets:new(oe_ets, [bag, protected])}).%%------------------- Data structures selectors -------------------%% Attributes-define(get_Grammar(S),         S#state.constraint_grammar).-define(get_DefVal(S),          S#state.value).-define(get_DefTC(S),           S#state.typeC).-define(get_DefAny(S),          S#state.value).%% ID:s-define(get_IdCounter(S),       S#state.idCounter).%% Constraints-define(get_Constraint(S,I),    find_obj(lists:keysearch(I, 1, S#state.constraints),					 constraint)).-define(get_AllConstraints(S),  lists:map(fun({I, C, _W, _WC, _K, T, A}) -> 						  ?create_MappingInfo(T, C, I, A) 					  end, 					  S#state.constraints)).-define(get_ConstraintAllData(S), S#state.constraints).-define(get_ConstraintData(S,I), lists:keysearch(I, 1, S#state.constraints)).-define(match_Type(S,I,ET),     ets:lookup(S#state.etsR, {I, ET})).%% Parse Tree-define(get_ParseTree(S,K),     find_obj(ets:lookup(S#state.etsR, K), tree)).%%------------------- Data structures modifiers -------------------%% ID:s-define(set_IdCounter(S,V),     S#state{idCounter=V}).-define(new_Id(S),              'CosNotification_Common':create_id(S#state.idCounter)).%% Constraints-define(del_Constraint(S, I),   match_delete(S, S#state.constraints, I)).-define(del_AllConstraints(S),  clear_DB(S)).-define(add_Constraint(S,I,C,W,_WC,K,T,A), S#state{constraints = 					  [{I, C, W, _WC, K, T, A}|S#state.constraints]}).-define(set_Constraints(S,C),   S#state{constraints = C}).-define(del_AllTypes(S),        ets:match_delete(S#state.etsR, {'_','_',types})).-define(del_Type(S,I),          ets:match_delete(S#state.etsR, {{I, '_'}, '_', types})).-define(add_Type(S,I,ET,K),     ets:insert(S#state.etsR, {{I, ET}, K, types})).%% Parse Tree-define(add_ParseTree(S,K,T),   ets:insert(S#state.etsR, {K, T, tree})).-define(del_ParseTree(S,K),     ets:delete(S#state.etsR, K)).-define(del_AllParseTress(S),   ets:match_delete(S#state.etsR, {'_','_',tree})).%%------------------- MISC -----------------------------------------define(is_EmptyFilter(S),     S#state.constraints==[]).-define(is_EqualType(S,T),     S#state.typeC==any:get_typecode(T)).%%-----------------------------------------------------------%%% function : handle_info, code_change%% Arguments: See gen_server documentation.%% Effect   : Functions demanded by the gen_server module. %%------------------------------------------------------------code_change(_OldVsn, State, _Extra) ->    {ok, State}.handle_info(Info, State) ->    ?debug_print("INFO: ~p  DATA: ~p~n", [State, Info]),    case Info of        {'EXIT', _Pid, _Reason} ->            {noreply, State};        _ ->            {noreply, State}    end.%%----------------------------------------------------------%%% function : init, terminate%% Arguments: %%-----------------------------------------------------------init([FiFac, FacPid, InitGr, DefVal]) ->    process_flag(trap_exit, true),    {ok, ?get_InitState(InitGr, DefVal, FiFac, FacPid)}.terminate(_Reason, _State) ->    ok.%%-----------------------------------------------------------%%------- Exported external attributes ----------------------%%-----------------------------------------------------------%%----------------------------------------------------------%%% Function : '_get_constraint_grammar'/2%% Type     : readonly%% Returns  : string()%%-----------------------------------------------------------'_get_constraint_grammar'(_OE_THIS, State) ->    {reply, ?get_Grammar(State), State}.%%----------------------------------------------------------%%% Function : '_get_value_type'/2%% Type     : readonly%% Returns  : CORBA::TypeCode%%-----------------------------------------------------------'_get_value_type'(_OE_THIS, State) ->    {reply, ?get_DefTC(State), State}.%%----------------------------------------------------------%%% Function : '_get_default_value'/2%% Type     : readonly%% Returns  : #any{}%%-----------------------------------------------------------'_get_default_value'(_OE_THIS, State) ->    {reply, ?get_DefVal(State), State}.%%-----------------------------------------------------------%%------- Exported external functions -----------------------%%-----------------------------------------------------------%%----------------------------------------------------------%%% Function : add_mapping_constraints/3%% Arguments: Pairs - CosNotifyFilter::MappingConstraintPairSeq%% Returns  : CosNotifyFilter::MappingConstraintInfoSeq |%%            {'EXCEPTION', CosNotifyFilter::InvalidConstraint} |%%            {'EXCEPTION', CosNotifyFilter::InvalidValue}%%-----------------------------------------------------------add_mapping_constraints(_OE_THIS, State, Pairs) ->    {NewState, Filters, Info} = try_create_filters(State, Pairs),    NewState2=store_filters(NewState, Filters),    {reply, Info, NewState2}.%%----------------------------------------------------------%%% Function : modify_mapping_constraints/4%% Arguments: IDs - CosNotifyFilter::ConstraintIDSeq%%            Info - CosNotifyFilter::MappingConstraintInfoSeq%% Returns  : ok |%%            {'EXCEPTION', CosNotifyFilter::InvalidConstraint} |%%            {'EXCEPTION', CosNotifyFilter::InvalidValue} |%%            {'EXCEPTION', CosNotifyFilter::ConstraintNotFound}%%-----------------------------------------------------------modify_mapping_constraints(_OE_THIS, State, IDs, InfoSeq) ->    lookup_constraints(IDs, State),    lookup_constraints(InfoSeq, State),    {NewState, Filters, _Info} = try_create_filters(State, InfoSeq),    %% We cannot change anything before our checks (see above). Hence,    %% do NOT move the following lines above this point.    NewState2  = delete_constraints(IDs, NewState),    NewState3  = delete_constraints(InfoSeq, NewState2),    NewState4  = store_filters(NewState3, Filters),    {reply, ok, NewState4}.%%----------------------------------------------------------%%% Function : get_mapping_constraints/3%% Arguments: IDs - CosNotifyFilter::ConstraintIDSeq%% Returns  : CosNotifyFilter::MappingConstraintInfoSeq |%%            {'EXCEPTION', CosNotifyFilter::ConstraintNotFound}%%-----------------------------------------------------------get_mapping_constraints(_OE_THIS, State, IDs) ->    {reply, lookup_constraints(IDs, State), State}.%%----------------------------------------------------------%%% Function : get_all_mapping_constraints/2%% Arguments: -%% Returns  : CosNotifyFilter::MappingConstraintInfoSeq %%-----------------------------------------------------------get_all_mapping_constraints(_OE_THIS, State) ->    {reply, ?get_AllConstraints(State), State}.%%----------------------------------------------------------%%% Function : remove_all_mapping_constraints/2%% Arguments: -%% Returns  : ok%%-----------------------------------------------------------remove_all_mapping_constraints(_OE_THIS, State) ->    {reply, ok, ?del_AllConstraints(State)}.%%----------------------------------------------------------%%% Function : destroy/2%% Arguments: -%% Returns  : ok%%-----------------------------------------------------------destroy(_OE_THIS, State) ->    {stop, normal, ok, State}.%%----------------------------------------------------------%%% Function : match/3%% Arguments: Event - #any{}%% Returns  : boolean(), #any{} (out-type) |%%            {'EXCEPTION', CosNotifyFilter::UnsupportedFilterableData}%%-----------------------------------------------------------match(_OE_THIS, State, Event) when record(Event,'any'), ?is_EmptyFilter(State) ->    {reply, {false, ?get_DefAny(State)}, State};match(_OE_THIS, State, Event) when record(Event,'any') ->    match_any_event(State, Event, ?get_ConstraintAllData(State));match(_,_,_) ->    corba:raise(#'BAD_PARAM'{completion_status=?COMPLETED_NO}).%%----------------------------------------------------------%%% Function : match_structured/3%% Arguments: Event - CosNotification::StructuredEvent%% Returns  : boolean(), #any{} (out-type) |%%            {'EXCEPTION', CosNotifyFilter::UnsupportedFilterableData}%%-----------------------------------------------------------match_structured(_OE_THIS, State, Event) when   record(Event,'CosNotification_StructuredEvent'), ?is_EmptyFilter(State) ->    {reply, {false, ?get_DefAny(State)}, State};match_structured(_OE_THIS, State, Event) when   record(Event,'CosNotification_StructuredEvent') ->    match_str_event(State, Event, ?get_ConstraintAllData(State));

⌨️ 快捷键说明

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