summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-11-02 23:55:00 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-11-02 23:55:00 +0100
commit4ee8fd87719428159c1a059f8aa13ecb2d18b2b8 (patch)
treef6ee4e4f75e393a9cde2d8c949c9b6b35d5f553f
parent37c93f93583348cc430175e7c472bddb2ec6fd50 (diff)
Add gen_server stub
-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}])).