Wrote the boiler-plate code to start the IRC modules as an application.
authorMatt Mullins <mmullins@mmlx.us>
Sun, 22 May 2011 05:11:25 +0000 (00:11 -0500)
committerMatt Mullins <mmullins@mmlx.us>
Sun, 22 May 2011 05:11:25 +0000 (00:11 -0500)
irc/irc.app [new file with mode: 0644]
irc/irc_app.erl [new file with mode: 0644]
irc/irc_conn.erl
irc/irc_sup.erl [new file with mode: 0644]

diff --git a/irc/irc.app b/irc/irc.app
new file mode 100644 (file)
index 0000000..509b3e9
--- /dev/null
@@ -0,0 +1,8 @@
+{application, irc,
+ [{description, "IRC protocol application"},
+  {vsn, 1},
+  {modules, [irc_app, irc_sup, irc_net_sup, irc_conn]},
+  {registered, [irc_sup]},
+  {applications, [core]},
+  {mod, {irc_app, []}}
+ ]}.
diff --git a/irc/irc_app.erl b/irc/irc_app.erl
new file mode 100644 (file)
index 0000000..8a00c89
--- /dev/null
@@ -0,0 +1,8 @@
+%% @doc IRC application call-back module
+-module(irc_app).
+-behavior(application).
+
+-export([start/2]).
+
+start(normal, _Args) ->
+    irc_sup:start_link().
index ab7c6ed..7e64770 100644 (file)
@@ -1,5 +1,6 @@
 -module(irc_conn).
 -behavior(gen_server).
+-vsn(1).
 
 -export([
           start_link/2
diff --git a/irc/irc_sup.erl b/irc/irc_sup.erl
new file mode 100644 (file)
index 0000000..32311cc
--- /dev/null
@@ -0,0 +1,28 @@
+%% @doc Top-level supervisor for the IRC application.
+-module(irc_sup).
+-behavior(supervisor).
+
+%% Public functions
+-export([start_link/0]).
+
+%% Callbacks for supervisor behavior
+-export([init/1]).
+-compile(export_all).
+
+start_link() ->
+    supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+
+init(_) ->
+    IrcConfigs = config:get_config(irc),
+    Children = lists:map(fun config_to_childspec/1, IrcConfigs),
+    Restart = {one_for_one, 5, 60},
+    {ok, {Restart, Children}}.
+
+config_to_childspec({Instance, Config}) ->
+    {instance, % child's name
+     {irc_net_sup, start_link, [Instance, Config]}, % MFA
+     permanent, % Restart
+     5, % shutdown [timeout of 5 seconds]
+     supervisor,
+     [irc_net_sup]
+    }.