Skip to content

Commit

Permalink
KAZOO-5188: ensure all exported functions are spec-ed (2600hz#2819)
Browse files Browse the repository at this point in the history
* specs: add missing specs to exported functions in core/

* specs: use kz_util:put_callid

* specs: add missing specs to exported functions in applications/ part un

* specs: part deux

* specs: part trois

* specs: part quatre

* specs: part quatre

* specs: part six

* specs: part sept

* specs: part huit

* specs: part huit et demi

* specs: fix compile error

* specs: make fmt

* specs: fix some Dialyzer issue

* specs: part huit trois quarts

* specs: part neuf

* specs: part dix

* specs: add compilation flag +warn_missing_spec

* specs: add last missing specs

* specs: make fmt

* specs: fix some Dialyzer errors

* specs: disable new compilation flag when compiling in test mode

* specs: rebase artifacts

* KAZOO-5188: leftovers

* KAZOO-5188: some cleansing

* KAZOO-5188: fix record def

* KAZOO-5188: fix all acdc_agent_fsm Dialyzer warnings

* KAZOO-5188: cleansing

* KAZOO-5188: fix all acdc_queue_fsm Dialyzer warnings

* KAZOO-5188: fix last warnings

* KAZOO-5188: really fix last warnings
  • Loading branch information
fenollp authored and lazedo committed Nov 20, 2016
1 parent fb85977 commit e174397
Show file tree
Hide file tree
Showing 251 changed files with 1,360 additions and 658 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ clean-kazoo: ACTION = clean
clean-kazoo: $(KAZOODIRS)

compile-test: ACTION = compile-test
compile-test: ERLC_OPTS += +nowarn_missing_spec
compile-test: deps $(KAZOODIRS)

eunit: ACTION = eunit
Expand All @@ -40,6 +41,7 @@ proper: $(KAZOODIRS)

test: ACTION = test
test: ERLC_OPTS += -DPROPER
test: ERLC_OPTS += +nowarn_missing_spec
test: $(KAZOODIRS)

coverage-report:
Expand Down
89 changes: 54 additions & 35 deletions applications/acdc/src/acdc_agent_fsm.erl

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions applications/acdc/src/acdc_agent_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ handle_call_event(Category, <<"CHANNEL_DESTROY">> = Name, FSM, JObj, Props) ->
handle_call_event(Category, Name, FSM, JObj, _) ->
acdc_agent_fsm:call_event(FSM, Category, Name, JObj).

-spec handle_new_channel(kz_json:object(), ne_binary()) -> 'ok'.
handle_new_channel(JObj, AccountId) ->
'true' = kapi_call:event_v(JObj),
_ = kz_util:put_callid(JObj),
Expand All @@ -249,6 +250,7 @@ handle_new_channel_acct(JObj, AccountId) ->
_ -> lager:debug("invalid call direction for call ~s", [CallId])
end.

-spec handle_originate_resp(kz_json:object(), kz_proplist()) -> 'ok'.
handle_originate_resp(JObj, Props) ->
case kz_json:get_value(<<"Event-Name">>, JObj) of
<<"originate_resp">> ->
Expand Down Expand Up @@ -287,9 +289,9 @@ handle_agent_message(JObj, Props, <<"connect_timeout">>) ->
handle_agent_message(_, _, _EvtName) ->
lager:debug("not handling agent event ~s", [_EvtName]).

-spec handle_config_change(kz_json:object(), kz_proplist()) -> 'ok'.
handle_config_change(JObj, _Props) ->
'true' = kapi_conf:doc_update_v(JObj),

handle_change(JObj, kz_json:get_value(<<"Type">>, JObj)).

-spec handle_change(kz_json:object(), ne_binary()) -> 'ok'.
Expand Down Expand Up @@ -383,11 +385,14 @@ handle_agent_change(_, AccountId, AgentId, ?DOC_DELETED) ->
acdc_agent_stats:agent_logged_out(AccountId, AgentId)
end.

-spec handle_presence_probe(kz_json:object(), kz_proplist()) -> 'ok'.
handle_presence_probe(JObj, _Props) ->
'true' = kapi_presence:probe_v(JObj),
Realm = kz_json:get_value(<<"Realm">>, JObj),
case kapps_util:get_account_by_realm(Realm) of
{'ok', AcctDb} -> maybe_respond_to_presence_probe(JObj, kz_util:format_account_id(AcctDb, 'raw'));
{'ok', AcctDb} ->
AccountId = kz_util:format_account_id(AcctDb, 'raw'),
maybe_respond_to_presence_probe(JObj, AccountId);
_ -> lager:debug("ignoring presence probe from realm ~s", [Realm])
end.

Expand Down Expand Up @@ -415,6 +420,7 @@ send_probe(JObj, State) ->
],
kapi_presence:publish_update(PresenceUpdate).

