From ebbf2038b2e131cc43eae1d4c98fbd6efb548f0a Mon Sep 17 00:00:00 2001 From: Jakob Pfender Date: Fri, 15 Oct 2010 10:44:30 +0200 Subject: documentation for server/cldb.erl --- server/cldb.erl | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/server/cldb.erl b/server/cldb.erl index c294471..8d58fb4 100644 --- a/server/cldb.erl +++ b/server/cldb.erl @@ -1,10 +1,10 @@ -% The clientdatabase +%% The client database -module(cldb). -export([init/0, all/0, find/1, login/2, dec_vote/1, inc_vote/1, register/3, check_rights/1, update_votes/0, logout/1, set_client_pid/2, get_votes/1]). -record(user, {name, passwd, votes, logged_in, pid, rights}). -%% The initialisations of the mnesia database +%% Initialisation of the mnesia database init() -> mnesia:create_schema([node()]), mnesia:start(), @@ -41,7 +41,7 @@ find_user_by_pid(Pid) -> _ -> {error} end. -%% Retrieve all the entrys +%% Retrieve all entries all() -> F = fun() -> @@ -73,7 +73,7 @@ login(User, Pwd) when is_list(User) and is_list(Pwd) -> login(_, _) -> {error}. -%% Inorder to log out the client after his process died. +%% In order to log out the client after its process has died. set_client_pid(User, Pid) -> case find(User) of {atomic, [UserRow|_]} -> @@ -91,7 +91,7 @@ set_client_pid(User, Pid) -> {error, user_not_found} end. -%% Changing the database to log out a user by PID +%% Change the database to log out a user by PID logout(Pid) -> case find_user_by_pid(Pid) of {atomic, [UserRow|_]} -> @@ -109,9 +109,10 @@ logout(Pid) -> _ -> {error, invalid_user} end. -%% Makes an entry into the database for this user. -%% If he is already registerd an error will be returned. -%% In order to vote it is needed to login afterwards. + +%% Adds an entry into the database for this user. +%% If he is already registered, this will return an error. +%% In order to vote, users arer required to log in after registering. register(User, Pwd, Root) when is_list(User) and is_list(Pwd) -> case find(User) of {atomic, []} -> @@ -131,7 +132,7 @@ register(User, Pwd, Root) when is_list(User) and is_list(Pwd) -> register(_,_,_) -> {error, invalid_username}. -%% functions to de- and increment the amount of votes a user got left. +%% functions to de- and increment the amount of votes a user has left. dec_vote(User) when is_list(User) -> {atomic, [Head|_]} = find(User), if Head#user.votes > 0 -> @@ -156,13 +157,13 @@ inc_vote(User) -> end, mnesia:transaction(F). -%% Return rights of User (admin or nan). +%% Return rights of a user (admin or nan). check_rights(User) -> {atomic, [UserRow|_]} = find(User), UserRow#user.rights. update_votes() -> - %% after a song every logged_in client gets on more vote + %% after a song every logged in client gets one more vote to spend case find_logged_in_user() of {ok, List} -> give_votes(List); @@ -170,13 +171,13 @@ update_votes() -> end. %% Increment the votes of every user. -%% It will be called when a song has ended. +%% This is called when a song has ended. give_votes([User|Rest]) -> inc_vote(User#user.name), give_votes(Rest); give_votes([]) -> ok. -%% Returns the amount of votes from User. +%% Returns the amount of votes a specific user has. get_votes(User) -> case find(User) of {atomic, [UserRow|_]} -> -- cgit v1.2.3