25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-24 17:29:28 +01:00

Remove Type and Spec, backport list comprehensions, so R12B-5 can compile

This commit is contained in:
Badlop 2010-12-13 12:17:28 +01:00
parent fbcb9bb154
commit 3e9c9fc750

View File

@ -30,18 +30,12 @@
%%% Exported functions %%% Exported functions
%%% %%%
-spec start_link() -> {'ok', pid()} | {'error', term()}.
start_link() -> start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
-spec start() -> {'ok', pid()} | {'error', term()}.
start() -> start() ->
ensure_started(). ensure_started().
-spec create(term()) -> 'ok'.
create(Name) -> create(Name) ->
ensure_started(), ensure_started(),
case ets:member(pg2_table, {group, Name}) of case ets:member(pg2_table, {group, Name}) of
@ -55,10 +49,6 @@ create(Name) ->
ok ok
end. end.
-type name() :: term().
-spec delete(name()) -> 'ok'.
delete(Name) -> delete(Name) ->
ensure_started(), ensure_started(),
global:trans({{?MODULE, Name}, self()}, global:trans({{?MODULE, Name}, self()},
@ -67,8 +57,6 @@ delete(Name) ->
end), end),
ok. ok.
-spec join(name(), pid()) -> 'ok' | {'error', {'no_such_group', term()}}.
join(Name, Pid) when is_pid(Pid) -> join(Name, Pid) when is_pid(Pid) ->
ensure_started(), ensure_started(),
case ets:member(pg2_table, {group, Name}) of case ets:member(pg2_table, {group, Name}) of
@ -83,8 +71,6 @@ join(Name, Pid) when is_pid(Pid) ->
ok ok
end. end.
-spec leave(name(), pid()) -> 'ok' | {'error', {'no_such_group', name()}}.
leave(Name, Pid) when is_pid(Pid) -> leave(Name, Pid) when is_pid(Pid) ->
ensure_started(), ensure_started(),
case ets:member(pg2_table, {group, Name}) of case ets:member(pg2_table, {group, Name}) of
@ -99,10 +85,6 @@ leave(Name, Pid) when is_pid(Pid) ->
ok ok
end. end.
-type get_members_ret() :: [pid()] | {'error', {'no_such_group', name()}}.
-spec get_members(name()) -> get_members_ret().
get_members(Name) -> get_members(Name) ->
ensure_started(), ensure_started(),
case ets:member(pg2_table, {group, Name}) of case ets:member(pg2_table, {group, Name}) of
@ -112,8 +94,6 @@ get_members(Name) ->
{error, {no_such_group, Name}} {error, {no_such_group, Name}}
end. end.
-spec get_local_members(name()) -> get_members_ret().
get_local_members(Name) -> get_local_members(Name) ->
ensure_started(), ensure_started(),
case ets:member(pg2_table, {group, Name}) of case ets:member(pg2_table, {group, Name}) of
@ -123,16 +103,10 @@ get_local_members(Name) ->
{error, {no_such_group, Name}} {error, {no_such_group, Name}}
end. end.
-spec which_groups() -> [name()].
which_groups() -> which_groups() ->
ensure_started(), ensure_started(),
all_groups(). all_groups().
-type gcp_error_reason() :: {'no_process', term()} | {'no_such_group', term()}.
-spec get_closest_pid(term()) -> pid() | {'error', gcp_error_reason()}.
get_closest_pid(Name) -> get_closest_pid(Name) ->
case get_local_members(Name) of case get_local_members(Name) of
[Pid] -> [Pid] ->
@ -157,8 +131,6 @@ get_closest_pid(Name) ->
-record(state, {}). -record(state, {}).
-spec init([]) -> {'ok', #state{}}.
init([]) -> init([]) ->
Ns = nodes(), Ns = nodes(),
net_kernel:monitor_nodes(true), net_kernel:monitor_nodes(true),
@ -169,14 +141,6 @@ init([]) ->
pg2_table = ets:new(pg2_table, [ordered_set, protected, named_table]), pg2_table = ets:new(pg2_table, [ordered_set, protected, named_table]),
{ok, #state{}}. {ok, #state{}}.
-type call() :: {'create', name()}
| {'delete', name()}
| {'join', name(), pid()}
| {'leave', name(), pid()}.
-spec handle_call(call(), _, #state{}) ->
{'reply', 'ok', #state{}}.
handle_call({create, Name}, _From, S) -> handle_call({create, Name}, _From, S) ->
assure_group(Name), assure_group(Name),
{reply, ok, S}; {reply, ok, S};
@ -195,12 +159,6 @@ handle_call(Request, From, S) ->
[Request, From]), [Request, From]),
{noreply, S}. {noreply, S}.
-type all_members() :: [[name(),...]].
-type cast() :: {'exchange', node(), all_members()}
| {'del_member', name(), pid()}.
-spec handle_cast(cast(), #state{}) -> {'noreply', #state{}}.
handle_cast({exchange, _Node, List}, S) -> handle_cast({exchange, _Node, List}, S) ->
store(List), store(List),
{noreply, S}; {noreply, S};
@ -208,8 +166,6 @@ handle_cast(_, S) ->
%% Ignore {del_member, Name, Pid}. %% Ignore {del_member, Name, Pid}.
{noreply, S}. {noreply, S}.
-spec handle_info(tuple(), #state{}) -> {'noreply', #state{}}.
handle_info({'DOWN', MonitorRef, process, _Pid, _Info}, S) -> handle_info({'DOWN', MonitorRef, process, _Pid, _Info}, S) ->
member_died(MonitorRef), member_died(MonitorRef),
{noreply, S}; {noreply, S};
@ -222,8 +178,6 @@ handle_info({new_pg2, Node}, S) ->
handle_info(_, S) -> handle_info(_, S) ->
{noreply, S}. {noreply, S}.
-spec terminate(term(), #state{}) -> 'ok'.
terminate(_Reason, _S) -> terminate(_Reason, _S) ->
true = ets:delete(pg2_table), true = ets:delete(pg2_table),
ok. ok.
@ -289,8 +243,9 @@ join_group(Name, Pid) ->
try _ = ets:update_counter(pg2_table, Member_Name_Pid, {2, +1}) try _ = ets:update_counter(pg2_table, Member_Name_Pid, {2, +1})
catch _:_ -> catch _:_ ->
true = ets:insert(pg2_table, {Member_Name_Pid, 1}), true = ets:insert(pg2_table, {Member_Name_Pid, 1}),
_ = [ets:insert(pg2_table, {{local_member, Name, Pid}}) || _ = [ets:insert(pg2_table, {{local_member, Name, PidX}}) ||
node(Pid) =:= node()], PidX <- [Pid],
node(PidX) =:= node()],
true = ets:insert(pg2_table, {{pid, Pid, Name}}) true = ets:insert(pg2_table, {{pid, Pid, Name}})
end. end.
@ -301,8 +256,9 @@ leave_group(Name, Pid) ->
if if
N =:= 0 -> N =:= 0 ->
true = ets:delete(pg2_table, {pid, Pid, Name}), true = ets:delete(pg2_table, {pid, Pid, Name}),
_ = [ets:delete(pg2_table, {local_member, Name, Pid}) || _ = [ets:delete(pg2_table, {local_member, Name, PidX}) ||
node(Pid) =:= node()], PidX <- [Pid],
node(PidX) =:= node()],
true = ets:delete(pg2_table, Member_Name_Pid); true = ets:delete(pg2_table, Member_Name_Pid);
true -> true ->
ok ok