-spec handle_destroy(kz_json:object(), kz_proplist()) -> 'ok'.
handle_destroy(JObj, Props) ->
'true' = kapi_call:event_v(JObj),
FSM = props:get_value('fsm_pid', Props),
Expand Down
36 changes: 34 additions & 2 deletions applications/acdc/src/acdc_agent_listener.erl
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@
%% @doc Starts the server
%%--------------------------------------------------------------------
-spec start_link(pid(), kz_json:object()) -> startlink_ret().
-spec start_link(pid(), kz_json:object(), ne_binary(), ne_binary(), ne_binaries()) -> startlink_ret().
-spec start_link(pid(), kapps_call:call(), ne_binary()) -> startlink_ret().
start_link(Supervisor, AgentJObj) ->
AgentId = kz_doc:id(AgentJObj),
AcctId = account_id(AgentJObj),
Expand Down Expand Up @@ -197,18 +199,22 @@ start_link(Supervisor, ThiefCall, QueueId) ->
,[Supervisor, ThiefCall, [QueueId]]
).

-spec stop(pid()) -> 'ok'.
stop(Srv) -> gen_listener:cast(Srv, {'stop_agent', self()}).

-spec member_connect_resp(pid(), kz_json:object()) -> 'ok'.
member_connect_resp(Srv, ReqJObj) ->
gen_listener:cast(Srv, {'member_connect_resp', ReqJObj}).

-spec member_connect_retry(pid(), kz_json:object()) -> 'ok'.
member_connect_retry(Srv, WinJObj) ->
gen_listener:cast(Srv, {'member_connect_retry', WinJObj}).

-spec agent_timeout(pid()) -> 'ok'.
agent_timeout(Srv) -> gen_listener:cast(Srv, 'agent_timeout').

-spec member_connect_accepted(pid()) -> 'ok'.
-spec member_connect_accepted(pid(), ne_binary()) -> 'ok'.
member_connect_accepted(Srv) ->
gen_listener:cast(Srv, {'member_connect_accepted'}).
member_connect_accepted(Srv, ACallId) ->
Expand All @@ -224,6 +230,7 @@ hangup_call(Srv) ->
bridge_to_member(Srv, Call, WinJObj, EPs, CDRUrl, RecordingUrl) ->
gen_listener:cast(Srv, {'bridge_to_member', Call, WinJObj, EPs, CDRUrl, RecordingUrl}).

-spec monitor_call(pid(), kapps_call:call(), api_binary(), api_binary()) -> 'ok'.
monitor_call(Srv, Call, CDRUrl, RecordingUrl) ->
gen_listener:cast(Srv, {'monitor_call', Call, CDRUrl, RecordingUrl}).

Expand All @@ -239,76 +246,97 @@ unbind_from_events(Srv, CallId) ->
rebind_events(Srv, OldCallId, NewCallId) ->
gen_listener:cast(Srv, {'rebind_events', OldCallId, NewCallId}).

-spec originate_execute(pid(), kz_json:object()) -> 'ok'.
originate_execute(Srv, JObj) ->
gen_listener:cast(Srv, {'originate_execute', JObj}).

-spec originate_uuid(pid(), ne_binary(), ne_binary()) -> 'ok'.
originate_uuid(Srv, UUID, CtlQ) ->
gen_listener:cast(Srv, {'originate_uuid', UUID, CtlQ}).

-spec outbound_call(pid(), ne_binary()) -> 'ok'.
outbound_call(Srv, CallId) ->
gen_listener:cast(Srv, {'outbound_call', CallId}).

-spec send_agent_available(pid()) -> 'ok'.
send_agent_available(Srv) ->
gen_listener:cast(Srv, 'send_agent_available').

-spec send_sync_req(pid()) -> 'ok'.
send_sync_req(Srv) -> gen_listener:cast(Srv, {'send_sync_req'}).

