aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2010-10-14 14:10:10 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2010-10-14 14:10:10 +0200
commite70fe72c584a8798f5bd7024949c32de5ce90aa0 (patch)
treecf18679e4b7b53bbd96fdf0f2885dd179ad3924e
parenta8e3e940706ebc9f4a9a6a26ed2273d7f73f7905 (diff)
downloaderlang-e70fe72c584a8798f5bd7024949c32de5ce90aa0.tar.gz
erlang-e70fe72c584a8798f5bd7024949c32de5ce90aa0.tar.xz
erlang-e70fe72c584a8798f5bd7024949c32de5ce90aa0.zip
implemented some functions on the server
-rw-r--r--server/client.erl46
1 files changed, 33 insertions, 13 deletions
diff --git a/server/client.erl b/server/client.erl
index ce7c99b..333df4a 100644
--- a/server/client.erl
+++ b/server/client.erl
@@ -10,32 +10,52 @@ start(Node) ->
case server:rpc(Client, {change_state, Server}) of
{ok} ->
{ok, Client};
- _ ->
- {error, unknown_error}
+ Why ->
+ {error, {unknown_error, Why}}
end.
loop(Client) ->
receive
list ->
- Client ! {ok, {foo}},
- loop(Client);
+ try media:all() of
+ Result ->
+ Client ! {ok, Result}
+ catch
+ _: Why ->
+ Client ! {error, Why}
+ end;
get_votes ->
- Client ! {ok, media:getVotes(Client)},
- loop(Client);
+ try media:getVotes(Client) of
+ Result ->
+ Client ! {ok, Result}
+ catch
+ _: Why ->
+ Client ! {error, Why}
+ end;
{vote, Artist, Title} ->
- Client ! media:vote(Artist, Title),
- loop(Client);
+ try media:vote(Artist, Title) of
+ Result ->
+ Client ! {ok, Result}
+ catch
+ _: Why ->
+ Client ! {error, Why}
+ end;
{devote, Artist, Title} ->
- Client ! media:devote(Artist, Title),
- loop(Client);
+ try media:devote(Artist, Title) of
+ Result ->
+ Client ! {ok, Result}
+ catch
+ _: Why ->
+ Client ! {error, Why}
+ end;
Cmd ->
- Client ! {error, {unknown_command, Cmd}},
- loop(Client)
- end.
+ Client ! {error, {unknown_command, Cmd}}
+ end,
+ loop(Client).
register(Client, {Name, Password}) ->
dis ! {Client, {register, {Name, Password}}}.