Skip to content
Browse files

v4, helper_app

  • Loading branch information...
1 parent e48a96a commit 82f34f08bd40301903d81c87dd223d427555e854 @RJ committed Mar 16, 2011
View
8 apps/helper_app/ebin/helper_app.app
@@ -0,0 +1,8 @@
+{application,helper_app,
+ [{description,"Helper app for dummy project"},
+ {vsn,"1"},
+ {registered,[]},
+ {applications,[kernel,stdlib]},
+ {mod,{helper_app,[]}},
+ {env,[]},
+ {modules,[helper_app,helper_app_server,helper_app_sup]}]}.
View
12 apps/helper_app/src/helper_app.app.src
@@ -0,0 +1,12 @@
+{application, helper_app,
+ [
+ {description, "Helper app for dummy project"},
+ {vsn, "1"},
+ {registered, []},
+ {applications, [
+ kernel,
+ stdlib
+ ]},
+ {mod, { helper_app, []}},
+ {env, []}
+ ]}.
View
19 apps/helper_app/src/helper_app.erl
@@ -0,0 +1,19 @@
+-module(helper_app).
+
+-behaviour(application).
+
+%% Application callbacks
+-export([start/0, start/2, stop/1]).
+
+start() -> application:start(helper_app).
+
+%% ===================================================================
+%% Application callbacks
+%% ===================================================================
+
+start(_StartType, _StartArgs) ->
+ error_logger:info_msg("Starting helper_app application...~n"),
+ helper_app_sup:start_link().
+
+stop(_State) ->
+ ok.
View
50 apps/helper_app/src/helper_app_server.erl
@@ -0,0 +1,50 @@
+-module(helper_app_server).
+
+-behaviour(gen_server).
+
+%% API
+%% API
+-export([ start_link/0
+ , num_to_comment/1
+ ]).
+
+%% gen_server callbacks
+-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
+ terminate/2, code_change/3]).
+
+-record(state, {num_pokes = 0, num_prods = 0}).
+
+%% API
+start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
+
+num_to_comment(N) -> gen_server:call(?MODULE, {num_to_comment, N}).
+
+%% gen_server callbacks
+init([]) ->
+ {ok, #state{}}.
+
+handle_call({num_to_comment, N}, _From, State) ->
+ Reply = comment(N),
+ {reply, Reply, State}.
+
+handle_cast(_Msg, State) ->
+ {noreply, State}.
+
+handle_info(_Info, State) ->
+ {noreply, State}.
+
+terminate(_Reason, _State) ->
+ ok.
+
+%% Upgrade from 2
+code_change(_OldVsn, State, _Extra) ->
+ error_logger:info_msg("code_change in helper app server~n"),
+ {ok, State}.
+
+%% Note downgrade code_change not implemented
+
+
+%%% Internal functions
+
+comment(N) when is_integer(N), N rem 2 =:= 0 -> "An even number!";
+comment(_) -> "An odd number!".
View
30 apps/helper_app/src/helper_app_sup.erl
@@ -0,0 +1,30 @@
+-module(helper_app_sup).
+
+-behaviour(supervisor).
+
+%% API
+-export([start_link/0]).
+
+%% Supervisor callbacks
+-export([init/1]).
+
+%% Helper macro for declaring children of supervisor
+-define(CHILD(I, Type), {I, {I, start_link, []}, permanent, 5000, Type, [I]}).
+
+%% ===================================================================
+%% API functions
+%% ===================================================================
+
+start_link() ->
+ supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+
+%% ===================================================================
+%% Supervisor callbacks
+%% ===================================================================
+
+init([]) ->
+ Children = [
+ ?CHILD(helper_app_server, worker)
+ ],
+ {ok, { {one_for_one, 5, 10}, Children} }.
+
View
1 rebar.config
@@ -1,5 +1,6 @@
{sub_dirs, [
"apps/dummy_app",
+ "apps/helper_app",
"rel"
]}.
View
3 rel/reltool.config
@@ -1,10 +1,11 @@
{sys, [
{lib_dirs, ["../apps"]},
- {rel, "dummy", "3",
+ {rel, "dummy", "4",
[
kernel,
stdlib,
sasl,
+ helper_app,
dummy_app
]},
{rel, "start_clean", "",

0 comments on commit 82f34f0

Please sign in to comment.
Something went wrong with that request. Please try again.