aboutsummaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2010-10-14 11:05:09 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2010-10-14 11:05:09 +0200
commit40d28960b17bfe6b09fabdcfc0555c9db9cd5971 (patch)
tree4f3f26ca45813caec004f7a9cc0594666617179c /client
parentb008056e15f165b8d51bfbd2b5a06f993b88a1a2 (diff)
downloaderlang-40d28960b17bfe6b09fabdcfc0555c9db9cd5971.tar.gz
erlang-40d28960b17bfe6b09fabdcfc0555c9db9cd5971.tar.xz
erlang-40d28960b17bfe6b09fabdcfc0555c9db9cd5971.zip
fixed errors
Diffstat (limited to 'client')
-rw-r--r--client/client.erl72
1 files changed, 50 insertions, 22 deletions
diff --git a/client/client.erl b/client/client.erl
index 67be4ee..aab0b4e 100644
--- a/client/client.erl
+++ b/client/client.erl
@@ -1,5 +1,5 @@
-module(client).
--export([register/3, login/3, list/0, handle/2]).
+-export([register/3, login/3, list/0, handle/2, getVotes/0, vote/2, devote/2]).
contains([], _) ->
false;
@@ -67,6 +67,33 @@ handle(list, Server) ->
{Msg, Server}
end;
+handle(get_votes, Server) ->
+ Server ! get_votes,
+ receive
+ {ok, Msg} ->
+ {Msg, Server};
+ Msg ->
+ {Msg, Server}
+ end;
+
+handle({vote, Artist, Title}, Server) ->
+ Server ! {vote, Artist, Title},
+ receive
+ {ok, Msg} ->
+ {Msg, Server};
+ Msg ->
+ {Msg, Server}
+ end;
+
+handle({devote, Artist, Title}, Server) ->
+ Server ! {vote, Artist, Title},
+ receive
+ {ok, Msg} ->
+ {Msg, Server};
+ Msg ->
+ {Msg, Server}
+ end;
+
handle({change_state, NewState}, _) ->
{{ok}, NewState};
@@ -74,31 +101,32 @@ handle(Cmd, Server) ->
{{error, {unknown_command, Cmd}}, Server}.
%queries the server for the current votes this client possesses
-getVotes(Server) ->
- rpc(Server, getVotes, self()),
- receive
- Msg ->
- Msg
- end.
+getVotes() ->
+ try checkLogin(true) of
+ _ ->
+ server:rpc(cli, get_votes)
+ catch
+ {error, login_state} ->
+ {error, not_logged_in}
+ end.
%positive vote, increments the votes for {Artist, Title} by one
vote(Artist, Title) ->
- rpc(Server, vote, [Artist, Title]),
- receive
- {_, ok, Msg} ->
- Msg;
- {_, error, Msg} ->
- {error, Msg}
- end.
+ try checkLogin(true) of
+ _ ->
+ server:rpc(cli, {vote, Artist, Title})
+ catch
+ {error, login_state} ->
+ {error, not_logged_in}
+ end.
%negative vote, decrements the votes for {Artist, Title} by one
devote(Artist, Title) ->
- rpc(Server, devote, [Artist, Title]),
- receive
- {_, ok, Msg} ->
- Msg;
- {_, error, Msg} ->
- {error, Msg}
- end.
-
+ try checkLogin(true) of
+ _ ->
+ server:rpc(cli, {devote, Artist, Title})
+ catch
+ {error, login_state} ->
+ {error, not_logged_in}
+ end.