aboutsummaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2010-10-14 02:56:32 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2010-10-14 02:56:32 +0200
commit9b5db7ab37a4a2527d523ff39bb0c5525553119e (patch)
tree8b89f91f02bc589e14a911f294513d4a351494a1 /client
parentb29dda5113a994d2ad18f9e6048d9b69c91a79c7 (diff)
downloaderlang-9b5db7ab37a4a2527d523ff39bb0c5525553119e.tar.gz
erlang-9b5db7ab37a4a2527d523ff39bb0c5525553119e.tar.xz
erlang-9b5db7ab37a4a2527d523ff39bb0c5525553119e.zip
progress
server is working somehow...
Diffstat (limited to 'client')
-rw-r--r--client/client.erl85
1 files changed, 35 insertions, 50 deletions
diff --git a/client/client.erl b/client/client.erl
index f8d5de2..d0bae4c 100644
--- a/client/client.erl
+++ b/client/client.erl
@@ -1,5 +1,19 @@
-module(client).
--export([register/3, login/3, list/0, handle/3]).
+-export([register/3, login/3, list/0, handle/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}).
buildNode(Server) ->
list_to_atom("distributed_music_system_main_node@" ++ Server).
@@ -13,24 +27,21 @@ register(Server, Name, Password) ->
{_, ok, Msg} ->
Msg;
{_, error, Msg} ->
- Msg
+ {error, Msg}
end.
login(Server, Name, Password) ->
+ code:purge(server),
+ code:load_abs("../common/server"),
+
try checkLogin(false) of
_ ->
- rpc(Server, login, [self(), {Name, Password}]),
+ rpc(Server, login, [self(), {node(), Name, Password}]),
receive
- {_, ok, {ok, {logged_in, Client}}} ->
- code:purge(server),
- code:load_abs("../common/server"),
- case server:start(cli, client, Client) of
- true ->
- {ok, logged_in};
- _ ->
- {error, unable_to_login}
- end;
- {_, error, Msg} ->
+ {_, ok, {ok, {logged_in, {Pid, _}}}} ->
+ server:registration(Pid, cli),
+ {ok, logged_in};
+ {_, _, Msg} ->
Msg;
Msg ->
Msg
@@ -40,52 +51,26 @@ login(Server, Name, Password) ->
{error, logged_in}
end.
-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}).
-
list() ->
try checkLogin(true) of
_ ->
- cli ! {self(), list},
- receive
- {_, ok, Msg} ->
- Msg;
- {_, error, Msg} ->
- {error, Msg};
- Msg ->
- {error, Msg}
- end
+ server:rpc(cli, list)
catch
{error, login_state} ->
{error, not_logged_in}
end.
-handle(Cli, list, Client) ->
- Client ! {list},
+handle(list, Server) ->
+ Server ! list,
receive
- {_, {ok, List}} ->
- io:format("List: ~w~n", List),
- {{ok}, Client}
+ {ok, Msg} ->
+ {Msg, Server};
+ Msg ->
+ {Msg, Server}
end;
-handle(Cli, {test, X}, Client) ->
- Client ! {X},
- receive
- Msg ->
- io:format("Test: ~w~n~n", [Msg]),
- {{ok}, Client}
- end;
+handle({change_state, NewState}, _) ->
+ {{ok}, NewState};
-handle(_, Cmd, Client) ->
- {{error, {unknown_command, Cmd}}, Client}.
+handle(Cmd, Server) ->
+ {{error, {unknown_command, Cmd}}, Server}.