Skip to content

Commit

Permalink
tabify & indent
Browse files Browse the repository at this point in the history
  • Loading branch information
joelreymont committed Nov 10, 2008
1 parent fbd35f3 commit 35b406f
Show file tree
Hide file tree
Showing 55 changed files with 7,323 additions and 7,321 deletions.
28 changes: 14 additions & 14 deletions src/ante.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
-include("game.hrl").

start(Game, Ctx, []) ->
Game1 = g:reset_player_state(Game, ?PS_ANY, ?PS_PLAY),
Players = g:get_seats(Game1, ?PS_ACTIVE),
post_ante(Game1, Game1#game.ante, Players),
{stop, Game, Ctx}.
Game1 = g:reset_player_state(Game, ?PS_ANY, ?PS_PLAY),
Players = g:get_seats(Game1, ?PS_ACTIVE),
post_ante(Game1, Game1#game.ante, Players),
{stop, Game, Ctx}.

post_ante(Game, _, []) ->
Game;
Game;

post_ante(Game, Ante, [H|T]) ->
Seat = g:get_seat(Game, H),
Game1 = g:add_bet(Game, H, Ante),
R = #notify_raise{
game = Game1#game.gid,
player = Seat#seat.pid,
Seat = g:get_seat(Game, H),
Game1 = g:add_bet(Game, H, Ante),
R = #notify_raise{
game = Game1#game.gid,
player = Seat#seat.pid,
raise = 0,
call = Ante
},
Game2 = g:broadcast(Game1, R),
post_ante(Game2, Ante, T).
call = Ante
},
Game2 = g:broadcast(Game1, R),
post_ante(Game2, Ante, T).
184 changes: 92 additions & 92 deletions src/barrier.erl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
%%% Copyright (C) 2005-2008 Wager Labs, SA
%%%% Copyright (C) 2005-2008 Wager Labs, SA

-module(barrier).
-behaviour(gen_server).

-export([init/1, handle_call/3, handle_cast/2,
handle_info/2, terminate/2, code_change/3]).
handle_info/2, terminate/2, code_change/3]).

-export([start/2, stop/1, bump/1, wait/1]).

Expand All @@ -13,139 +13,139 @@
-include("test.hrl").

-record(barrier, {
target,
counter,
timer
}).
target,
counter,
timer
}).

start(time, Target)
when is_tuple(Target) ->
gen_server:start(barrier, [time, Target], []);
when is_tuple(Target) ->
gen_server:start(barrier, [time, Target], []);

start(counter, Target)
when is_integer(Target) ->
gen_server:start(barrier, [counter, Target], []).
when is_integer(Target) ->
gen_server:start(barrier, [counter, Target], []).