-spec send_sync_resp(pid(), text(), kz_json:object()) -> 'ok'.
-spec send_sync_resp(pid(), text(), kz_json:object(), kz_proplist()) -> 'ok'.
send_sync_resp(Srv, Status, ReqJObj) -> send_sync_resp(Srv, Status, ReqJObj, []).
send_sync_resp(Srv, Status, ReqJObj, Options) ->
gen_listener:cast(Srv, {'send_sync_resp', Status, ReqJObj, Options}).

-spec config(pid()) -> config().
config(Srv) -> gen_listener:call(Srv, 'config').

-spec refresh_config(pid(), api_ne_binaries()) -> 'ok'.
refresh_config(_, 'undefined') -> 'ok';
refresh_config(Srv, Qs) -> gen_listener:cast(Srv, {'refresh_config', Qs}).

-spec agent_info(pid(), kz_json:path()) -> kz_json:api_json_term().
agent_info(Srv, Field) -> gen_listener:call(Srv, {'agent_info', Field}).

-spec send_status_resume(pid()) -> 'ok'.
send_status_resume(Srv) ->
gen_listener:cast(Srv, {'send_status_update', 'resume'}).

-spec add_acdc_queue(pid(), ne_binary()) -> 'ok'.
add_acdc_queue(Srv, Q) ->
gen_listener:cast(Srv, {'add_acdc_queue', Q}).

-spec rm_acdc_queue(pid(), ne_binary()) -> 'ok'.
rm_acdc_queue(Srv, Q) ->
gen_listener:cast(Srv, {'rm_acdc_queue', Q}).

-spec call_status_req(pid()) -> 'ok'.
-spec call_status_req(pid(), ne_binary()) -> 'ok'.
call_status_req(Srv) ->
gen_listener:cast(Srv, 'call_status_req').
call_status_req(Srv, CallId) ->
gen_listener:cast(Srv, {'call_status_req', CallId}).

-spec fsm_started(pid(), pid()) -> 'ok'.
fsm_started(Srv, FSM) ->
gen_listener:cast(Srv, {'fsm_started', FSM}).

-spec add_endpoint_bindings(pid(), ne_binary(), api_ne_binary()) -> 'ok'.
add_endpoint_bindings(_Srv, _Realm, 'undefined') ->
lager:debug("ignoring adding endpoint bindings for undefined user @ ~s", [_Realm]);
add_endpoint_bindings(Srv, Realm, User) ->
lager:debug("adding route bindings to ~p for endpoint ~s@~s", [Srv, User, Realm]),
gen_listener:add_binding(Srv, 'route', [{'realm', Realm}
,{'user', User}
]).

-spec remove_endpoint_bindings(pid(), ne_binary(), ne_binary()) -> 'ok'.
remove_endpoint_bindings(Srv, Realm, User) ->
lager:debug("removing route bindings to ~p for endpoint ~s@~s", [Srv, User, Realm]),
gen_listener:rm_binding(Srv, 'route', [{'realm', Realm}
,{'user', User}
]).

-spec remove_cdr_urls(pid(), ne_binary()) -> 'ok'.
remove_cdr_urls(Srv, CallId) -> gen_listener:cast(Srv, {'remove_cdr_urls', CallId}).

-spec logout_agent(pid()) -> 'ok'.
logout_agent(Srv) -> gen_listener:cast(Srv, 'logout_agent').

-spec maybe_update_presence_id(pid(), api_ne_binary()) -> 'ok'.
maybe_update_presence_id(_Srv, 'undefined') -> 'ok';
maybe_update_presence_id(Srv, Id) ->
gen_listener:cast(Srv, {'presence_id', Id}).

-spec maybe_update_presence_state(pid(), api_ne_binary()) -> 'ok'.
maybe_update_presence_state(_Srv, 'undefined') -> 'ok';
maybe_update_presence_state(Srv, State) ->
presence_update(Srv, State).

