PageRenderTime 23ms CodeModel.GetById 15ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/doc/template.gen_server

https://code.google.com/p/zotonic/
Unknown | 100 lines | 81 code | 19 blank | 0 comment | 0 complexity | fa0c0f8a33bd00e9d233de3fe526f857 MD5 | raw file
  1%% @author Marc Worrell <marc@worrell.nl>
  2%% @copyright 2009 Marc Worrell
  3%%
  4%% @doc 
  5
  6%% Copyright 2009 Marc Worrell
  7%%
  8%% Licensed under the Apache License, Version 2.0 (the "License");
  9%% you may not use this file except in compliance with the License.
 10%% You may obtain a copy of the License at
 11%% 
 12%%     http://www.apache.org/licenses/LICENSE-2.0
 13%% 
 14%% Unless required by applicable law or agreed to in writing, software
 15%% distributed under the License is distributed on an "AS IS" BASIS,
 16%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 17%% See the License for the specific language governing permissions and
 18%% limitations under the License.
 19
 20-module(module_name).
 21-author("Marc Worrell <marc@worrell.nl>").
 22-behaviour(gen_server).
 23
 24%% gen_server exports
 25-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
 26-export([start_link/0, start_link/1]).
 27
 28%% interface functions
 29-export([
 30]).
 31
 32%%====================================================================
 33%% API
 34%%====================================================================
 35%% @spec start_link() -> {ok,Pid} | ignore | {error,Error}
 36%% @doc Starts the server
 37start_link() -> 
 38    start_link([]).
 39start_link(Args) when is_list(Args) ->
 40    gen_server:start_link({local, ?MODULE}, ?MODULE, Args, []).
 41
 42%%====================================================================
 43%% gen_server callbacks
 44%%====================================================================
 45
 46%% @spec init(Args) -> {ok, State} |
 47%%                     {ok, State, Timeout} |
 48%%                     ignore               |
 49%%                     {stop, Reason}
 50%% @doc Initiates the server.
 51init(_Args) ->
 52    {ok, []}.
 53
 54%% @spec handle_call(Request, From, State) -> {reply, Reply, State} |
 55%%                                      {reply, Reply, State, Timeout} |
 56%%                                      {noreply, State} |
 57%%                                      {noreply, State, Timeout} |
 58%%                                      {stop, Reason, Reply, State} |
 59%%                                      {stop, Reason, State}
 60%% Description: Handling call messages
 61%% @doc Trap unknown calls
 62handle_call(Message, _From, State) ->
 63    {stop, {unknown_call, Message}, State}.
 64
 65
 66%% @spec handle_cast(Msg, State) -> {noreply, State} |
 67%%                                  {noreply, State, Timeout} |
 68%%                                  {stop, Reason, State}
 69%% @doc Trap unknown casts
 70handle_cast(Message, State) ->
 71    {stop, {unknown_cast, Message}, State}.
 72
 73
 74
 75%% @spec handle_info(Info, State) -> {noreply, State} |
 76%%                                       {noreply, State, Timeout} |
 77%%                                       {stop, Reason, State}
 78%% @doc Handling all non call/cast messages
 79handle_info(_Info, State) ->
 80    {noreply, State}.
 81
 82%% @spec terminate(Reason, State) -> void()
 83%% @doc This function is called by a gen_server when it is about to
 84%% terminate. It should be the opposite of Module:init/1 and do any necessary
 85%% cleaning up. When it returns, the gen_server terminates with Reason.
 86%% The return value is ignored.
 87terminate(_Reason, _State) ->
 88    ok.
 89
 90%% @spec code_change(OldVsn, State, Extra) -> {ok, NewState}
 91%% @doc Convert process state when code is changed
 92
 93code_change(_OldVsn, State, _Extra) ->
 94    {ok, State}.
 95
 96
 97%%====================================================================
 98%% support functions
 99%%====================================================================
100