1 |
|
|
2 |
|
-module(mongoose_iq_worker). |
3 |
|
-behaviour(gen_server). |
4 |
|
|
5 |
|
%% API |
6 |
|
-export([start/0, start_link/0, process_iq/6, stop/1]). |
7 |
|
|
8 |
|
%% gen_server callbacks |
9 |
|
-export([init/1, handle_call/3, handle_cast/2]). |
10 |
|
|
11 |
|
-ignore_xref([start_link/0]). |
12 |
|
|
13 |
|
%%-------------------------------------------------------------------- |
14 |
|
%% API |
15 |
|
%%-------------------------------------------------------------------- |
16 |
|
-spec start() -> {ok,pid()}. |
17 |
|
start() -> |
18 |
4718 |
supervisor:start_child(ejabberd_iq_sup, []). |
19 |
|
|
20 |
|
-spec start_link() -> |
21 |
|
'ignore' | {'error', _} | {'ok', pid()}. |
22 |
|
start_link() -> |
23 |
4718 |
gen_server:start_link(?MODULE, ok, []). |
24 |
|
|
25 |
|
-spec process_iq(Pid :: pid(), |
26 |
|
IQHandler :: mongoose_iq_handler:t(), |
27 |
|
Acc :: mongoose_acc:t(), |
28 |
|
From :: jid:jid(), |
29 |
|
To :: jid:jid(), |
30 |
|
IQ :: jlib:iq()) -> ok. |
31 |
|
process_iq(Pid, IQHandler, Acc, From, To, IQ) -> |
32 |
574 |
gen_server:cast(Pid, {process_iq, IQHandler, Acc, From, To, IQ}). |
33 |
|
|
34 |
|
-spec stop(Pid :: pid()) -> ok. |
35 |
|
stop(Pid) -> |
36 |
3886 |
gen_server:cast(Pid, stop). |
37 |
|
%%-------------------------------------------------------------------- |
38 |
|
%% gen_server callbacks |
39 |
|
%%-------------------------------------------------------------------- |
40 |
|
|
41 |
|
%% @doc Initiates the server |
42 |
|
-spec init(_) -> {ok, ok}. |
43 |
|
init(_) -> |
44 |
|
%% no need for a state |
45 |
4718 |
{ok, ok}. |
46 |
|
|
47 |
|
handle_call(stop, _From, State) -> |
48 |
:-( |
Reply = ok, |
49 |
:-( |
{stop, normal, Reply, State}; |
50 |
|
handle_call(_Msg, _From, State) -> |
51 |
:-( |
{reply, not_implemented, State}. |
52 |
|
|
53 |
|
handle_cast({process_iq, IQHandler, Acc, From, To, IQ}, State) -> |
54 |
574 |
mongoose_iq_handler:execute_handler(IQHandler, Acc, From, To, IQ), |
55 |
574 |
{noreply, State}; |
56 |
|
handle_cast(_Msg, State) -> |
57 |
3886 |
{noreply, State}. |