cosnotification_filter.erl

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

ERL
964
字号
    case catch M:tc() of	{tk_struct,_,_,SList} ->	    %% {tk_struct, Id, Name, ElementList}.	    Field = get_field(ID, SList),	    element(Field, Value);	{tk_union,_,_,_, DefNo, UList} ->	    %% {tk_union, Id, Name, DiscrTC, Default, ElementList}	    case id2switch(UList, ID) of		[default] when DefNo >= 0 ->		    element(3, Value);		[default] ->		    throw({error, {bad_id, "Bad Union ID supplied"}});		Found ->		    case catch lists:member(element(2, Value), Found) of			true ->			    element(3, Value);			_ ->			    throw({error, {bad_id, "Bad Union ID supplied"}})		    end	    end;	_->	    throw({error, {bad_id, ID}})    end;get_variable([#'CosNotification_Property'{name=ID, value=A}|_], ID, _) ->    any:get_value(A);get_variable([_|T], ID, Any) ->    get_variable(T, ID, Any).%%------------------------------------------------------------%% function : lookup%% Arguments: T - A parse tree representing the grammar.%%            S - The event we want to extract data from%%            Op - which type of lookup should be done on this%%                 component, e.g., 'default' or 'exist'.%% Returns  : {ok, boolean()} |%%            {error, _}%% Comment  : WARNING!!!! %%            This function uses some Orber core information to %%            extract data, e.g., TypeCode representation. Why?%%            We don't want to see the performance take a plunge%%            due to that users write constraints which they%%            can/may not know is slow. The alternative would be%%            to use the IFR. However, these shortcuts aren't%%            that frequent and we can easily update the code.%%            To update, investigate:%%            * lookup/3 cases related to '_type_id'%%            * lookup/3 cases related to unions%%            * get_variable/3%%            * id2switch/2%%            * switch2alias/2%%------------------------------------------------------------%% Done parsing, return the result.lookup([],S,_) -> {ok, S};lookup('$empty', #'CosNotification_StructuredEvent'{remainder_of_body = Any},_) ->     {ok, any:get_value(Any)};lookup('$empty',S,_) when record(S, any) ->     {ok, any:get_value(S)};%%------- varid --------%% CosNotification-revision-98-11-01/46 states:%% "The following rules govern translation of a run-time variable,   $variable , %% into a specific event field. If the run-time variable is reserved %% (e.g., $curtime) this translation takes precedence. Next, the first matching%% translation is chosen respectively from: %% * a simple-typed member of $.header.fixed_header, %% * properties in $.header.variable_header, %% and properties in $.header.filterable_data.%% If no match is found, the translation defaults to $.variable. %% Given these rules, an unstructured event with a $.priority member and a %% structured event using $.header.variable_header(priority) can be specified %% in a generic constraint using the run-time variable  $priority . %% Alternatively, a constraint can be written specifically for a structured or %% unstructured event by avoiding the use of run-time variables."%% The above contains one error; $.header.filterable_data is not a part of the%% header, but contained in the event body.%% For any events we must first verify that a path exist, e.g.,%% "header"->"fixed_header"->"event_type"->"domain_name", otherwise we will%% use {dotid, "xxx"}.lookup([{varid, "type_name"}|T],        #'CosNotification_StructuredEvent'       {header = #'CosNotification_EventHeader'	{fixed_header = #'CosNotification_FixedEventHeader'	 {event_type =  #'CosNotification_EventType'{type_name=TN}}}}, Op) ->    lookup(T, TN, Op);lookup([{varid, "type_name"}|T], Any, Op) when record(Any, any) ->    case locate_var([?TYPE_PATH, ?VARIABLE_PATH("type_name"), 		     ?FILTERABLE_PATH("type_name")], Any, Op) of	{ok, Val} ->	    lookup(T, Val, Op);	_ ->	    lookup(T, get_variable([], "type_name", Any), Op)    end;lookup([{varid, "domain_name"}|T],        #'CosNotification_StructuredEvent'       {header = #'CosNotification_EventHeader'	{fixed_header = #'CosNotification_FixedEventHeader'	 {event_type =  #'CosNotification_EventType'{domain_name=DN}}}}, Op) ->    lookup(T, DN, Op);lookup([{varid, "domain_name"}|T], Any, Op) when record(Any, any) ->    case locate_var([?DOMAIN_PATH, ?VARIABLE_PATH("domain_name"), 		     ?FILTERABLE_PATH("domain_name")], Any, Op) of	{ok, Val} ->	    lookup(T, Val, Op);	_ ->	    lookup(T, get_variable([], "domain_name", Any), Op)    end;lookup([{varid, "event_name"}|T],        #'CosNotification_StructuredEvent'       {header = #'CosNotification_EventHeader'	{fixed_header = #'CosNotification_FixedEventHeader'	 {event_name =  EN}}}, Op) ->    lookup(T, EN, Op);lookup([{varid, "event_name"}|T], Any, Op) when record(Any, any) ->    case locate_var([?EVENT_PATH, ?VARIABLE_PATH("event_name"), 		     ?FILTERABLE_PATH("event_name")], Any, Op) of	{ok, Val} ->	    lookup(T, Val, Op);	_ ->	    lookup(T, get_variable([], "event_name", Any), Op)    end;lookup([{varid, ID}|T], 	     #'CosNotification_StructuredEvent'{header =		#'CosNotification_EventHeader'{variable_header = VS},						filterable_data = FS,						remainder_of_body = Any}, Op) ->    lookup(T, get_variable(VS++FS, ID, Any), Op);lookup([{varid, ID}|T], Any, Op) ->    case locate_var([?VARIABLE_PATH(ID), ?FILTERABLE_PATH(ID)], Any, Op) of	{ok, Val} ->	    lookup(T, Val, Op);	_ ->	    lookup(T, get_variable([], ID, Any), Op)    end;%%------- dotid --------%% First levellookup([{dotid, "header"}|T], 	     #'CosNotification_StructuredEvent'{header = S}, Op) ->    lookup(T, S, Op);lookup([{dotid, "filterable_data"}|T], 	     #'CosNotification_StructuredEvent'{filterable_data = S}, Op) ->    lookup(T, S, Op);lookup([{dotid, remainder_of_body}|T], 	     #'CosNotification_StructuredEvent'{remainder_of_body = S}, Op) ->    lookup(T, S, Op);%% Second level. Previous token must have been headerlookup([{dotid, "fixed_header"}|T], 	     #'CosNotification_EventHeader'{fixed_header = S}, Op) ->    lookup(T, S, Op);lookup([{dotid, "variable_header"}|T], 	     #'CosNotification_EventHeader'{variable_header = S}, Op) ->    lookup(T, S, Op);%% Third level. Previous token must have been fixed_header.lookup([{dotid, "event_type"}|T], 	     #'CosNotification_FixedEventHeader'{event_type = S}, Op) ->    lookup(T, S, Op);lookup([{dotid, "event_name"}|T], 	     #'CosNotification_FixedEventHeader'{event_name = S}, Op) ->    lookup(T, S, Op);%% Fourth level. Previous token must have been event_typelookup([{dotid, "domain_name"}|T], #'CosNotification_EventType'{domain_name = S}, Op) ->    lookup(T, S, Op);lookup([{dotid, "type_name"}|T], #'CosNotification_EventType'{type_name = S}, Op) ->    lookup(T, S, Op);%% Leaf expressionslookup([{dotid, "name"}|T], #'CosNotification_Property'{name=S}, Op)  ->    lookup(T, S, Op); lookup([{dotid, "value"}|T], #'CosNotification_Property'{value=S}, Op)  ->    lookup(T, S, Op); lookup([{dotid, ID}|T],        #'CosNotification_StructuredEvent'{remainder_of_body = Any}, Op) ->    lookup(T, get_variable([], ID, Any), Op);lookup([{dotid, ID}|T], Any, Op) ->    lookup(T, get_variable([], ID, Any), Op);lookup([{associd, ID}|T], S, Op) when list(S) ->    %% Refers to an associative array, i.e., a list of    %% #'CosNotification_Property'{name=ID, value=A}    lookup(T, get_variable(S, ID, false), Op);lookup([{dotint, Position}|T], S, Op) when record(S, any) ->    lookup(T, element(Position+2, any:get_value(S)), Op);lookup([{dotint, Position}|T], S, Op) ->    lookup(T, element(Position+2, S), Op);lookup([{uint, ID}|T], S, Op) when record(S, any) ->    lookup([{uint, ID}|T], any:get_value(S), Op);lookup([{uint, ID} |T], S, Op) when tuple(S) ->    case catch element(2, S) of	ID ->	    %% The supplied union do contain the requested discriminator.	    lookup(T, element(3, S), Op);	_Other when Op == exist_component ->	    throw({error, {bad_id, "Bad Union ID"}});	Other ->	    %% Check if default is allowed.	    M = element(1, S),	    case catch M:tc() of		{tk_union,_,_,_,DefNo, UList} ->		    %% {tk_union, Id, Name, DiscrTC, Default, ElementList}		    case switch2alias(UList, ID) of			{ok, [], _} ->			    throw({error, {bad_id, "Bad Union ID"}});			{ok, default, _} when DefNo >= 0 ->			    lookup(T, element(3, S), Op);			{ok, List, _} ->			    case lists:member(Other, List) of				true ->				    lookup(T, element(3, S), Op);				_->				    throw({error, {bad_id, "Bad Union ID"}})			    end		    end	    end    end;lookup([{ustr, ID}|T], S, Op) when record(S, any) ->    lookup([{ustr, ID}|T], any:get_value(S), Op);lookup([{ustr, ID}|T], S, Op) when tuple(S) ->    M = element(1, S),    case catch M:tc() of	{tk_union,_,_,_,DefNo, UList} ->	    case id2switch(UList, ID) of		[default] when DefNo >= 0 ->		    lookup(T, element(3, S), Op);		[default] ->		    throw({error, {bad_id, "Bad Union ID supplied"}});		Found ->		    case catch lists:member(element(2, S), Found) of			true ->			    lookup(T, element(3, S), Op);			_ ->			    throw({error, {bad_id, "Bad Union ID supplied"}})		    end	    end    end;lookup([default|T], S, Op) when record(S, any) ->    lookup([default|T], any:get_value(S), Op);lookup([default|T], S, Op) when tuple(S) ->    M = element(1, S),    case catch M:tc() of	{tk_union,_,_,_,DefNo, _UList} when DefNo < 0 ->	    %% {tk_union, Id, Name, DiscrTC, Default, ElementList}	    throw({error, {bad_id, "No default discriminator"}});	{tk_union,_,_,_,_DefNo, UList} ->	    %% {tk_union, Id, Name, DiscrTC, Default, ElementList}	    %% Check if the label really is default.	    case lists:keymember(element(2, S), 1, UList) of		false ->		    lookup(T, element(3, S), Op);		_->		    throw({error, {bad_id, "Bad Union"}})	    end;	_->	    throw({error, {bad_id, "Bad Union"}})    end;lookup([{arrindex, Index}|T], S, Op) when tuple(S) ->    %% The OMG uses c/c++ index. We must add one.    lookup(T, element(Index+1,S), Op);%%%%%%%%%%%%%%%%%%%%%%% LEAF EXPRESSIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% got '$._length', which maps to the 'remainder_of_body'lookup(['_length'],	     #'CosNotification_StructuredEvent'{remainder_of_body = Any}, _Op) ->    {ok, length(any:get_value(Any))};lookup(['_length'], S, _Op)  when record(S, any) ->    {ok, length(any:get_value(S))};lookup(['_length'], S, _Op)  when list(S) ->    {ok, length(S)};lookup(['_length'], S, _Op)  when tuple(S) ->    {ok, length(tuple_to_list(S))};%% got '$._d', which maps to the 'remainder_of_body'%% The discriminator may, accordiong to the CORBA specification, be (2.3/p3-37):%% * integer_type%% * char_type%% * boolean_type%% * enum_type%% * scoped_namelookup(['_d'],        #'CosNotification_StructuredEvent'{remainder_of_body = Any},        default_component) ->    lookup(['_d'], any:get_value(Any), default_component);lookup(['_d'], S, default_component) when record(S, any) ->    lookup(['_d'], any:get_value(S), default_component);lookup(['_d'], S, default_component) ->    M = element(1, S),    case catch M:tc() of	{tk_union,_,_,_,DefNo,_} when DefNo < 0 -> 	    %% '-1' indicates that no default value may exist.	    {ok, false};	{tk_union,_,_,_,_,UList} -> 	    %% May be using the default setting; check if the Value is in the list.	    {ok, not lists:keymember(element(2, S), 1, UList)};	_ ->	    {ok, false}    end;lookup(['_d'],        #'CosNotification_StructuredEvent'{remainder_of_body = Any}, _Op) ->    {ok, element(2, any:get_value(Any))};lookup(['_d'], S, _Op) when record(S, any) ->    {ok, element(2, any:get_value(S))};lookup(['_d'], S, _Op) ->    {ok, element(2, S)};lookup(['_type_id'], S, _Op) when record(S,'CosNotification_StructuredEvent') ->    {ok, "StructuredEvent"};lookup(['_type_id'], S, _Op) when record(S,'CosNotification_EventHeader') ->    {ok, "EventHeader"};lookup(['_type_id'], S, _Op) when record(S,'CosNotification_FixedEventHeader') ->    {ok, "FixedEventHeader"};lookup(['_type_id'], S, _Op) when record(S,'CosNotification_EventType') ->    {ok, "EventType"};lookup(['_type_id'], S, _Op) when record(S,'CosNotification_Property') ->    {ok, "Property"};

⌨️ 快捷键说明

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