Commits

arkdro committed c1bb095

add get_timing api

Comments (0)

Files changed (1)

erlang/src/c_server.erl

 -behaviour(gen_server).
 
 -export([
+         get_timing/0,
+
          divide/2,
          subtract/2,
          add/2,
 %%==================================================================
 %% API
 %%==================================================================
+get_timing() ->
+    gen_server:call(?SERVER, get_timing).
+
 ping() ->
     gen_server:call(?SERVER, ping).
 
     {ok, #state{status = init, port = Port, portcmd = PortCommand }}.
 
 %-------------------------------------------------------------------
+handle_call(get_timing, _From, #state{count=Cnt, duration=Dur} = State) ->
+    Res = {Cnt, Dur},
+    {reply, Res, State};
 handle_call(ping, From, #state{status=running, port=Port} = State) ->
     New = send_to_port(State, Port, term_to_binary(ping)),
     {noreply, New#state{from=From}};
     gen_server:reply(From, pong),
     {noreply, New#state{from=undefined}};
 handle_info({Port, {data, Data}}, #state{from=From, port=Port} = State) ->
+    New = add_timing(State),
     Term = binary_to_term(Data),
     gen_server:reply(From, Term),
-    {noreply, State#state{from=undefined}};
+    {noreply, New#state{from=undefined}};
 handle_info(_I, State) ->
     error_logger:info_report({handle_info, unknown, _I}),
     {noreply, State}.