Browse Source

Merge branch 'gen_fsm-template' of https://github.com/grahamrhay/erlang.mk

Loïc Hoguin 10 years ago
parent
commit
708812c67f
1 changed files with 42 additions and 0 deletions
  1. 42 0
      plugins/bootstrap.mk

+ 42 - 0
plugins/bootstrap.mk

@@ -117,6 +117,48 @@ tpl_gen_server = "-module($(n))." \
 	"" \
 	"" \
 	"code_change(_OldVsn, State, _Extra) ->" \
 	"code_change(_OldVsn, State, _Extra) ->" \
 	"	{ok, State}."
 	"	{ok, State}."
+tpl_gen_fsm = "-module($(n))." \
+	"-behaviour(gen_fsm)." \
+	"" \
+	"%% API." \
+	"-export([start_link/0])." \
+	"" \
+	"%% gen_fsm." \
+	"-export([init/1])." \
+	"-export([handle_event/3])." \
+	"-export([handle_sync_event/4])." \
+	"-export([handle_info/3])." \
+	"-export([terminate/3])." \
+	"-export([code_change/4])." \
+	"" \
+	"-record(state, {" \
+	"})." \
+	"" \
+	"%% API." \
+	"" \
+	"-spec start_link() -> {ok, pid()}." \
+	"start_link() ->" \
+	"	gen_fsm:start_link(?MODULE, [], [])." \
+	"" \
+	"%% gen_fsm." \
+	"" \
+	"init([]) ->" \
+	"	{ok, initial_state, \#state{}}." \
+	"" \
+	"handle_event(_Event, StateName, State) ->" \
+	"	{next_state, StateName, State}." \
+	"" \
+	"handle_sync_event(_Event, _From, StateName, State) ->" \
+	"	{reply, ignored, StateName, State}." \
+	"" \
+	"handle_info(_Info, StateName, State) ->" \
+	"	{next_state, StateName, State}." \
+	"" \
+	"terminate(_Reason, _StateName, _State) ->" \
+	"	ok." \
+	"" \
+	"code_change(_OldVsn, StateName, State, _Extra) ->" \
+	"	{ok, StateName, State}."
 tpl_cowboy_http = "-module($(n))." \
 tpl_cowboy_http = "-module($(n))." \
 	"-behaviour(cowboy_http_handler)." \
 	"-behaviour(cowboy_http_handler)." \
 	"" \
 	"" \