-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3556 from esl/mu-stream-man-backend
Add mod_stream_management_backend
- Loading branch information
Showing
10 changed files
with
369 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/stream_management/mod_stream_management_backend.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
-module(mod_stream_management_backend). | ||
-export([init/2, | ||
register_smid/3, | ||
unregister_smid/2, | ||
get_sid/2]). | ||
|
||
-export([read_stale_h/2, | ||
write_stale_h/3, | ||
delete_stale_h/2]). | ||
|
||
-define(MAIN_MODULE, mod_stream_management). | ||
|
||
%% ---------------------------------------------------------------------- | ||
%% Callbacks | ||
%% (exactly the same as specs in this module) | ||
|
||
-callback init(HostType, Opts) -> ok when | ||
HostType :: mongooseim:host_type(), | ||
Opts :: gen_mod:module_opts(). | ||
|
||
-callback register_smid(HostType, SMID, SID) -> | ||
ok | {error, term()} when | ||
HostType :: mongooseim:host_type(), | ||
SMID :: mod_stream_management:smid(), | ||
SID :: ejabberd_sm:sid(). | ||
|
||
-callback unregister_smid(mongooseim:host_type(), ejabberd_sm:sid()) -> | ||
{ok, SMID :: mod_stream_management:smid()} | {error, smid_not_found}. | ||
|
||
-callback get_sid(mongooseim:host_type(), mod_stream_management:smid()) -> | ||
{sid, ejabberd_sm:sid()} | {error, smid_not_found}. | ||
|
||
%% stale_h functions | ||
|
||
-callback read_stale_h(HostType, SMID) -> | ||
{stale_h, non_neg_integer()} | {error, smid_not_found} when | ||
HostType :: mongooseim:host_type(), | ||
SMID :: mod_stream_management:smid(). | ||
|
||
-callback write_stale_h(HostType, SMID, H) -> ok | {error, any()} when | ||
HostType :: mongooseim:host_type(), | ||
SMID :: mod_stream_management:smid(), | ||
H :: non_neg_integer(). | ||
|
||
-callback delete_stale_h(HostType, SMID) -> ok | {error, any()} when | ||
HostType :: mongooseim:host_type(), | ||
SMID :: mod_stream_management:smid(). | ||
|
||
%% ---------------------------------------------------------------------- | ||
%% API Functions | ||
|
||
-spec init(HostType, Opts) -> ok when | ||
HostType :: mongooseim:host_type(), | ||
Opts :: gen_mod:module_opts(). | ||
init(HostType, Opts) -> | ||
TrackedFuns = [], | ||
mongoose_backend:init(HostType, ?MAIN_MODULE, TrackedFuns, Opts), | ||
Args = [HostType, Opts], | ||
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). | ||
|
||
-spec register_smid(HostType, SMID, SID) -> | ||
ok | {error, term()} when | ||
HostType :: mongooseim:host_type(), | ||
SMID :: mod_stream_management:smid(), | ||
SID :: ejabberd_sm:sid(). | ||
register_smid(HostType, SMID, SID) -> | ||
Args = [HostType, SMID, SID], | ||
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). | ||
|
||
-spec unregister_smid(mongooseim:host_type(), ejabberd_sm:sid()) -> | ||
{ok, SMID :: mod_stream_management:smid()} | {error, smid_not_found}. | ||
unregister_smid(HostType, SID) -> | ||
Args = [HostType, SID], | ||
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). | ||
|
||
-spec get_sid(mongooseim:host_type(), mod_stream_management:smid()) -> | ||
{sid, ejabberd_sm:sid()} | {error, smid_not_found}. | ||
get_sid(HostType, SMID) -> | ||
Args = [HostType, SMID], | ||
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). | ||
|
||
%% stale_h functions | ||
|
||
-spec read_stale_h(HostType, SMID) -> | ||
{stale_h, non_neg_integer()} | {error, smid_not_found} when | ||
HostType :: mongooseim:host_type(), | ||
SMID :: mod_stream_management:smid(). | ||
read_stale_h(HostType, SMID) -> | ||
Args = [HostType, SMID], | ||
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). | ||
|
||
-spec write_stale_h(HostType, SMID, H) -> ok | {error, any()} when | ||
HostType :: mongooseim:host_type(), | ||
SMID :: mod_stream_management:smid(), | ||
H :: non_neg_integer(). | ||
write_stale_h(HostType, SMID, H) -> | ||
Args = [HostType, SMID, H], | ||
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). | ||
|
||
-spec delete_stale_h(HostType, SMID) -> ok | {error, any()} when | ||
HostType :: mongooseim:host_type(), | ||
SMID :: mod_stream_management:smid(). | ||
delete_stale_h(HostType, SMID) -> | ||
Args = [HostType, SMID], | ||
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
Oops, something went wrong.