Add missing files

This commit is contained in:
Carlos Martín Nieto
2014-05-19 12:15:14 +02:00
parent 98b176c925
commit 29d468c90a
5 changed files with 238 additions and 0 deletions

122
src/geef_config.erl Normal file
View File

@@ -0,0 +1,122 @@
%%%-------------------------------------------------------------------
%%% @author Carlos Martín Nieto <cmn@dwim.me>
%%% @copyright (C) 2014, Carlos Martín Nieto
%%% @doc
%%%
%%% @end
%%% Created : 18 May 2014 by Carlos Martín Nieto <cmn@dwim.me>
%%%-------------------------------------------------------------------
-module(geef_config).
-behaviour(gen_server).
%% API
-export([start_link/1]).
-export([set/3]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
-define(SERVER, ?MODULE).
-record(state, {handle}).
%%%===================================================================
%%% API
%%%===================================================================
%%--------------------------------------------------------------------
%% @doc
%% Starts the server
%%
%% @spec start_link() -> {ok, Pid} | ignore | {error, Error}
%% @end
%%--------------------------------------------------------------------
start_link(Handle) ->
gen_server:start_link(?MODULE, Handle, []).
%% @doc Set a value in the configuration
set(Pid, Name, Val) when is_boolean(Val) ->
gen_server:call(Pid, {set_bool, Name, Val}).
%%%===================================================================
%%% gen_server callbacks
%%%===================================================================
%% @private
init(Handle) ->
{ok, #state{handle=Handle}}.
%%--------------------------------------------------------------------
%% @private
%% @doc
%% Handling call messages
%%
%% @spec handle_call(Request, From, State) ->
%% {reply, Reply, State} |
%% {reply, Reply, State, Timeout} |
%% {noreply, State} |
%% {noreply, State, Timeout} |
%% {stop, Reason, Reply, State} |
%% {stop, Reason, State}
%% @end
%%--------------------------------------------------------------------
handle_call({set_bool, Name, Val}, _From, State = #state{handle=Handle}) ->
Reply = geef_nif:config_set_bool(Handle, Name, Val),
{reply, Reply, State}.
%%--------------------------------------------------------------------
%% @private
%% @doc
%% Handling cast messages
%%
%% @spec handle_cast(Msg, State) -> {noreply, State} |
%% {noreply, State, Timeout} |
%% {stop, Reason, State}
%% @end
%%--------------------------------------------------------------------
handle_cast(_Msg, State) ->
{noreply, State}.
%%--------------------------------------------------------------------
%% @private
%% @doc
%% Handling all non call/cast messages
%%
%% @spec handle_info(Info, State) -> {noreply, State} |
%% {noreply, State, Timeout} |
%% {stop, Reason, State}
%% @end
%%--------------------------------------------------------------------
handle_info(_Info, State) ->
{noreply, State}.
%%--------------------------------------------------------------------
%% @private
%% @doc
%% This function is called by a gen_server when it is about to
%% terminate. It should be the opposite of Module:init/1 and do any
%% necessary cleaning up. When it returns, the gen_server terminates
%% with Reason. The return value is ignored.
%%
%% @spec terminate(Reason, State) -> void()
%% @end
%%--------------------------------------------------------------------
terminate(_Reason, _State) ->
ok.
%%--------------------------------------------------------------------
%% @private
%% @doc
%% Convert process state when code is changed
%%
%% @spec code_change(OldVsn, State, Extra) -> {ok, NewState}
%% @end
%%--------------------------------------------------------------------
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
%%%===================================================================
%%% Internal functions
%%%===================================================================

View File

@@ -209,6 +209,10 @@ revparse_single(_Handle, _Str) ->
config_set_bool(_Handle, _Name, _Val) ->
?NIF_FN.
-spec config_get_bool(term(), iolist()) -> {ok, boolean()} | {error, term()}.
config_get_bool(_Handle, _Name) ->
?NIF_FN.
nif_error(Line) ->
erlang:nif_error({nif_not_loaded,module,?MODULE,line,Line}).