-spec presence_update(pid(), api_ne_binary()) -> 'ok'.
presence_update(_, 'undefined') -> 'ok';
presence_update(Srv, PresenceState) ->
gen_listener:cast(Srv, {'presence_update', PresenceState}).
Expand Down Expand Up @@ -344,6 +372,7 @@ id(Srv) ->
%% {stop, Reason}
%% @end
%%--------------------------------------------------------------------
-spec init([atom() | agent() | ne_binaries()]) -> {'ok', state()}.
init([Supervisor, Agent, Queues]) ->
AgentId = agent_id(Agent),
kz_util:put_callid(AgentId),
Expand Down Expand Up @@ -1090,10 +1119,13 @@ maybe_connect_to_agent(MyQ, EPs, Call, Timeout, AgentId, _CdrUrl) ->
kapi_resource:publish_originate_req(Prop),
ACallIds.

-spec outbound_call_id(kapps_call:call() | ne_binary(), ne_binary()) -> ne_binary().
outbound_call_id(CallId, AgentId) when is_binary(CallId) ->
Hash = kz_util:to_hex_binary(erlang:md5(CallId)),
Rnd = kz_util:rand_hex_binary(4),
<<(kz_util:to_hex_binary(erlang:md5(CallId)))/binary, "-", AgentId/binary, "-", Rnd/binary>>;
outbound_call_id(Call, AgentId) -> outbound_call_id(kapps_call:call_id(Call), AgentId).
<<Hash/binary, "-", AgentId/binary, "-", Rnd/binary>>;
outbound_call_id(Call, AgentId) ->
outbound_call_id(kapps_call:call_id(Call), AgentId).

-spec add_queue_binding(ne_binary(), ne_binary(), ne_binary()) -> 'ok'.
add_queue_binding(AcctId, AgentId, QueueId) ->
Expand Down
17 changes: 12 additions & 5 deletions applications/acdc/src/acdc_agent_maintenance.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
]).

-include("acdc.hrl").


-spec status() -> 'ok'.
status() -> acdc_agents_sup:status().

-spec acct_status(text()) -> 'ok'.
acct_status(AcctId) when not is_binary(AcctId) ->
acct_status(kz_util:to_binary(AcctId));
acct_status(AcctId) ->
Expand All @@ -29,15 +33,17 @@ acct_status(AcctId) ->
lists:foreach(fun acdc_agent_sup:status/1, As)
end.

agent_status(AcctId, AgentId) when (not is_binary(AcctId))
orelse (not is_binary(AgentId)) ->
-spec agent_status(text(), text()) -> 'ok'.
agent_status(AcctId, AgentId) when not is_binary(AcctId);
not is_binary(AgentId) ->
agent_status(kz_util:to_binary(AcctId), kz_util:to_binary(AgentId));
agent_status(AcctId, AgentId) ->
case acdc_agents_sup:find_agent_supervisor(AcctId, AgentId) of
'undefined' -> lager:info("no agent ~s in account ~s available", [AgentId, AcctId]);
S -> acdc_agent_sup:status(S), 'ok'
S -> acdc_agent_sup:status(S)
end.

-spec acct_restart(text()) -> 'ok'.
acct_restart(AcctId) when not is_binary(AcctId) ->
acct_restart(kz_util:to_binary(AcctId));
acct_restart(AcctId) ->
Expand All @@ -51,8 +57,9 @@ acct_restart(AcctId) ->
'ok'
end.

agent_restart(AcctId, AgentId) when (not is_binary(AcctId))
orelse (not is_binary(AgentId)) ->
-spec agent_restart(text(), text()) -> 'ok'.
agent_restart(AcctId, AgentId) when not is_binary(AcctId);
not is_binary(AgentId) ->
agent_restart(kz_util:to_binary(AcctId), kz_util:to_binary(AgentId));
agent_restart(AcctId, AgentId) ->
case acdc_agents_sup:find_agent_supervisor(AcctId, AgentId) of
Expand Down
14 changes: 9 additions & 5 deletions applications/acdc/src/acdc_agent_stats.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
-include("acdc.hrl").
-include("acdc_stats.hrl").

-spec status_table_id() -> atom().
-spec status_key_pos() -> pos_integer().
-spec status_table_opts() -> kz_proplist().
status_table_id() -> 'acdc_stats_status'.
status_key_pos() -> #status_stat.id.
status_table_opts() ->
Expand Down Expand Up @@ -397,19 +400,19 @@ status_stat_to_doc(#status_stat{id=Id
,{'type', <<"status_stat">>}
]).

-spec archive_status_data(pid(), boolean()) -> 'ok'.
archive_status_data(Srv, 'true') ->
kz_util:put_callid(<<"acdc_stats.force_status_archiver">>),

