cosnotifyfilter_mappingfilter_impl.erl
来自「OTP是开放电信平台的简称」· ERL 代码 · 共 578 行 · 第 1/2 页
ERL
578 行
match_structured(_,_,_) -> corba:raise(#'BAD_PARAM'{completion_status=?COMPLETED_NO}).%%----------------------------------------------------------*%% Function : match_typed/3%% Arguments: Data - CosNotification::PropertySeq%% Returns : boolean() , #any{} (out-type) |%% {'EXCEPTION', CosNotifyFilter::UnsupportedFilterableData}%%-----------------------------------------------------------match_typed(_OE_THIS, _State, _Data) -> corba:raise(#'NO_IMPLEMENT'{completion_status=?COMPLETED_NO}). %%--------------- LOCAL FUNCTIONS ----------------------------%% To match constraintsfind_obj({value, {Id, Con, _, _, _, Types, Any}}, _) -> ?create_MappingInfo(Types, Con, Id, Any);find_obj([{_, Tree, tree}|_], tree) -> Tree;find_obj(_,tree) -> undefined;find_obj(_,constraint) -> error.%% Delete given object from list and all related objects in DB (parse tree and types).match_delete(State, Constraints, ID) -> match_delete(State, Constraints, ID, []).match_delete(_, [], _, _) -> error;match_delete(State, [{ID, _Con, _Which, _WC, Key, _Types, _Any}|T], ID, Acc) -> ?del_Type(State, ID), ?del_ParseTree(State, Key), {ok, ?set_Constraints(State, Acc++T)};match_delete(State, [H|T], ID, Acc) -> match_delete(State, T, ID, [H|Acc]).%% Remove all data related with constraints; for now, since no other data %% stored in DB, we do in a rather brutal way.clear_DB(State) -> catch ets:delete(State#state.etsR), State#state{etsR = ets:new(oe_ets, [bag, protected]), constraints=[]}.%% Given a list of Constrain IDs we want to find the related constraints.%% !!!!!! This function may not alter any data in DB in any way !!!!!!!!!!lookup_constraints(IDs, State) -> lookup_constraints(IDs, State, []).lookup_constraints([], _State, Accum) -> Accum;lookup_constraints([H|T], State, Accum) when record(H, 'CosNotifyFilter_MappingConstraintInfo') -> case ?get_Constraint(State, H#'CosNotifyFilter_MappingConstraintInfo'.constraint_id) of error -> corba:raise(#'CosNotifyFilter_ConstraintNotFound' {id = H#'CosNotifyFilter_MappingConstraintInfo'.constraint_id}); _Con -> %% We don't need to collect the result since the input already is of %% the correct type, i.e., ConstraintInfoSeq lookup_constraints(T, State, Accum) end;lookup_constraints([H|T], State, Accum) when integer(H) -> case ?get_Constraint(State,H) of error -> corba:raise(#'CosNotifyFilter_ConstraintNotFound'{id=H}); Con -> lookup_constraints(T, State, [Con|Accum]) end;lookup_constraints(_, _, _) -> corba:raise(#'BAD_PARAM'{completion_status=?COMPLETED_NO}).%% Given a list of Constrain IDs we want to delet the related constraints.%% We need also to return the ConstraintInfoSeq described related to the%% given ID's.delete_constraints([], State) -> State;delete_constraints([H|T], State) when record(H, 'CosNotifyFilter_MappingConstraintInfo') -> case catch ?del_Constraint(State, H#'CosNotifyFilter_MappingConstraintInfo'.constraint_id) of {ok, NewState} -> delete_constraints(T, NewState); Reason -> orber:dbg("[~p] 'CosNotifyFilter_MappingFilter':modify_mapping_constraints().~n" "Unable to remove: ~p~n" "Reason: ~p~n", [?LINE, H, Reason], ?DEBUG_LEVEL), delete_constraints(T, State) end;delete_constraints([H|T], State) -> case catch ?del_Constraint(State,H) of {ok, NewState} -> delete_constraints(T, NewState); Reason -> orber:dbg("[~p] 'CosNotifyFilter_MappingFilter':modify_mapping_constraints().~n" "Unable to remove: ~p~n" "Reason: ~p~n", [?LINE, H, Reason], ?DEBUG_LEVEL), delete_constraints(T, State) end. %%-----------------------------------------------------------%% Function : try_create_filters/2%% Arguments: CL - #'CosNotifyFilter_MappingConstraintPair{%% constraint_expression = %% #'CosNotifyFilter_ConstraintExp'{%% event_types = %% [#'CosNotification_EventType'{%% domain_name = Str, type_name = Str}]%% constraint_expr = Str},%% result_to_set = Any}%% Returns : {State, AccumList}%%-----------------------------------------------------------%% !!!!!! This function may not alter any data in DB in any way !!!!!!!!!!try_create_filters(State, CL) -> try_create_filters(State, CL, [], []).try_create_filters(State, [], Accum, InfoSeq) -> {State, Accum, InfoSeq};try_create_filters(State, [#'CosNotifyFilter_MappingConstraintPair' {constraint_expression = #'CosNotifyFilter_ConstraintExp'{event_types = Types, constraint_expr = Con}, result_to_set=Any}|T], Accum, InfoSeq) -> case catch {?is_EqualType(State,Any), cosNotification_Filter:create_filter(Con)} of {false, _} -> corba:raise(#'CosNotifyFilter_InvalidValue' {constr = #'CosNotifyFilter_ConstraintExp' {event_types = Types, constraint_expr = Con}, value=Any}); {_, {ok, Tree}} -> case catch cosNotification_Filter:check_types(Types) of true -> ID = ?new_Id(State), Key = ?not_CreateDBKey, try_create_filters(?set_IdCounter(State, ID), T, [{ID, true, [], Key, Types, Con, Tree, Any}|Accum], [?create_MappingInfo(Types, Con, ID, Any)|InfoSeq]); {ok, Which, WC} -> ID = ?new_Id(State), Key = ?not_CreateDBKey, try_create_filters(?set_IdCounter(State, ID), T, [{ID, Which, WC, Key, Types, Con, Tree, Any}|Accum], [?create_MappingInfo(Types, Con, ID, Any)|InfoSeq]); _ -> corba:raise(#'BAD_PARAM'{completion_status=?COMPLETED_NO}) end; _ -> corba:raise(#'CosNotifyFilter_InvalidConstraint' {constr = #'CosNotifyFilter_ConstraintExp' {event_types = Types, constraint_expr = Con}}) end;try_create_filters(State, [#'CosNotifyFilter_MappingConstraintInfo' {constraint_expression = #'CosNotifyFilter_ConstraintExp' {event_types = Types, constraint_expr = Con}, constraint_id=ID, value=Any}|T], Accum, InfoSeq) -> case catch cosNotification_Filter:create_filter(Con) of {ok, Tree} -> case catch cosNotification_Filter:check_types(Types) of true -> Key = ?not_CreateDBKey, try_create_filters(State, T, [{ID, true, [], Key, Types, Con, Tree, Any}|Accum], [?create_MappingInfo(Types, Con, ID, Any)|InfoSeq]); {ok, Which, WC} -> Key = ?not_CreateDBKey, try_create_filters(State, T, [{ID, Which, WC, Key, Types, Con, Tree, Any}|Accum], [?create_MappingInfo(Types, Con, ID, Any)|InfoSeq]); _ -> corba:raise(#'BAD_PARAM'{completion_status=?COMPLETED_NO}) end; _ -> corba:raise(#'CosNotifyFilter_InvalidConstraint' {constr = #'CosNotifyFilter_ConstraintExp' {event_types = Types, constraint_expr = Con}}) end;try_create_filters(_,_,_,_) -> %% The list contained something else but ConstraintExp. corba:raise(#'BAD_PARAM'{completion_status=?COMPLETED_NO}).%%-----------------------------------------------------------%% Function : store_filters/4%% Arguments: Filters - a list of filters.%% Returns : %%-----------------------------------------------------------store_filters(State, []) -> State;store_filters(State, [{ID, Which, WC, Key, Types, Con, Tree, Any}|T]) -> ?add_ParseTree(State, Key, Tree), write_types(State, Types, ID, Key), store_filters(?add_Constraint(State, ID, Con, Which, WC, Key, Types, Any), T). write_types(_State, [],_, _) -> ok;write_types(State, [EventType|T], ID, Key) -> ?add_Type(State, ID, EventType, Key), ?debug_print("FILTER: ~p ~p ~p~n", [ID, Key, EventType]), write_types(State, T, ID, Key).%%-----------------------------------------------------------%% Function : match_any_event%% Arguments: Event - #any{}%% Returns : %%-----------------------------------------------------------match_any_event(State, _Event, []) -> ?debug_print("FILTER REJECTED: ~p~n", [_Event]), {reply, {false, ?get_DefAny(State)}, State};match_any_event(State, Event, [{_, _, _, _, Key, Any}|T]) -> case catch cosNotification_Filter:eval(?get_ParseTree(State,Key), Event) of true -> ?debug_print("FILTER APPROVED (WC): ~p~n", [Event]), {reply, {true, Any}, State}; _ -> match_any_event(State, Event, T) end. %%-----------------------------------------------------------%% Function : match_str_event%% Arguments: %% Returns : %%-----------------------------------------------------------match_str_event(State, _Event, []) -> ?debug_print("FILTER REJECTED: ~p~n", [_Event]), {reply, {false, ?get_DefAny(State)}, State};match_str_event(State, Event, [{ID, _Con, Which, WC, Key, _Types, Any}|T]) -> ET = ((Event#'CosNotification_StructuredEvent'.header) #'CosNotification_EventHeader'.fixed_header) #'CosNotification_FixedEventHeader'.event_type, CheckList = case Which of both -> [ET]; domain -> [ET, ET#'CosNotification_EventType'{type_name=""}, ET#'CosNotification_EventType'{type_name="*"}]; type -> [ET, ET#'CosNotification_EventType'{domain_name=""}, ET#'CosNotification_EventType'{domain_name="*"}]; _ -> [ET, ET#'CosNotification_EventType'{type_name=""}, ET#'CosNotification_EventType'{type_name="*"}, ET#'CosNotification_EventType'{domain_name=""}, ET#'CosNotification_EventType'{domain_name="*"}] end, case check_DB(State, ID, CheckList) of false -> %% No match, may have used wildcards, e.g., "dom*". case catch cosNotification_Filter:match_types( ET#'CosNotification_EventType'.domain_name, ET#'CosNotification_EventType'.type_name, WC) of true -> case catch cosNotification_Filter:eval(?get_ParseTree(State,Key), Event) of true -> ?debug_print("FILTER APPROVED (WC): ~p~n", [Event]), {reply, {true, Any}, State}; _ -> match_str_event(State, Event, T) end; _-> match_str_event(State, Event, T) end; Key -> case catch cosNotification_Filter:eval(?get_ParseTree(State,Key), Event) of true -> ?debug_print("FILTER APPROVED: ~p~n", [Event]), {reply, {true, Any}, State}; _ -> match_str_event(State, Event, T) end end.check_DB(_, _, []) -> false;check_DB(State, ID, [H|T]) -> case ?match_Type(State, ID, H) of [] -> check_DB(State, ID, T); [{_, K, types}|_] -> K end.%%--------------- MISC FUNCTIONS, E.G. DEBUGGING -------------%%--------------- END OF MODULE ------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?