summaryrefslogtreecommitdiff
path: root/src/pbx_invoke.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/pbx_invoke.erl')
-rw-r--r--src/pbx_invoke.erl51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/pbx_invoke.erl b/src/pbx_invoke.erl
new file mode 100644
index 0000000..034fc1e
--- /dev/null
+++ b/src/pbx_invoke.erl
@@ -0,0 +1,51 @@
+-module(pbx_invoke).
+-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([next/0, get/0, set/1]).
+
+-define(MAXCOUNT, 32767).
+
+start_link() ->
+ gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
+
+init(_Args) ->
+ {ok, 0}.
+
+handle_call(next, _From, N) when N >= ?MAXCOUNT ->
+ {reply, 0, 0};
+handle_call(next, _From, N) ->
+ {reply, N + 1, N + 1};
+handle_call(get, _From, N) ->
+ {reply, N, N};
+handle_call({set, N}, _From, _N) ->
+ {reply, ok, N}.
+
+handle_cast(_Msg, State) ->
+ {noreply, State}.
+
+handle_info(_Info, State) ->
+ {noreply, State}.
+
+terminate(_Reason, _State) ->
+ ok.
+
+code_change(_OldVsn, State, _Extra) ->
+ {ok, State}.
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+set({present, N}) ->
+ gen_server:call(?SERVER, {set, N}).
+
+next() ->
+ N = gen_server:call(?SERVER, next),
+ {present, N}.
+
+get() ->
+ N = gen_server:call(?SERVER, gete),
+ {present, N}.