summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-10-29 13:06:51 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-10-29 13:06:51 +0100
commited8124bd452ad2d3d927c2d95ef718fec81a4180 (patch)
tree06413816431988def5dfad7b4a49cf411219631e
parent515371ecf04c1fd274c6ea6d8f1d60fbefc4587f (diff)
Trap exit
-rw-r--r--counter.erl15
-rw-r--r--csta.erl8
-rw-r--r--rose.erl4
-rw-r--r--tda.erl2
4 files changed, 22 insertions, 7 deletions
diff --git a/counter.erl b/counter.erl
index 6ecd335..98605f6 100644
--- a/counter.erl
+++ b/counter.erl
@@ -1,11 +1,17 @@
-module(counter).
--export([start/0, count/1, next/0, set/1, stop/0]).
+-export([start/0, counter/0, next/0, set/1, stop/0]).
+
+-define(MAXCOUNT, 32767).
start() ->
- register(counterPid, spawn(?MODULE, count, [0])).
+ register(counterPid, spawn_link(?MODULE, counter, [0])).
+
+counter() ->
+ process_flag(trap_exit, true),
+ count(0).
-count(N) when N > 32767 ->
+count(N) when N > ?MAXCOUNT ->
count(0);
count(N) ->
@@ -15,6 +21,9 @@ count(N) ->
count(N+1);
{set, New} ->
count(New);
+ {'EXIT', Pid, Reason} ->
+ io:format("~p: ~p~n", [Pid, Reason]),
+ exit(normal);
{stop} ->
exit(normal)
end.
diff --git a/csta.erl b/csta.erl
index ca5fb09..60aaaee 100644
--- a/csta.erl
+++ b/csta.erl
@@ -1,6 +1,7 @@
-module(csta).
--export([lines/1, decode/1, status/0, snapshot/1]).
+-export([lines/1, decode/1, snapshot/1]).
+-export([decodeStatus/1, statusOk/0]).
-include("CSTA-escape-service.hrl").
-include("CSTA-snapshot-device.hrl").
@@ -21,7 +22,10 @@ lines(Device) ->
{kmeSystemData, {getSystemData, {request, {deviceList,
{category, {standardDevice, Device}}}}}}}}).
-status() ->
+decodeStatus(Data) ->
+ 'CSTA-system-status':decode('SystemStatusArg', Data).
+
+statusOk() ->
'CSTA-system-status':encode('SystemStatusRes', {noData, []}).
snapshot(Device) ->
diff --git a/rose.erl b/rose.erl
index e2fb004..c720dd8 100644
--- a/rose.erl
+++ b/rose.erl
@@ -31,7 +31,9 @@ dispatch({invoke, #'Invoke'{invokeId = Id, opcode = Op, argument = Data}}) ->
{local, 74} ->
ok;
{local, 211} ->
- return(Id, Op, csta:status());
+ {ok, Status} = csta:decodeStatus(Data),
+ io:format("Status: ~p~n", [Status]),
+ return(Id, Op, csta:statusOk());
_ ->
error
end;
diff --git a/tda.erl b/tda.erl
index 09f0752..0798365 100644
--- a/tda.erl
+++ b/tda.erl
@@ -9,7 +9,6 @@
-define(PORT, 33333).
start() ->
- counter:start(),
register(tdaPid, spawn(?MODULE, client, [{dial, ?HOST, ?PORT}])).
stop() ->
@@ -30,6 +29,7 @@ client({dial, Host, Port}) ->
Conn = gen_tcp:connect(Host, Port,
[binary, {active, once}, {packet, 2}],
?CONNECT_TIMEOUT),
+ counter:start(),
client(Conn);
client({ok, Sock}) ->