Permalink
Browse files

Initial code - using rebar.

  • Loading branch information...
alexarnon committed Jan 26, 2012
1 parent 46db4b2 commit 004a6dde0433188eee4063845c65bc535f45b068
View
Binary file not shown.
@@ -0,0 +1,12 @@
+{application, gwatt_lib,
+ [
+ {description, ""},
+ {vsn, "1"},
+ {registered, []},
+ {applications, [
+ kernel,
+ stdlib
+ ]},
+ {mod, { gwatt_lib_app, []}},
+ {env, []}
+ ]}.
@@ -0,0 +1,16 @@
+-module(gwatt_lib_app).
+
+-behaviour(application).
+
+%% Application callbacks
+-export([start/2, stop/1]).
+
+%% ===================================================================
+%% Application callbacks
+%% ===================================================================
+
+start(_StartType, _StartArgs) ->
+ gwatt_lib_sup:start_link().
+
+stop(_State) ->
+ ok.
@@ -0,0 +1,48 @@
+%%% @author <alex.arnon@gmail.com>
+%%% @copyright (C) 2012,
+%%% @doc
+%%% Dummy server to be watched by Sup - to be removed
+%%% once we figure out how to use this Rebar person.
+%%% @end
+%%% Created : 26 Jan 2012 by <alex.arnon@gmail.com>
+
+-module(gwatt_lib_server).
+
+-behaviour(gen_server).
+
+-export([start_link/0, say_hello/0]).
+
+-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
+ terminate/2, code_change/3]).
+
+start_link() ->
+ gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
+
+init([]) ->
+ {ok, []}.
+
+say_hello() ->
+ gen_server:call(?MODULE, hello).
+
+%% callbacks
+handle_call(hello, _From, State) ->
+ io:format("Hello from server!~n", []),
+ {reply, ok, State};
+
+handle_call(_Request, _From, State) ->
+ Reply = ok,
+ {reply, Reply, State}.
+
+handle_cast(_Msg, State) ->
+ {noreply, State}.
+
+handle_info(_Info, State) ->
+ {noreply, State}.
+
+terminate(_Reason, _State) ->
+ ok.
+
+code_change(_OldVsn, State, _Extra) ->
+ {ok, State}.
+
+
@@ -0,0 +1,29 @@
+
+-module(gwatt_lib_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([]) ->
+ GwattLibServer = ?CHILD(gwatt_lib_server, worker),
+ {ok, { {one_for_one, 5, 10}, [GwattLibServer]} }.
+

0 comments on commit 004a6dd

Please sign in to comment.