From: Matt Mullins Date: Sun, 22 May 2011 05:11:25 +0000 (-0500) Subject: Wrote the boiler-plate code to start the IRC modules as an application. X-Git-Tag: v4~7 X-Git-Url: http://git.mmlx.us/?a=commitdiff_plain;h=3dc494d3c9f3f63c2a52c1d0df16f255e4bbadd5;p=erlbot.git Wrote the boiler-plate code to start the IRC modules as an application. --- diff --git a/irc/irc.app b/irc/irc.app new file mode 100644 index 0000000..509b3e9 --- /dev/null +++ b/irc/irc.app @@ -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 index 0000000..8a00c89 --- /dev/null +++ b/irc/irc_app.erl @@ -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(). diff --git a/irc/irc_conn.erl b/irc/irc_conn.erl index ab7c6ed..7e64770 100644 --- a/irc/irc_conn.erl +++ b/irc/irc_conn.erl @@ -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 index 0000000..32311cc --- /dev/null +++ b/irc/irc_sup.erl @@ -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] + }.