sccp_user: take advantage of new simplified osmo_util:pointcode2int()

This commit is contained in:
Harald Welte 2011-12-08 11:58:03 +01:00
parent 5b0f66f828
commit 44a9c99c0c
1 changed files with 15 additions and 25 deletions

View File

@ -32,7 +32,7 @@
-export([start_link/0]). -export([start_link/0]).
% client functions, may internally talk to our sccp_user server % client functions, may internally talk to our sccp_user server
-export([bind_ssn/2, unbind_ssn/2, pid_for_ssn/2, local_ssn_avail/2, -export([bind_ssn/1, bind_ssn/2, unbind_ssn/2, pid_for_ssn/2, local_ssn_avail/2,
dump/0]). dump/0]).
-record(scu_state, { -record(scu_state, {
@ -60,20 +60,17 @@ bind_ssn(Ssn) when is_integer(Ssn) ->
gen_server:call(?MODULE, {bind_ssn, Ssn, undefined}). gen_server:call(?MODULE, {bind_ssn, Ssn, undefined}).
bind_ssn(Ssn, undefined) when is_integer(Ssn) -> bind_ssn(Ssn, undefined) when is_integer(Ssn) ->
gen_server:call(?MODULE, {bind_ssn, Ssn, undefined}); gen_server:call(?MODULE, {bind_ssn, Ssn, undefined});
bind_ssn(Ssn, Pc) when is_integer(Ssn), is_integer(Pc) -> bind_ssn(Ssn, PcIn) when is_integer(Ssn) ->
gen_server:call(?MODULE, {bind_ssn, Ssn, Pc}); Pc = osmo_util:pointcode2int(PcIn),
bind_ssn(Ssn, Pc) when is_integer(Ssn), is_tuple(Pc) -> gen_server:call(?MODULE, {bind_ssn, Ssn, Pc}).
PcInt = osmo_util:pointcode2int(Pc),
bind_ssn(Ssn, PcInt).
unbind_ssn(Ssn, Pc) when is_integer(Pc) -> unbind_ssn(Ssn, PcIn) when is_integer(Ssn) ->
gen_server:call(?MODULE, {unbind_ssn, Ssn, Pc}); Pc = osmo_util:pointcode2int(PcIn),
unbind_ssn(Ssn, Pc) when is_integer(Ssn), is_tuple(Pc) -> gen_server:call(?MODULE, {unbind_ssn, Ssn, Pc}).
PcInt = osmo_util:pointcode2int(Pc),
unbind_ssn(Ssn, PcInt).
% determine the pid registered for a given {Ssn, PC} % determine the pid registered for a given {Ssn, PC}
pid_for_ssn(Ssn, Pc) when is_integer(Ssn), is_integer(Pc) -> pid_for_ssn(Ssn, PcIn) when is_integer(Ssn) ->
Pc = osmo_util:pointcode2int(PcIn),
% as this is only a read access, we read the ets table directly % as this is only a read access, we read the ets table directly
% rather than going through call/2 % rather than going through call/2
case ets:lookup(sccp_user_tbl, {Ssn, Pc}) of case ets:lookup(sccp_user_tbl, {Ssn, Pc}) of
@ -87,23 +84,16 @@ pid_for_ssn(Ssn, Pc) when is_integer(Ssn), is_integer(Pc) ->
_ -> _ ->
{error, no_such_ssn} {error, no_such_ssn}
end end
end; end.
pid_for_ssn(Ssn, Pc) when is_integer(Ssn), is_tuple(Pc) ->
PcInt = osmo_util:pointcode2int(Pc),
pid_for_ssn(Ssn, PcInt).
local_ssn_avail(Ssn, PcIn) when is_integer(Ssn) ->
local_ssn_avail(Ssn, Pc) when is_integer(Ssn), is_integer(Pc) -> Pc = osmo_util:pointcode2int(PcIn),
case pid_for_ssn(Ssn, Pc) of case pid_for_ssn(Ssn, Pc) of
{ok, UserPid} -> {ok, _UserPid} ->
true; true;
_ -> _ ->
false false
end; end.
local_ssn_avail(Ssn, Pc) when is_integer(Ssn), is_tuple(Pc) ->
PcInt = osmo_util:pointcode2int(Pc),
local_ssn_avail(Ssn, PcInt).
dump() -> dump() ->
List = ets:tab2list(sccp_user_tbl), List = ets:tab2list(sccp_user_tbl),
@ -126,7 +116,7 @@ handle_call({bind_ssn, Ssn, Pc}, {FromPid, _FromRef}, S) ->
case ets:insert_new(Tbl, NewRec) of case ets:insert_new(Tbl, NewRec) of
false -> false ->
{reply, {error, ets_insert}, S}; {reply, {error, ets_insert}, S};
Error -> _ ->
% We need to trap the user Pid for EXIT % We need to trap the user Pid for EXIT
% in order to automatically remove any SSN if % in order to automatically remove any SSN if
% the user process dies % the user process dies