aboutsummaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
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.