Match = [{#status_stat{is_archived='$1'
,_='_'
}
,[{'=:=', '$1', 'false'}]
,['$_']
}],
maybe_archive_status_data(Srv, Match);

archive_status_data(Srv, 'false') ->
kz_util:put_callid(<<"acdc_stats.status_archiver">>),

Past = kz_util:current_tstamp() - ?ARCHIVE_WINDOW,
Match = [{#status_stat{timestamp='$1'
,is_archived='$2'
Expand All @@ -431,9 +434,10 @@ maybe_archive_status_data(Srv, Match) ->
_ = [kz_datamgr:save_docs(acdc_stats_util:db_name(Acct), Docs)
|| {Acct, Docs} <- dict:to_list(ToSave)
],
[gen_listener:cast(Srv, {'update_status', Id, [{#status_stat.is_archived, 'true'}]})
|| #status_stat{id=Id} <- Stats
]
_ = [gen_listener:cast(Srv, {'update_status', Id, [{#status_stat.is_archived, 'true'}]})
|| #status_stat{id=Id} <- Stats
],
'ok'
end.

-spec archive_status_fold(status_stat(), dict:dict()) -> dict:dict().
Expand Down
3 changes: 2 additions & 1 deletion applications/acdc/src/acdc_agent_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
%%% Daniel Finke
%%%-------------------------------------------------------------------
-module(acdc_agent_sup).

-behaviour(supervisor).

-include("acdc.hrl").
Expand Down Expand Up @@ -40,6 +39,7 @@
%%--------------------------------------------------------------------
-spec start_link(kz_json:object()) -> startlink_ret().
-spec start_link(kapps_call:call(), ne_binary()) -> startlink_ret().
-spec start_link(ne_binary(), ne_binary(), kz_json:object(), ne_binaries()) -> startlink_ret().
start_link(AgentJObj) ->
supervisor:start_link(?SERVER, [AgentJObj]).
start_link(ThiefCall, QueueId) ->
Expand All @@ -51,6 +51,7 @@ start_link(AcctId, AgentId, AgentJObj, Queues) ->
stop(Supervisor) ->
supervisor:terminate_child('acdc_agents_sup', Supervisor).

-spec restart(pid()) -> sup_startchild_ret().
restart(Supervisor) ->
_ = stop(Supervisor),
supervisor:restart_child('acdc_agents_sup', Supervisor).
Expand Down
17 changes: 13 additions & 4 deletions applications/acdc/src/acdc_agent_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,15 @@ async_most_recent_db_statuses(AccountId, AgentId, Options, Pid) ->
'ok'
end.

-spec most_recent_ets_statuses(ne_binary()) -> statuses_return() |
{'error', any()}.
-spec most_recent_ets_statuses(ne_binary(), api_binary(), kz_proplist()) -> statuses_return() |
{'error', any()}.
-spec most_recent_ets_statuses(ne_binary()) ->
statuses_return() |
{'error', any()}.
-spec most_recent_ets_statuses(ne_binary(), api_binary()) ->
statuses_return() |
{'error', any()}.
-spec most_recent_ets_statuses(ne_binary(), api_binary(), kz_proplist()) ->
statuses_return() |
{'error', any()}.
most_recent_ets_statuses(AccountId) ->
most_recent_ets_statuses(AccountId, 'undefined', []).

Expand Down Expand Up @@ -257,6 +262,9 @@ most_recent_ets_statuses(AccountId, AgentId, Options) ->
-spec most_recent_db_statuses(ne_binary()) ->
statuses_return() |
{'error', any()}.
-spec most_recent_db_statuses(ne_binary(), api_binary()) ->
statuses_return() |
{'error', any()}.
-spec most_recent_db_statuses(ne_binary(), api_binary(), kz_proplist()) ->
statuses_return() |
{'error', any()}.
Expand Down Expand Up @@ -407,6 +415,7 @@ cleanup_db_statuses(Stats, ReqOpts) ->

always_true(_) -> 'true'.

-spec changed(list(), list()) -> {list(), list()}.
changed([], To) -> {To, []};
changed(From, []) -> {[], From};
changed(From, To) -> changed(From, To, [], []).
Expand Down
Loading

0 comments on commit e174397

Please sign in to comment.