Browse files

Template for Finsignia compliant gen_server.

Used with rebar create subcommand we can generate a initial gen_server
that complies with Finsignia internal coding standards/style guidelines.

To generate run:
% rebar create template=finsrv server_name=server_name_minus_srv \
    description="Manages connections to database...." \
    author_name="Your Name" author_email="user@domain.com"
  • Loading branch information...
1 parent 1d3437d commit 277ceff9921b3516fa148639bb5d8cef81ebd793 @mbbx6spp committed Jan 31, 2011
Showing with 86 additions and 0 deletions.
  1. +81 −0 finsrv.erl
  2. +5 −0 finsrv.template
View
81 finsrv.erl
@@ -0,0 +1,81 @@
+%%%' HEADER
+%%% @author {{author_name}} <{{author_name}}>
+%%% @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]).
+
+-ifdef(TEST).
+-compile(export_all).
+-endif.
+
+% TODO: If unnamed server, remove definition below.
+-define(SERVER, ?MODULE).
+%%%.
+%%%' PUBLIC API
+
+%% @doc starts gen_server implementation and caller links to the process too.
+%% @spec start_link() -> {ok, Pid} | ignore | {error, Error}
+%% where
+%% Pid = pid(),
+%% Error = {already_started, Pid} | term()
+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, [], []).
+
+% TODO: add more public API here...
+
+%%%.
+%%%' CALLBACKS
+%% @private
+init(State) ->
+ {ok, State}.
+
+%% @private
+handle_call(_Req, _From, State) ->
+ {reply, State}.
+
+%% @private
+handle_cast(stop, State) ->
+ {stop, normal, State};
+handle_cast(_Req, State) ->
+ {noreply, State}.
+
+%% @private
+handle_info(_Info, State) ->
+ {noreply, State}.
+
+%% @private
+code_change(_OldVsn, State, _Extra) ->
+ {ok, State}.
+
+%% @private
+stop() ->
+ gen_server:cast(?MODULE, stop).
+
+%% @private
+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:
View
5 finsrv.template
@@ -0,0 +1,5 @@
+{variables, [
+ {name, "myserver"},
+ {author_name, "Susan Potter"},
+ {author_email, "me@susanpotter.net"}]}.
+{template, "gen_server.erl", "src/{{name}}.erl"}.

0 comments on commit 277ceff

Please sign in to comment.