diff --git a/.gitignore b/.gitignore index c0a872f..04a4185 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ .eunit ebin/*.app -ebin/*.beam +*.beam doc/*.html doc/edoc-info doc/erlang.png diff --git a/test/sample.app b/test/sample.app new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/test/sample.app @@ -0,0 +1 @@ + diff --git a/test/sample.erl b/test/sample.erl new file mode 100644 index 0000000..88700ec --- /dev/null +++ b/test/sample.erl @@ -0,0 +1,17 @@ +%%%------------------------------------------------------------------- +%%% File : sample.erl +%%% Author : UENISHI Kota +%%% Description : +%%% +%%% Created : 5 May 2011 by UENISHI Kota +%%%------------------------------------------------------------------- +-module(sample). + +-export([start/0, stop/0]). + +start()-> + application:start(sample_app). + +stop()-> + application:stop(sample_app). + diff --git a/test/sample_app.erl b/test/sample_app.erl index 14cfaf0..5ea6d29 100644 --- a/test/sample_app.erl +++ b/test/sample_app.erl @@ -7,18 +7,41 @@ %%%------------------------------------------------------------------- -module(sample_app). --include_lib("eunit/include/eunit.hrl"). +-behaviour(application). %% Application callbacks -%-export([start_link/1]). +-export([start/2, stop/1]). -%% start()-> -%% msgpack_rpc:start(), -%% case msgpack_rpc:add_server(sample_srv, [{addr, localhost}]) of -%% {ok, _} -> ok; -%% Other -> Other -%% end. +%%==================================================================== +%% Application callbacks +%%==================================================================== +%%-------------------------------------------------------------------- +%% Function: start(Type, StartArgs) -> {ok, Pid} | +%% {ok, Pid, State} | +%% {error, Reason} +%% Description: This function is called whenever an application +%% is started using application:start/1,2, and should start the processes +%% of the application. If the application is structured according to the +%% OTP design principles as a supervision tree, this means starting the +%% top supervisor of the tree. +%%-------------------------------------------------------------------- +start(_Type, StartArgs) -> + case sample_sup:start_link(StartArgs) of + {ok, Pid} -> + {ok, Pid}; + Error -> + Error + end. -%% stop()-> -%% msgpack_rpc:del_server(sample_srv), -%% msgpack_rpc:stop(). +%%-------------------------------------------------------------------- +%% Function: stop(State) -> void() +%% Description: This function is called whenever an application +%% has stopped. It is intended to be the opposite of Module:start/2 and +%% should do any necessary cleaning up. The return value is ignored. +%%-------------------------------------------------------------------- +stop(_State) -> + ok. + +%%==================================================================== +%% Internal functions +%%==================================================================== diff --git a/test/sample_sup.erl b/test/sample_sup.erl new file mode 100644 index 0000000..7e0a5fb --- /dev/null +++ b/test/sample_sup.erl @@ -0,0 +1,49 @@ +%%%------------------------------------------------------------------- +%%% File : sample_sup.erl +%%% Author : UENISHI Kota +%%% Description : +%%% +%%% Created : 5 May 2011 by UENISHI Kota +%%%------------------------------------------------------------------- +-module(sample_sup). + +-behaviour(supervisor). + +%% API +-export([start_link/0]). + +%% Supervisor callbacks +-export([init/1]). + +-define(SERVER, ?MODULE). + +%%==================================================================== +%% API functions +%%==================================================================== +%%-------------------------------------------------------------------- +%% Function: start_link() -> {ok,Pid} | ignore | {error,Error} +%% Description: Starts the supervisor +%%-------------------------------------------------------------------- +start_link() -> + supervisor:start_link({local, ?SERVER}, ?MODULE, []). + +%%==================================================================== +%% Supervisor callbacks +%%==================================================================== +%%-------------------------------------------------------------------- +%% Func: init(Args) -> {ok, {SupFlags, [ChildSpec]}} | +%% ignore | +%% {error, Reason} +%% Description: Whenever a supervisor is started using +%% supervisor:start_link/[2,3], this function is called by the new process +%% to find out about restart strategy, maximum restart frequency and child +%% specifications. +%%-------------------------------------------------------------------- +init([]) -> + AChild = {'AName',{sample_srv,start_link,[]}, + permanent,2000,worker,[sample_srv]}, + {ok,{{one_for_all,0,1}, [AChild]}}. + +%%==================================================================== +%% Internal functions +%%==================================================================== diff --git a/test/samplectl b/test/samplectl new file mode 100755 index 0000000..6c1ccbd --- /dev/null +++ b/test/samplectl @@ -0,0 +1,30 @@ +#! /bin/sh + +ERL_LIBS=`pwd` +erl -make + +case "$1" in + start) + + echo "Starting SampleApp server" "erl_msgpack_sample" + if exec erl -hidden -s sample start -s init stop -noshell -sname sampleapp; then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; + stop) + echo "Stopping SampleApp server" "erl_msgpack_sample" + if erl -eval 'rpc:call(sampleapp, sample, stop, []).' -noshell -sname sampleapp_ctl ; then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; + + *) + log_action_msg "Usage: samplectl {start|stop}" + exit 1 +esac + +exit 0