init([time, Time])
when is_tuple(Time) ->
process_flag(trap_exit, true),
Delta = case Time of
{seconds, N} ->
timer:seconds(N);
{minutes, N} ->
timer:minutes(N)
end,
{ok, Timer} = timer:apply_after(Delta, barrier, stop, [self()]),
{ok, #barrier{ timer = Timer }};
when is_tuple(Time) ->
process_flag(trap_exit, true),
Delta = case Time of
{seconds, N} ->
timer:seconds(N);
{minutes, N} ->
timer:minutes(N)
end,
{ok, Timer} = timer:apply_after(Delta, barrier, stop, [self()]),
{ok, #barrier{ timer = Timer }};

init([counter, Target])
when is_integer(Target) ->
process_flag(trap_exit, true),
{ok, #barrier{ target = Target, counter = 0 }}.
when is_integer(Target) ->
process_flag(trap_exit, true),
{ok, #barrier{ target = Target, counter = 0 }}.

stop(Barrier)
when is_pid(Barrier) ->
gen_server:cast(Barrier, {stop, self()}).
when is_pid(Barrier) ->
gen_server:cast(Barrier, {stop, self()}).

bump(Barrier) ->
gen_server:cast(Barrier, 'BUMP').
gen_server:cast(Barrier, 'BUMP').

terminate(_Reason, Data)
when Data#barrier.timer /= undefined ->
catch timer:cancel(Data#barrier.timer),
ok;
when Data#barrier.timer /= undefined ->
catch timer:cancel(Data#barrier.timer),
ok;

terminate(_Reason, _Data) ->
ok.
ok.

handle_cast('BUMP', Data)
when Data#barrier.counter + 1 >= Data#barrier.target ->
io:format("barrier: reached target of ~p~n",
[Data#barrier.target]),
{stop, normal, Data};
when Data#barrier.counter + 1 >= Data#barrier.target ->
io:format("barrier: reached target of ~p~n",
[Data#barrier.target]),
{stop, normal, Data};

handle_cast('BUMP', Data) ->
N = Data#barrier.counter,
{noreply, Data#barrier{ counter = N + 1}};
N = Data#barrier.counter,
{noreply, Data#barrier{ counter = N + 1}};

handle_cast({'TARGET', N}, Data) ->
{noreply, Data#barrier{ target = N }};
{noreply, Data#barrier{ target = N }};

handle_cast({stop, _Pid}, Data) ->
{stop, normal, Data};
{stop, normal, Data};

handle_cast(Event, Data) ->
error_logger:info_report([{module, ?MODULE},
{line, ?LINE},
{self, self()},
{data, Data},
{message, Event}
]),
{noreply, Data}.
error_logger:info_report([{module, ?MODULE},
{line, ?LINE},
{self, self()},
{data, Data},
{message, Event}
]),
{noreply, Data}.

handle_call('COUNTER', _From, Data) ->
{reply, Data#barrier.counter, Data};
{reply, Data#barrier.counter, Data};

handle_call('TARGET', _From, Data) ->
{reply, Data#barrier.target, Data};
{reply, Data#barrier.target, Data};

handle_call(Event, From, Data) ->
error_logger:info_report([{module, ?MODULE},
{line, ?LINE},
{self, self()},
{from, From},
{data, Data},
{message, Event}
]),
{noreply, Data}.
error_logger:info_report([{module, ?MODULE},
{line, ?LINE},
{self, self()},
{from, From},
{data, Data},
{message, Event}
]),
{noreply, Data}.

handle_info({'EXIT', _Pid, _Reason}, Data) ->
%% child exit?
{noreply, Data};
%% child exit?
{noreply, Data};

handle_info(Info, Data) ->
error_logger:info_report([{module, ?MODULE},
{line, ?LINE},
{self, self()},
{data, Data},
{message, Info}
]),
{noreply, Data}.

error_logger:info_report([{module, ?MODULE},
{line, ?LINE},
{self, self()},
{data, Data},
{message, Info}
]),
{noreply, Data}.


code_change(_OldVsn, Data, _Extra) ->
{ok, Data}.
{ok, Data}.

wait(Barrier) ->
TE = process_flag(trap_exit, true),
link(Barrier),
receive {'EXIT', Barrier, normal} -> ok end,
process_flag(trap_exit, TE),
ok.
TE = process_flag(trap_exit, true),
link(Barrier),
receive {'EXIT', Barrier, normal} -> ok end,
process_flag(trap_exit, TE),
ok.

%%%
%%% Test suite
%%%

counter_test() ->
{ok, B} = start(counter, 2),
?assertEqual(true, util:is_process_alive(B)),
bump(B),
?assertEqual(true, util:is_process_alive(B)),
bump(B),
timer:sleep(100),
?assertEqual(false, util:is_process_alive(B)),
ok.

timer_test() ->
{ok, B} = start(time, {seconds, 2}),
?assertEqual(true, util:is_process_alive(B)),
timer:sleep(2000),
?assertEqual(false, util:is_process_alive(B)),
ok.
{ok, B} = start(counter, 2),
?assertEqual(true, util:is_process_alive(B)),
bump(B),
?assertEqual(true, util:is_process_alive(B)),
bump(B),
timer:sleep(100),
?assertEqual(false, util:is_process_alive(B)),
ok.

timer_test() ->
{ok, B} = start(time, {seconds, 2}),
?assertEqual(true, util:is_process_alive(B)),
timer:sleep(2000),
?assertEqual(false, util:is_process_alive(B)),
ok.

wait_test() ->
{ok, B} = start(time, {seconds, 2}),
?assertEqual(ok, wait(B)),
ok.
{ok, B} = start(time, {seconds, 2}),
?assertEqual(ok, wait(B)),
ok.

Loading

0 comments on commit 35b406f

Please sign in to comment.