1 |
|
-module(mod_stream_management_backend). |
2 |
|
-export([init/2, |
3 |
|
stop/1, |
4 |
|
register_smid/3, |
5 |
|
unregister_smid/2, |
6 |
|
get_sid/2]). |
7 |
|
|
8 |
|
-export([read_stale_h/2, |
9 |
|
write_stale_h/3, |
10 |
|
delete_stale_h/2]). |
11 |
|
|
12 |
|
-define(MAIN_MODULE, mod_stream_management). |
13 |
|
|
14 |
|
%% ---------------------------------------------------------------------- |
15 |
|
%% Callbacks |
16 |
|
%% (exactly the same as specs in this module) |
17 |
|
|
18 |
|
-callback init(HostType, Opts) -> ok when |
19 |
|
HostType :: mongooseim:host_type(), |
20 |
|
Opts :: gen_mod:module_opts(). |
21 |
|
|
22 |
|
-callback stop(HostType) -> ok when |
23 |
|
HostType :: mongooseim:host_type(). |
24 |
|
|
25 |
|
-callback register_smid(HostType, SMID, SID) -> |
26 |
|
ok | {error, term()} when |
27 |
|
HostType :: mongooseim:host_type(), |
28 |
|
SMID :: mod_stream_management:smid(), |
29 |
|
SID :: ejabberd_sm:sid(). |
30 |
|
|
31 |
|
-callback unregister_smid(mongooseim:host_type(), ejabberd_sm:sid()) -> |
32 |
|
{ok, SMID :: mod_stream_management:smid()} | {error, smid_not_found}. |
33 |
|
|
34 |
|
-callback get_sid(mongooseim:host_type(), mod_stream_management:smid()) -> |
35 |
|
{sid, ejabberd_sm:sid()} | {error, smid_not_found}. |
36 |
|
|
37 |
|
%% stale_h functions |
38 |
|
|
39 |
|
-callback read_stale_h(HostType, SMID) -> |
40 |
|
{stale_h, non_neg_integer()} | {error, smid_not_found} when |
41 |
|
HostType :: mongooseim:host_type(), |
42 |
|
SMID :: mod_stream_management:smid(). |
43 |
|
|
44 |
|
-callback write_stale_h(HostType, SMID, H) -> ok | {error, any()} when |
45 |
|
HostType :: mongooseim:host_type(), |
46 |
|
SMID :: mod_stream_management:smid(), |
47 |
|
H :: non_neg_integer(). |
48 |
|
|
49 |
|
-callback delete_stale_h(HostType, SMID) -> ok | {error, any()} when |
50 |
|
HostType :: mongooseim:host_type(), |
51 |
|
SMID :: mod_stream_management:smid(). |
52 |
|
|
53 |
|
%% ---------------------------------------------------------------------- |
54 |
|
%% API Functions |
55 |
|
|
56 |
|
-spec init(HostType, Opts) -> ok when |
57 |
|
HostType :: mongooseim:host_type(), |
58 |
|
Opts :: gen_mod:module_opts(). |
59 |
|
init(HostType, Opts) -> |
60 |
487 |
TrackedFuns = [], |
61 |
487 |
mongoose_backend:init(HostType, ?MAIN_MODULE, TrackedFuns, Opts), |
62 |
487 |
Args = [HostType, Opts], |
63 |
487 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
64 |
|
|
65 |
|
-spec stop(HostType :: mongooseim:host_type()) -> ok. |
66 |
|
stop(HostType) -> |
67 |
487 |
Args = [HostType], |
68 |
487 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
69 |
|
|
70 |
|
-spec register_smid(HostType, SMID, SID) -> |
71 |
|
ok | {error, term()} when |
72 |
|
HostType :: mongooseim:host_type(), |
73 |
|
SMID :: mod_stream_management:smid(), |
74 |
|
SID :: ejabberd_sm:sid(). |
75 |
|
register_smid(HostType, SMID, SID) -> |
76 |
57 |
Args = [HostType, SMID, SID], |
77 |
57 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
78 |
|
|
79 |
|
-spec unregister_smid(mongooseim:host_type(), ejabberd_sm:sid()) -> |
80 |
|
{ok, SMID :: mod_stream_management:smid()} | {error, smid_not_found}. |
81 |
|
unregister_smid(HostType, SID) -> |
82 |
149 |
Args = [HostType, SID], |
83 |
149 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
84 |
|
|
85 |
|
-spec get_sid(mongooseim:host_type(), mod_stream_management:smid()) -> |
86 |
|
{sid, ejabberd_sm:sid()} | {error, smid_not_found}. |
87 |
|
get_sid(HostType, SMID) -> |
88 |
24 |
Args = [HostType, SMID], |
89 |
24 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
90 |
|
|
91 |
|
%% stale_h functions |
92 |
|
|
93 |
|
-spec read_stale_h(HostType, SMID) -> |
94 |
|
{stale_h, non_neg_integer()} | {error, smid_not_found} when |
95 |
|
HostType :: mongooseim:host_type(), |
96 |
|
SMID :: mod_stream_management:smid(). |
97 |
|
read_stale_h(HostType, SMID) -> |
98 |
25 |
Args = [HostType, SMID], |
99 |
25 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
100 |
|
|
101 |
|
-spec write_stale_h(HostType, SMID, H) -> ok | {error, any()} when |
102 |
|
HostType :: mongooseim:host_type(), |
103 |
|
SMID :: mod_stream_management:smid(), |
104 |
|
H :: non_neg_integer(). |
105 |
|
write_stale_h(HostType, SMID, H) -> |
106 |
8 |
Args = [HostType, SMID, H], |
107 |
8 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
108 |
|
|
109 |
|
-spec delete_stale_h(HostType, SMID) -> ok | {error, any()} when |
110 |
|
HostType :: mongooseim:host_type(), |
111 |
|
SMID :: mod_stream_management:smid(). |
112 |
|
delete_stale_h(HostType, SMID) -> |
113 |
:-( |
Args = [HostType, SMID], |
114 |
:-( |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |