aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakob Pfender <jpfender@zedat.fu-berlin.de>2010-10-14 10:30:13 +0200
committerJakob Pfender <jpfender@zedat.fu-berlin.de>2010-10-14 10:30:13 +0200
commit37a33b4ef3a8d9c4a1b984e44bfe5be03525c302 (patch)
treee934bba4f1d652df02f099a8df07715cfe744679
parent9b5db7ab37a4a2527d523ff39bb0c5525553119e (diff)
downloaderlang-37a33b4ef3a8d9c4a1b984e44bfe5be03525c302.tar.gz
erlang-37a33b4ef3a8d9c4a1b984e44bfe5be03525c302.tar.xz
erlang-37a33b4ef3a8d9c4a1b984e44bfe5be03525c302.zip
client-side voting
-rw-r--r--client/client.erl30
-rw-r--r--server/client.erl13
2 files changed, 43 insertions, 0 deletions
diff --git a/client/client.erl b/client/client.erl
index d0bae4c..a287af3 100644
--- a/client/client.erl
+++ b/client/client.erl
@@ -74,3 +74,33 @@ handle({change_state, NewState}, _) ->
handle(Cmd, Server) ->
{{error, {unknown_command, Cmd}}, Server}.
+
+%queries the server for the current votes this client possesses
+getVotes() ->
+ rpc(Server, getVotes, self()),
+ receive
+ Msg ->
+ Msg
+ 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.
+
+%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.
+
+
diff --git a/server/client.erl b/server/client.erl
index 31d382f..61260b4 100644
--- a/server/client.erl
+++ b/server/client.erl
@@ -30,3 +30,16 @@ register(Client, {Name, Password}) ->
login(Client, {Node, Name, Password}) ->
dis ! {Client, {login, {Node, Name, Password}}}.
+
+getVotes() ->
+ media:getVotes(self()),
+ receive
+ Msg ->
+ Client ! Msg
+ end.
+
+vote(Artist,Title) ->
+ media:vote(Artist, Title).
+
+devote(Artist,Title) ->
+ media:devote(Artist, Title).