📄 cospropertyservice_propertysetdef_impl.erl
字号:
locate_names(T, X, false, [#'CosPropertyService_Property' {property_name = "", property_value = any:create(tk_void, ok)}|Acc]);locate_names([H|T], X, AllOK, Acc) -> case catch find_property(X, H, value) of {'EXCEPTION', _} -> locate_names(T, X, false, [#'CosPropertyService_Property' {property_name = H, property_value = any:create(tk_void, ok)}|Acc]); Val -> locate_names(T, X, AllOK, [#'CosPropertyService_Property' {property_name = H, property_value = Val}|Acc]) end.%%---------------------------------------------------------------------%%% Function : get_all_properties%% Arguments : %% Description: %% Returns : {ok, State}%%----------------------------------------------------------------------get_all_properties(_OE_THIS, State, Max) -> X = lookup_table(?get_DBKey(State)), {reply, get_all_properties_helper(X, [], Max), State}.get_all_properties_helper([], Acc, _) -> %% There are no more properties; return a nil-object refernce. {ok, Acc, corba:create_nil_objref()};get_all_properties_helper(Left, Acc, 0) -> %% There are more properties; create Iterartor. Properties = lists:map(?Local2Property, Left), {ok, Acc, cosProperty:start_PropertiesIterator(Properties)};get_all_properties_helper([{Name, Val, _}|T], Acc, No) -> get_all_properties_helper(T, [#'CosPropertyService_Property' {property_name = Name, property_value = Val}|Acc], No-1).%%---------------------------------------------------------------------%%% Function : delete_properties%% Arguments : %% Description: %% Returns : {ok, State}%%----------------------------------------------------------------------delete_properties(_OE_THIS, State, []) -> {reply, ok, State};delete_properties(_OE_THIS, State, PropertyNames) when ?is_NotStatic(State) -> _DF = fun() -> case mnesia_read(State) of {'EXCEPTION', E} -> {'EXCEPTION', E}; X -> case catch delete_properties_helper(X, [], [], PropertyNames, State, length(X)) of {'EXCEPTION', E} -> {'EXCEPTION', E}; {{'EXCEPTION', E}, NotDeleted} -> ok = mnesia_write(State, NotDeleted), {'EXCEPTION', E}; {ok, NotDeleted} -> mnesia_write(State, NotDeleted) end end end, {reply, mnesia_transaction(_DF), State};delete_properties(_OE_THIS, State, PropertyNames) -> X = lookup_table(?get_DBKey(State)), case delete_properties_helper(X, [], [], PropertyNames, State, length(X)) of {'EXCEPTION', E} -> corba:raise(E); _-> %% Not acceptable if it was possible to delete one or more Properties. corba:raise(#'INTERNAL'{completion_status=?COMPLETED_NO}) end.delete_properties_helper([], [], NotDeleted, [], _State, _Len) -> %% Since there are no exceptions we have been able to delete all %% properties. {ok, NotDeleted};delete_properties_helper([], MultipleExc, NotDeleted, Names, _State, Len) -> %% Write remaining events to DB. case length(NotDeleted) of Len -> {'EXCEPTION', #'CosPropertyService_MultipleExceptions' {exceptions = add_not_found(Names, MultipleExc)}}; _-> {{'EXCEPTION', #'CosPropertyService_MultipleExceptions' {exceptions = add_not_found(Names, MultipleExc)}}, NotDeleted} end;delete_properties_helper([{Name, Val, Mode}|T], MultipleExc, NotDeleted, Names, State, Len) -> case lists:member(Name, Names) of true when Mode =/= fixed_normal, Mode =/= fixed_readonly -> delete_properties_helper(T, MultipleExc, NotDeleted, lists:delete(Name, Names), State, Len); true -> delete_properties_helper(T, [#'CosPropertyService_PropertyException' {reason = fixed_property, failing_property_name = Name}|MultipleExc], [{Name, Val, Mode}|NotDeleted], lists:delete(Name, Names), State, Len); false -> delete_properties_helper(T, MultipleExc, [{Name, Val, Mode}|NotDeleted], Names, State, Len) end.add_not_found([], MultipleExc) -> MultipleExc;add_not_found([Name|T], MultipleExc) -> add_not_found(T, [#'CosPropertyService_PropertyException' {reason = property_not_found, failing_property_name = Name}|MultipleExc]). %%---------------------------------------------------------------------%%% Function : delete_all_properties%% Arguments : %% Description: %% Returns : {ok, State}%%----------------------------------------------------------------------delete_all_properties(_OE_THIS, State) when ?is_NotStatic(State) -> _DF = fun() -> case mnesia_read(State) of {'EXCEPTION', E} -> {'EXCEPTION', E}; X -> case catch delete_all_properties_helper(X, [], State, length(X)) of {'EXCEPTION', E} -> {'EXCEPTION', E}; true -> ok = mnesia_write(State, []), true; false -> false; {false, NotDeleted} -> ok = mnesia_write(State, NotDeleted), false end end end, {reply, mnesia_transaction(_DF), State};delete_all_properties(_OE_THIS, State) -> X = lookup_table(?get_DBKey(State)), case delete_all_properties_helper(X, [], State, length(X)) of false -> {reply, false, State}; _-> corba:raise(#'INTERNAL'{completion_status=?COMPLETED_NO}) end.delete_all_properties_helper([], [], _State, _) -> %% Was able to delete all properties. true;delete_all_properties_helper([], NotDeleted, _State, Len) -> %% Write remaining events to DB. case length(NotDeleted) of Len -> false; _-> {false, NotDeleted} end;delete_all_properties_helper([{Name, Val, fixed_normal}|T], NotDeleted, State, Len) -> delete_all_properties_helper(T, [{Name, Val, fixed_normal}|NotDeleted], State, Len);delete_all_properties_helper([{Name, Val, fixed_readonly}|T], NotDeleted, State, Len) -> delete_all_properties_helper(T, [{Name, Val, fixed_readonly}|NotDeleted], State, Len);delete_all_properties_helper([_|T], NotDeleted, State, Len) -> delete_all_properties_helper(T, NotDeleted, State, Len).%%---------------------------------------------------------------------%%% Function : is_property_defined%% Arguments : %% Description: %% Returns : {ok, State}%%----------------------------------------------------------------------is_property_defined(_, _, "") -> corba:raise(#'CosPropertyService_InvalidPropertyName'{});is_property_defined(_OE_THIS, State, Name) -> X = lookup_table(?get_DBKey(State)), {reply, lists:keymember(Name, 1, X), State}.%%----------------------------------------------------------------------%% Interface CosPropertyService::PropertySetDef%%----------------------------------------------------------------------%%---------------------------------------------------------------------%%% Function : get_allowed_property_types%% Arguments : -%% Description: Returns the initially supplied restrictions. An empty%% list means no restrictions.%% Returns : {ok, TypeCodeList,State}%%----------------------------------------------------------------------get_allowed_property_types(_OE_THIS, State) when ?is_NotSetDef(State) -> corba:raise(#'NO_IMPLEMENT'{completion_status=?COMPLETED_NO});get_allowed_property_types(_OE_THIS, State) -> {reply, {ok, ?get_okTypes(State)}, State}.%%---------------------------------------------------------------------%%% Function : get_allowed_properties%% Arguments : %% Description: Returns the initially supplied restrictions. An empty%% list means no restrictions.%% Returns : {ok, PropertyDefList, State}%%----------------------------------------------------------------------get_allowed_properties(_OE_THIS, State) when ?is_NotSetDef(State) -> corba:raise(#'NO_IMPLEMENT'{completion_status=?COMPLETED_NO});get_allowed_properties(_OE_THIS, State) -> {reply, {ok, ?get_okProperties(State)}, State}.%%---------------------------------------------------------------------%%% Function : define_property_with_mode%% Arguments : %% Description: %% Returns : {ok, State}%%----------------------------------------------------------------------define_property_with_mode(_OE_THIS, State, _, _, _) when ?is_NotSetDef(State) -> corba:raise(#'NO_IMPLEMENT'{completion_status=?COMPLETED_NO});define_property_with_mode(_, _, "", _, _) -> corba:raise(#'CosPropertyService_InvalidPropertyName'{});define_property_with_mode(_OE_THIS, State, Name, Value, Mode) when ?is_NotStatic(State) -> evaluate_property_data(State, Value, Name), _DF = fun() -> case mnesia_read(State) of {'EXCEPTION', E} -> {'EXCEPTION', E}; X -> case catch update_property(X, Name, both, Value, Mode) of {'EXCEPTION', E} when record(E, 'CosPropertyService_PropertyNotFound') -> mnesia_write(State, [{Name, Value, Mode}|X]); {'EXCEPTION', E} -> {'EXCEPTION', E}; NewProperties -> mnesia_write(State, NewProperties) end end end, {reply, mnesia_transaction(_DF), State};define_property_with_mode(_OE_THIS, State, Name, Value, Mode) -> evaluate_property_data(State, Value, Name), X = lookup_table(?get_DBKey(State)), case catch update_property(X, Name, both, Value, Mode) of {'EXCEPTION', E} when record(E, 'CosPropertyService_PropertyNotFound') -> %% Should get not allowed exception. corba:raise(#'INTERNAL'{completion_status=?COMPLETED_NO}); {'EXCEPTION', E} -> corba:raise(E); _ -> %% Should be impossible. corba:raise(#'INTERNAL'{completion_status=?COMPLETED_NO}) end.%%---------------------------------------------------------------------%%% Function : define_properties_with_modes%% Arguments : %% Description: %% Returns : {ok, State}%%----------------------------------------------------------------------define_properties_with_modes(_OE_THIS, State, _) when ?is_NotSetDef(State) -> corba:raise(#'NO_IMPLEMENT'{completion_status=?COMPLETED_NO});define_properties_with_modes(_OE_THIS, State, PropertyDefSeq) when ?is_NotStatic(State)-> {OKProperteDefs, Exc} = evaluate_properties_data(State, PropertyDefSeq), _DF = fun() -> case mnesia_read(State) of {'EXCEPTION', E} -> {'EXCEPTION', E}; X -> case catch define_properties_with_modes_helper(OKProperteDefs, X, Exc, State) of {'EXCEPTION', E} -> {'EXCEPTION', E}; NewProperties -> mnesia_write(State, NewProperties) end end end, {reply, mnesia_transaction(_DF), State};define_properties_with_modes(_OE_THIS, State, PropertyDefSeq) -> {OKProperteDefs, Exc} = evaluate_properties_data(State, PropertyDefSeq), X = lookup_table(?get_DBKey(State)), case define_properties_with_modes_helper(OKProperteDefs, X, Exc, State) of {'EXCEPTION', E} -> corba:raise(E); _ -> corba:raise(#'INTERNAL'{completion_status=?COMPLETED_NO}) end. define_properties_with_modes_helper([], NewPropertyDefs, [], _State) -> %% No exceptions found. NewPropertyDefs;define_properties_with_modes_helper([], _, Exc, _) -> {'EXCEPTION', #'CosPropertyService_MultipleExceptions'{exceptions = Exc}};define_properties_with_modes_helper([#'CosPropertyService_PropertyDef' {property_name = Name, property_value = Value, property_mode = Mode}|T], X, Exc, State) -> case catch update_property(X, Name, both, Value, Mode) of {'EXCEPTION', E} when record(E, 'CosPropertyService_PropertyNotFound') -> define_properties_with_modes_helper(T, [{Name, Value, Mode}|X], Exc, State); {'EXCEPTION', E} -> define_properties_with_modes_helper(T, X, [#'CosPropertyService_PropertyException' {reason = remap_exception(E), failing_property_name = Name}|Exc], State); NewX -> define_properties_with_modes_helper(T, NewX, Exc, State) end.%%---------------------------------------------------------------------%%% Function : get_property_mode%% Arguments : %% Description: %% Returns : {ok, State}%%----------------------------------------------------------------------get_property_mode(_OE_THIS, State, _) when ?is_NotSetDef(State) -> corba:raise(#'NO_IMPLEMENT'{completion_status=?COMPLETED_NO});get_property_mode(_, _, "") -> corba:raise(#'CosPropertyService_InvalidPropertyName'{});get_property_mode(_OE_THIS, State, Name) -> X = lookup_table(?get_DBKey(State)), {reply, find_property(X, Name, mode), State}.%%---------------------------------------------------------------------%%% Function : get_property_modes%% Arguments : %% Description: %% Returns : {ok, State}%%----------------------------------------------------------------------get_property_modes(_OE_THIS, State, _) when ?is_NotSetDef(State) -> corba:raise(#'NO_IMPLEMENT'{completion_status=?COMPLETED_NO}); get_property_modes(_OE_THIS, State, PropertyNames) -> X = lookup_table(?get_DBKey(State)), {reply, get_property_modes_helper(PropertyNames, X, [], true), State}.get_property_modes_helper([], _, Acc, Bool) -> {Bool, Acc};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -