aboutsummaryrefslogtreecommitdiffstats
path: root/client/client.erl
diff options
context:
space:
mode:
authorJakob Pfender <jpfender@zedat.fu-berlin.de>2010-10-14 16:34:44 +0200
committerJakob Pfender <jpfender@zedat.fu-berlin.de>2010-10-14 16:34:44 +0200
commita53e0ebbf1e466abd0fce29688eb4112e7e6bff5 (patch)
tree4bcb80aa32bec556d717e3338e6d96e32d4ba989 /client/client.erl
parent83c76ed4f695dfd033308c663024f7a7e51c13e2 (diff)
parent3ab5da8355e114953c154114aa4c0c36b719e92e (diff)
downloaderlang-a53e0ebbf1e466abd0fce29688eb4112e7e6bff5.tar.gz
erlang-a53e0ebbf1e466abd0fce29688eb4112e7e6bff5.tar.xz
erlang-a53e0ebbf1e466abd0fce29688eb4112e7e6bff5.zip
documentation for media.erl
Diffstat (limited to 'client/client.erl')
-rw-r--r--client/client.erl51
1 files changed, 20 insertions, 31 deletions
diff --git a/client/client.erl b/client/client.erl
index 46ef59f..0e2fada 100644
--- a/client/client.erl
+++ b/client/client.erl
@@ -1,19 +1,15 @@
-module(client).
-export([register/3, login/3, list/0, handle/2, getVotes/0, vote/2, devote/2]).
-contains([], _) ->
- false;
-contains([H|_], H) ->
- true;
-contains([_|T], Search) ->
- contains(T, Search).
-
checkLogin(Value) ->
- checkLogin(Value, contains(registered(), cli)).
-checkLogin(Value, Value) ->
- true;
-checkLogin(_, _) ->
- throw({error, login_state}).
+ %% check if user meets the requirements to be locked in or not by
+ %% locking in to the registered processes and check if the cli
+ %% process is registered
+ LoggedIn = lists:member(cli, registered()),
+ if LoggedIn == Value ->
+ true;
+ true -> throw({error, login_state})
+ end.
buildNode(Server) ->
list_to_atom("distributed_music_system_main_node@" ++ Server).
@@ -82,33 +78,26 @@ handle({change_state, NewState}, _) ->
handle(Cmd, Server) ->
{{error, {unknown_command, Cmd}}, Server}.
-%queries the server for the current votes this client possesses
-getVotes() ->
+try_logged_in_rpc(Rpc) ->
+ %% tries to execute an rpc for logged in user and returns error
+ %% message if user is not logged in
try checkLogin(true) of
_ ->
- server:rpc(cli, get_votes)
+ server:rpc(cli, Rpc)
catch
{error, login_state} ->
{error, not_logged_in}
end.
-%positive vote, increments the votes for {Artist, Title} by one
+getVotes() ->
+ %% queries the server for the current votes this client possesses
+ try_logged_in_rpc(get_votes).
+
vote(Artist, Title) ->
- try checkLogin(true) of
- _ ->
- server:rpc(cli, {vote, Artist, Title})
- catch
- {error, login_state} ->
- {error, not_logged_in}
- end.
+ %% positive vote, increments the votes for {Artist, Title} by one
+ try_logged_in_rpc({vote, Artist, Title}).
-%negative vote, decrements the votes for {Artist, Title} by one
devote(Artist, Title) ->
- try checkLogin(true) of
- _ ->
- server:rpc(cli, {devote, Artist, Title})
- catch
- {error, login_state} ->
- {error, not_logged_in}
- end.
+ %% negative vote, decrements the votes for {Artist, Title} by one
+ try_logged_in_rpc({devote, Artist, Title}).