./ct_report/coverage/mod_caps_mnesia.COVER.html

1 -module(mod_caps_mnesia).
2 -behaviour(mod_caps_backend).
3
4 -export([init/2,
5 read/2,
6 write/3,
7 delete_node/2]).
8
9 -record(caps_features,
10 {
11 node_pair = {<<>>, <<>>} :: mod_caps:node_pair(),
12 features = [] :: mod_caps:maybe_pending_features()
13 }).
14
15 -spec init(mongooseim:host_type(), gen_mod:module_opts()) -> ok.
16 init(_HostName, _Opts) ->
17
:-(
case catch mnesia:table_info(caps_features, storage_type) of
18 {'EXIT', _} ->
19
:-(
ok;
20 disc_only_copies ->
21
:-(
ok;
22 _ ->
23
:-(
mnesia:delete_table(caps_features)
24 end,
25
:-(
mongoose_mnesia:create_table(caps_features,
26 [{disc_only_copies, [node()]},
27 {local_content, true},
28 {attributes, record_info(fields, caps_features)}]).
29
30 -spec read(mongooseim:host_type(), mod_caps:node_pair()) ->
31 {ok, mod_caps:maybe_pending_features()} | error.
32 read(_HostType, Node) ->
33
:-(
case mnesia:dirty_read({caps_features, Node}) of
34
:-(
[#caps_features{features = Features}] -> {ok, Features};
35
:-(
_ -> error
36 end.
37
38 -spec write(mongooseim:host_type(), mod_caps:node_pair(),
39 mod_caps:maybe_pending_features()) -> ok.
40 write(_HostType, Node, Features) ->
41
:-(
mnesia:dirty_write(#caps_features{node_pair = Node,
42 features = Features}),
43
:-(
ok.
44
45 -spec delete_node(mongooseim:host_type(), mod_caps:node_pair()) -> ok.
46 delete_node(_HostType, Node) ->
47
:-(
mnesia:dirty_delete(caps_features, Node),
48
:-(
ok.
Line Hits Source