summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/tda.erl33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/tda.erl b/src/tda.erl
index 847c421..7a7b04c 100644
--- a/src/tda.erl
+++ b/src/tda.erl
@@ -1,4 +1,10 @@
-module(tda).
+-behaviour(gen_server).
+-define (SERVER, ?MODULE).
+
+-export([start_link/0]).
+-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
+ terminate/2, code_change/3]).
-export([start/0, client/1, stop/0, decode/1]).
-export([send/1, ext/0, co/0, snapshot/1, monitor/1, button/1, dial/2]).
@@ -6,6 +12,33 @@
-include("config.hrl").
-include("opcodes.hrl").
+start_link() ->
+ gen_server:start_link({local, ?SERVER}, ?MODULE, [?HOST, ?PORT], []).
+
+init(Args) ->
+ counter:start(),
+ [Host, Port] = Args,
+ gen_tcp:connect(Host, Port, [binary, {packet, 2}], ?TIMEOUT).
+
+handle_call(_Request, _From, State) ->
+ {reply, ok, State}.
+
+handle_cast(_Msg, State) ->
+ {noreply, State}.
+
+handle_info(_Info, State) ->
+ {noreply, State}.
+
+terminate(_Reason, State) ->
+ counter:stop(),
+ gen_tcp:close(State),
+ ok.
+
+code_change(_OldVsn, State, _Extra) ->
+ {ok, State}.
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
start() ->
register(?MODULE, spawn(?MODULE, client, [{dial, ?HOST, ?PORT}])).