Refactored the way configuration data is passed through the IRC application.
authorMatt Mullins <mmullins@mmlx.us>
Tue, 30 Aug 2011 21:14:12 +0000 (16:14 -0500)
committerMatt Mullins <mmullins@mmlx.us>
Tue, 30 Aug 2011 21:14:12 +0000 (16:14 -0500)
Instead of passing configuration data all the way from the irc_sup, all that is
passed is the instance name, and the irc_conn is responsible for getting the
configuration data from the config module.

irc/irc_conn.erl
irc/irc_net_sup.erl
irc/irc_sup.erl

index 318838a..2108db6 100644 (file)
@@ -3,7 +3,7 @@
 -vsn(1).
 
 -export([
-          start_link/2
+          start_link/3
         ]).
 
 -export([
                     buffer = ""    % for the TCP session
                    }).
 
-start_link(Instance, Config) ->
+start_link(Instance, Supervisor, TableId) ->
     gen_server:start_link(?MODULE,
-        {Instance, Config}, []).
+        {Instance, Supervisor, TableId}, []).
 
-init({Instance, Config = {Host, Port, Nick, Realname, _Channels}}) ->
+init({Instance, Supervisor, TableId}) ->
+    {Instance, Config} = lists:keyfind(Instance, 1, config:get_config(irc)),
+    {Host, Port, Nick, Realname, _Channels} = Config,
     {ok, Socket} = gen_tcp:connect(Host, Port, [list]),
     send_command(#irc_command{command = "NICK", middles = [Nick]}),
     send_command(#irc_command{command = "USER",
index cd4be7a..f9f6e65 100644 (file)
@@ -7,17 +7,18 @@
 -behavior(supervisor).
 
 -export([
-          start_link/2
+          start_link/1
                ]).
 -export([init/1]).
 
-start_link(Instance, Config) ->
-       supervisor:start_link(?MODULE,
-               {Instance, Config}).
+start_link(Instance) ->
+       supervisor:start_link(?MODULE, Instance).
 
-init({Instance, Config}) ->
+init(Instance) ->
+    Supervisor = self(),
+    TableId = ets:new(?MODULE, [set, public]),
        Connection = {connection,
-                  {irc_conn, start_link, [Instance, Config]},
+                  {irc_conn, start_link, [Instance, Supervisor, TableId]},
                   permanent, % persistence type ("Restart" in the manual)
                   5,         % shutdown [sends signal, with timeout for response]
                   worker,    % it's not a supervisor itself
index 9ae2bd3..a4b4dd4 100644 (file)
@@ -18,9 +18,9 @@ init(_) ->
     Restart = {one_for_one, 5, 60},
     {ok, {Restart, Children}}.
 
-config_to_childspec({Instance, Config}) ->
+config_to_childspec({Instance, _Config}) ->
     {Instance, % child's name
-     {irc_net_sup, start_link, [Instance, Config]}, % MFA
+     {irc_net_sup, start_link, [Instance]}, % MFA
      permanent, % Restart
      5, % shutdown [timeout of 5 seconds]
      supervisor,