aboutsummaryrefslogtreecommitdiffstats
path: root/lib/diameter/src/base/diameter_config.erl
diff options
context:
space:
mode:
authorAnders Svensson <[email protected]>2011-11-28 12:13:56 +0100
committerAnders Svensson <[email protected]>2011-12-06 18:58:14 +0100
commit8e178ed5796628bd21a5c85fdc2c864a7b06ae70 (patch)
tree464694cbc601b3b401dc23465343ee2318988e49 /lib/diameter/src/base/diameter_config.erl
parentf2a4059d06f8b76d2c1da14197f170deebd64f45 (diff)
downloadotp-8e178ed5796628bd21a5c85fdc2c864a7b06ae70.tar.gz
otp-8e178ed5796628bd21a5c85fdc2c864a7b06ae70.tar.bz2
otp-8e178ed5796628bd21a5c85fdc2c864a7b06ae70.zip
Smarter diameter_callback
The module was originally just intended as a minimal callback implementation that could be used as a template. Being able to order just a subset of callbacks (with reasonable defaults) makes for simpler code in many cases however so ready support for this can be useful.
Diffstat (limited to 'lib/diameter/src/base/diameter_config.erl')
-rw-r--r--lib/diameter/src/base/diameter_config.erl15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/diameter/src/base/diameter_config.erl b/lib/diameter/src/base/diameter_config.erl
index a6b48fe65b..9253af0de2 100644
--- a/lib/diameter/src/base/diameter_config.erl
+++ b/lib/diameter/src/base/diameter_config.erl
@@ -605,6 +605,13 @@ app_acc({application, Opts}, Acc) ->
app_acc(_, Acc) ->
Acc.
+init_mod(#diameter_callback{} = R) ->
+ init_mod([diameter_callback, R]);
+init_mod([diameter_callback, #diameter_callback{}] = L) ->
+ L;
+init_mod([diameter_callback = M | L])
+ when is_list(L) ->
+ [M, init_cb(L)];
init_mod(M)
when is_atom(M) ->
[M];
@@ -614,6 +621,14 @@ init_mod([M|_] = L)
init_mod(M) ->
?THROW({module, M}).
+init_cb(List) ->
+ Fields = record_info(fields, diameter_callback),
+ Defaults = lists:zip(Fields, tl(tuple_to_list(#diameter_callback{}))),
+ Values = [V || F <- Fields,
+ D <- [proplists:get_value(F, Defaults)],
+ V <- [proplists:get_value(F, List, D)]],
+ #diameter_callback{} = list_to_tuple([diameter_callback | Values]).
+
init_mutable(M)
when M == true;
M == false ->