Skip to content

Commit

Permalink
added few functions to examine current tdlib gen_server state
Browse files Browse the repository at this point in the history
  • Loading branch information
lattenwald committed Sep 24, 2018
1 parent 144e432 commit 536f069
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
26 changes: 25 additions & 1 deletion doc/tdlib.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ __Behaviours:__ [`gen_server`](gen_server.md).
## Function Index ##


<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#auth_code-2">auth_code/2</a></td><td>Send authentication code.</td></tr><tr><td valign="top"><a href="#auth_password-2">auth_password/2</a></td><td>Send password.</td></tr><tr><td valign="top"><a href="#config-2">config/2</a></td><td>Send tdlib configuration.</td></tr><tr><td valign="top"><a href="#execute-2">execute/2</a></td><td>Execute synchronous tdlib request.</td></tr><tr><td valign="top"><a href="#phone_number-2">phone_number/2</a></td><td>Send phone number.</td></tr><tr><td valign="top"><a href="#register_handler-2">register_handler/2</a></td><td>Add handler to tdlib instance.</td></tr><tr><td valign="top"><a href="#send-2">send/2</a></td><td>Send tdlib request.</td></tr><tr><td valign="top"><a href="#set_log_file_path-0">set_log_file_path/0</a></td><td>Set log logging behaviour to default.</td></tr><tr><td valign="top"><a href="#set_log_file_path-1">set_log_file_path/1</a></td><td>Set log file path.</td></tr><tr><td valign="top"><a href="#set_log_max_file_size-1">set_log_max_file_size/1</a></td><td>Set max log file size.</td></tr><tr><td valign="top"><a href="#set_log_verbosity_level-1">set_log_verbosity_level/1</a></td><td>Set tdlib log verbosity level.</td></tr><tr><td valign="top"><a href="#start_link-0">start_link/0</a></td><td>Start new tdlib instance.</td></tr><tr><td valign="top"><a href="#start_link-2">start_link/2</a></td><td>Start new tdlib instance, register it and send config when ready.</td></tr></table>
<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#auth_code-2">auth_code/2</a></td><td>Send authentication code.</td></tr><tr><td valign="top"><a href="#auth_password-2">auth_password/2</a></td><td>Send password.</td></tr><tr><td valign="top"><a href="#config-2">config/2</a></td><td>Send tdlib configuration.</td></tr><tr><td valign="top"><a href="#execute-2">execute/2</a></td><td>Execute synchronous tdlib request.</td></tr><tr><td valign="top"><a href="#get_auth_state-1">get_auth_state/1</a></td><td>Get current auth state of tdlib.</td></tr><tr><td valign="top"><a href="#get_config-1">get_config/1</a></td><td>Get tdlib configuration.</td></tr><tr><td valign="top"><a href="#get_handlers-1">get_handlers/1</a></td><td>Get list of current handlers.</td></tr><tr><td valign="top"><a href="#phone_number-2">phone_number/2</a></td><td>Send phone number.</td></tr><tr><td valign="top"><a href="#register_handler-2">register_handler/2</a></td><td>Add handler to tdlib instance.</td></tr><tr><td valign="top"><a href="#send-2">send/2</a></td><td>Send tdlib request.</td></tr><tr><td valign="top"><a href="#set_log_file_path-0">set_log_file_path/0</a></td><td>Set log logging behaviour to default.</td></tr><tr><td valign="top"><a href="#set_log_file_path-1">set_log_file_path/1</a></td><td>Set log file path.</td></tr><tr><td valign="top"><a href="#set_log_max_file_size-1">set_log_max_file_size/1</a></td><td>Set max log file size.</td></tr><tr><td valign="top"><a href="#set_log_verbosity_level-1">set_log_verbosity_level/1</a></td><td>Set tdlib log verbosity level.</td></tr><tr><td valign="top"><a href="#start_link-0">start_link/0</a></td><td>Start new tdlib instance.</td></tr><tr><td valign="top"><a href="#start_link-2">start_link/2</a></td><td>Start new tdlib instance, register it and send config when ready.</td></tr></table>


<a name="functions"></a>
Expand Down Expand Up @@ -50,6 +50,30 @@ Send tdlib configuration.

Execute synchronous tdlib request.

<a name="get_auth_state-1"></a>

### get_auth_state/1 ###

`get_auth_state(Pid) -> any()`

Get current auth state of tdlib.

<a name="get_config-1"></a>

### get_config/1 ###

`get_config(Pid) -> any()`

Get tdlib configuration.

<a name="get_handlers-1"></a>

### get_handlers/1 ###

`get_handlers(Pid) -> any()`

Get list of current handlers.

<a name="phone_number-2"></a>

### phone_number/2 ###
Expand Down
36 changes: 35 additions & 1 deletion src/tdlib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
-export([register_handler/2, config/2, send/2, execute/2, method/2]).
-export([phone_number/2, auth_code/2, auth_password/2]).
-export([set_log_verbosity_level/1, set_log_file_path/0, set_log_file_path/1, set_log_max_file_size/1]).
-export([get_handlers/1, get_auth_state/1, get_config/1]).

-define(RECEIVE_TIMEOUT, 5.0).

Expand Down Expand Up @@ -199,6 +200,30 @@ set_log_verbosity_level(Level) ->
set_log_max_file_size(Size) ->
tdlib_nif:set_log_max_file_size(Size).

%%====================================================================
%% @doc Get list of current handlers.
%%
%% @param Pid tdlib gen_server pid
%%====================================================================
get_handlers(Pid) ->
gen_server:call(Pid, get_handlers).

%%====================================================================
%% @doc Get current auth state of tdlib.
%%
%% @param Pid tdlib gen_server pid
%%====================================================================
get_auth_state(Pid) ->
gen_server:call(Pid, get_auth_state).

%%====================================================================
%% @doc Get tdlib configuration.
%%
%% @param Pid tdlib gen_server pid
%%====================================================================
get_config(Pid) ->
gen_server:call(Pid, get_config).

%%====================================================================
%% callbacks
%%====================================================================
Expand Down Expand Up @@ -274,7 +299,7 @@ handle_call({config, Cfg}, _From, State=#state{auth_state = <<"authorizationStat

send(self(), Request),

{reply, Cfg, State};
{reply, Cfg, State#state{config = Config}};

handle_call({execute, Data}, _From, State=#state{tdlib = Tdlib}) ->
Resp = tdlib_nif:execute(Tdlib, Data),
Expand All @@ -284,6 +309,15 @@ handle_call({register_handler, Handler}, _From, State=#state{handlers = Handlers
NewHandlers = sets:add_element(Handler, Handlers),
{reply, ok, State#state{handlers = NewHandlers}};

handle_call(get_handlers, _From, State=#state{handlers = Handlers}) ->
{reply, Handlers, State};

handle_call(get_auth_state, _From, State=#state{auth_state = AuthState}) ->
{reply, AuthState, State};

handle_call(get_config, _From, State=#state{config = Config}) ->
{reply, Config, State};

handle_call(_Msg, _From, State) ->
{reply, ok, State}.

Expand Down

0 comments on commit 536f069

Please sign in to comment.