-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",
-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
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,