./ct_report/coverage/mod_offline_backend.COVER.html

1 %% Just a proxy interface module between the main mod_offline module and
2 %% the backend modules (i.e. mod_offline_mnesia, mod_offline_rdbms...).
3 -module(mod_offline_backend).
4
5 -export([init/2,
6 pop_messages/2,
7 fetch_messages/2,
8 write_messages/4,
9 count_offline_messages/4,
10 remove_expired_messages/2,
11 remove_old_messages/3,
12 remove_user/3,
13 remove_domain/2]).
14
15 -define(MAIN_MODULE, mod_offline).
16
17 -callback init(mongooseim:host_type(), gen_mod:module_opts()) -> ok.
18
19 -callback pop_messages(mongooseim:host_type(), jid:jid()) ->
20 {ok, [mod_offline:msg()]} | {error, any()}.
21
22 -callback fetch_messages(mongooseim:host_type(), jid:jid()) ->
23 {ok, [mod_offline:msg()]} | {error, any()}.
24
25 -callback write_messages(mongooseim:host_type(), jid:luser(), jid:lserver(), [mod_offline:msg()]) ->
26 ok | {error, any()}.
27
28 -callback count_offline_messages(mongooseim:host_type(), jid:luser(), jid:lserver(), Limit :: mod_offline:msg_count()) ->
29 mod_offline:msg_count().
30
31 -callback remove_expired_messages(mongooseim:host_type(), jid:lserver()) ->
32 {ok, mod_offline:msg_count()} | {error, any()}.
33
34 -callback remove_old_messages(mongooseim:host_type(), jid:lserver(), mod_offline:timestamp()) ->
35 {ok, mod_offline:msg_count()} | {error, any()}.
36
37 -callback remove_user(mongooseim:host_type(), jid:luser(), jid:lserver()) -> ok.
38
39 -callback remove_domain(mongooseim:host_type(), jid:lserver()) -> ok.
40
41 -optional_callbacks([remove_domain/2]).
42
43 -spec init(mongooseim:host_type(), gen_mod:module_opts()) -> ok.
44 init(HostType, Opts) ->
45 24 mongoose_backend:init(HostType, ?MAIN_MODULE, [pop_messages, write_messages], Opts),
46 24 Args = [HostType, Opts],
47 24 mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
48
49 -spec pop_messages(mongooseim:host_type(), jid:jid()) ->
50 {ok, [mod_offline:msg()]} | {error, any()}.
51 pop_messages(HostType, UserJID) ->
52 721 Args = [HostType, UserJID],
53 721 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
54
55 -spec fetch_messages(mongooseim:host_type(), jid:jid()) ->
56 {ok, [mod_offline:msg()]} | {error, any()}.
57 fetch_messages(HostType, UserJID) ->
58 38 Args = [HostType, UserJID],
59 38 mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
60
61 -spec write_messages(mongooseim:host_type(), jid:luser(), jid:lserver(), [mod_offline:msg()]) ->
62 ok | {error, any()}.
63 write_messages(HostType, LUser, LServer, Msgs) ->
64 157 Args = [HostType, LUser, LServer, Msgs],
65 157 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
66
67 -spec count_offline_messages(mongooseim:host_type(), jid:luser(), jid:lserver(), Limit :: mod_offline:msg_count()) ->
68 mod_offline:msg_count().
69 count_offline_messages(HostType, LUser, LServer, Limit) ->
70 164 Args = [HostType, LUser, LServer, Limit],
71 164 mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
72
73 -spec remove_expired_messages(mongooseim:host_type(), jid:lserver()) ->
74 {ok, mod_offline:msg_count()} | {error, any()}.
75 remove_expired_messages(HostType, LServer) ->
76 9 Args = [HostType, LServer],
77 9 mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
78
79 -spec remove_old_messages(mongooseim:host_type(), jid:lserver(), mod_offline:timestamp()) ->
80 {ok, mod_offline:msg_count()} | {error, any()}.
81 remove_old_messages(HostType, LServer, Timestamp) ->
82 9 Args = [HostType, LServer, Timestamp],
83 9 mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
84
85 -spec remove_user(mongooseim:host_type(), jid:luser(), jid:lserver()) -> ok.
86 remove_user(HostType, LUser, LServer) ->
87 436 Args = [HostType, LUser, LServer],
88 436 mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
89
90 -spec remove_domain(mongooseim:host_type(), jid:lserver()) -> ok.
91 remove_domain(HostType, LServer) ->
92 1 Args = [HostType, LServer],
93 1 case mongoose_backend:is_exported(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, 2) of
94 true ->
95 1 mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args);
96 false ->
97
:-(
ok
98 end.
Line Hits Source