Update GH URI
[cellular-automata.git] / 001 / src / life_god.erl
... / ...
CommitLineData
1-module(life_god).
2-behaviour(supervisor).
3
4
5%% API
6-export([start_link/3]).
7
8%% Callbacks
9-export([init/1]).
10
11
12%% Helper macro for declaring children of supervisor
13-define(CHILD(Type, I, Args), {I, {I, start_link, Args}, permanent, 5000, Type, [I]}).
14
15
16%% ============================================================================
17%% API
18%% ============================================================================
19
20start_link(X, Y, CellData) ->
21 supervisor:start_link({local, ?MODULE}, ?MODULE, [X, Y, CellData]).
22
23
24%% ============================================================================
25%% Callbacks
26%% ============================================================================
27
28init([X, Y, CellData]) ->
29 CellNames = [Name || {_, Name, _} <- CellData],
30 RestartStrategy = {one_for_one, 1000000, 1},
31
32 Observer = ?CHILD(worker, life_observer, [X, Y]),
33 Cells = [spec_cell(Datum) || Datum <- CellData],
34 Time = ?CHILD(worker, life_time, [X, Y, CellNames]),
35
36 Children = [Observer | Cells ++ [Time]],
37
38 {ok, {RestartStrategy, Children}}.
39
40
41spec_cell({_, Name, _}=Datum) ->
42 M = life_cell,
43 F = start_link,
44 A = [Datum],
45 {Name, {M, F, A}, permanent, 5000, worker, [M]}.
This page took 0.02677 seconds and 4 git commands to generate.