From 47e0876dcea3c307fd99b5c327f3fac436e43516 Mon Sep 17 00:00:00 2001 From: Simon MacMullen Date: Thu, 2 Jun 2011 14:41:09 +0100 Subject: Move set_table_value from federation to misc --- src/rabbit_misc.erl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 53171e87..cebb888f 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -25,7 +25,7 @@ protocol_error/3, protocol_error/4, protocol_error/1]). -export([not_found/1, assert_args_equivalence/4]). -export([dirty_read/1]). --export([table_lookup/2]). +-export([table_lookup/2, set_table_value/4]). -export([r/3, r/2, r_arg/4, rs/1]). -export([enable_cover/0, report_cover/0]). -export([enable_cover/1, report_cover/1]). @@ -104,6 +104,11 @@ -spec(table_lookup/2 :: (rabbit_framing:amqp_table(), binary()) -> 'undefined' | {rabbit_framing:amqp_field_type(), any()}). +-spec(set_table_value/4 :: + (rabbit_framing:amqp_table(), binary(), + rabbit_framing:amqp_field_type(), rabbit_framing:amqp_value()) + -> rabbit_framing:amqp_table()). + -spec(r/2 :: (rabbit_types:vhost(), K) -> rabbit_types:r3(rabbit_types:vhost(), K, '_') when is_subtype(K, atom())). @@ -268,6 +273,10 @@ table_lookup(Table, Key) -> false -> undefined end. +set_table_value(Table, Key, Type, Value) -> + sort_field_table( + lists:keystore(Key, 1, Table, {Key, Type, Value})). + r(#resource{virtual_host = VHostPath}, Kind, Name) when is_binary(Name) -> #resource{virtual_host = VHostPath, kind = Kind, name = Name}; -- cgit v1.2.1 From ac0245f94d2c6977014279c77ae9673dfb222bf5 Mon Sep 17 00:00:00 2001 From: Simon MacMullen Date: Thu, 2 Jun 2011 15:00:44 +0100 Subject: Move pget from federation / mgmt to misc. --- src/rabbit_misc.erl | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index cebb888f..b6b97f6d 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -56,6 +56,7 @@ -export([const_ok/0, const/1]). -export([ntoa/1, ntoab/1]). -export([is_process_alive/1]). +-export([pget/2, pget/3, pget_or_die/2]). %%---------------------------------------------------------------------------- @@ -201,6 +202,9 @@ -spec(ntoa/1 :: (inet:ip_address()) -> string()). -spec(ntoab/1 :: (inet:ip_address()) -> string()). -spec(is_process_alive/1 :: (pid()) -> boolean()). +-spec(pget/2 :: (term(), [term()]) -> term()). +-spec(pget/3 :: (term(), [term()], term()) -> term()). +-spec(pget_or_die/2 :: (term(), [term()]) -> term() | no_return()). -endif. @@ -906,3 +910,12 @@ is_process_alive(Pid) -> true -> true; _ -> false end. + +pget(K, P) -> proplists:get_value(K, P). +pget(K, P, D) -> proplists:get_value(K, P, D). + +pget_or_die(K, P) -> + case proplists:get_value(K, P) of + undefined -> exit({error, key_missing, K}); + V -> V + end. -- cgit v1.2.1