-
Notifications
You must be signed in to change notification settings - Fork 32
/
finsrv.erl
79 lines (64 loc) · 1.88 KB
/
finsrv.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
%%%' HEADER
%%% @author {{author_name}} <{{author_email}}>
%%% @copyright {{copyright_year}} {{author_name}}
%%% @doc gen_server callback module implementation:
%%% {{description}}
%%% @end
-module({{name}}_srv).
-author('{{author_name}} <{{author_email}}>').
-behaviour(gen_server).
-export([start_link/0]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2]).
-export([code_change/3]).
-export([stop/0, terminate/2]).
% TODO: If unnamed server, remove definition below.
-define(SERVER, ?MODULE).
%%%.
%%%' TYPE DEFINITIONS
-type start_link_error() :: {already_started, pid()} | term().
%%%.
%%%' PUBLIC API
%% @doc starts gen_server implementation and caller links to the process too.
-spec start_link() -> {ok, pid()} | ignore | {error, start_link_error()}.
start_link() ->
% TODO: decide whether to name gen_server callback implementation or not.
% gen_server:start_link(?MODULE, [], []). % for unnamed gen_server
gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
%% @doc stops gen_server implementation process
-spec stop() -> ok.
stop() ->
gen_server:cast(?SERVER, stop).
% TODO: add more public API here...
%%%.
%%%' CALLBACKS
%% @callback gen_server
init(State) ->
{ok, State}.
%% @callback gen_server
handle_call(_Req, _From, State) ->
{reply, State}.
%% @callback gen_server
handle_cast(stop, State) ->
{stop, normal, State};
handle_cast(_Req, State) ->
{noreply, State}.
%% @callback gen_server
handle_info(_Info, State) ->
{noreply, State}.
%% @callback gen_server
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
%% @callback gen_server
terminate(normal, _State) ->
ok;
terminate(shutdown, _State) ->
ok;
terminate({shutdown, _Reason}, _State) ->
ok;
terminate(_Reason, _State) ->
ok.
%%%.
%%%' PRIVATE FUNCTIONS
% TODO: Add private helper functions here.
%%%.
%%% vim: set filetype=erlang tabstop=2 foldmarker=%%%',%%%. foldmethod=marker: