From 6054521e117539d2a5d16f08a6b107e13c9dc370 Mon Sep 17 00:00:00 2001 From: Marco Ziener Date: Thu, 14 Oct 2010 15:47:04 +0200 Subject: Cleaned --- server/cldb.erl | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'server') diff --git a/server/cldb.erl b/server/cldb.erl index 0f9f407..9aad688 100644 --- a/server/cldb.erl +++ b/server/cldb.erl @@ -10,3 +10,14 @@ init() -> mnesia:create_table(track, [{attributes, record_info(fields, track)}]), io:format("Userdb up and running \n"). + +ask(User, Pwd) -> + F = fun() -> + mnesia:match_object({user, User, Pwd, _}), + end, + + + +login(User, Pwd) -> + {_, Reason} = ask(User, Pwd), + Reason. -- cgit v1.2.3 From e25c2d52d30bc1c0c68612ff48a2cd889631f937 Mon Sep 17 00:00:00 2001 From: Michael Wittig Date: Thu, 14 Oct 2010 15:48:48 +0200 Subject: maaaaaan fertig werden --- server/media.erl | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'server') diff --git a/server/media.erl b/server/media.erl index fbdaa7e..561a2c7 100644 --- a/server/media.erl +++ b/server/media.erl @@ -1,5 +1,5 @@ -module(media). --export([init/0,insert/3, ask/2, all/0, play/3, vote/2, devote/2, lock_process/2]). +-export([init/0,insert/3, ask/2, all/0, play/2, vote/2, devote/2, lock_process/2]). -define(TESTPATTERN, "../ac/*.mp3"). -define(TIMEOUT, 100000000). @@ -68,7 +68,7 @@ search_best([], _, Track) -> {Track#track.artist, Track#track.title}. % if nothing is playable anymore just reset them and start playing again... -reset_all([Head|Rest) -> +reset_all([Head|Rest]) -> unlock(Head#track.artist, Head#track.title), reset_all(Rest); reset_all([]) -> ok. @@ -100,7 +100,7 @@ play(Artist, Title) -> {_, Title, Artist, _, _, Fp} = Head, Port = erlang:open_port({spawn_executable, "/usr/bin/mplayer"}, [{args, [Fp]}, exit_status]), reset_votes(Artist, Title), - lock_process(Artist, Title), + spawn(media, lock_process, [Artist, Title]), io:format("playing: ~s, Artist: ~s~n", [Title, Artist]), receive @@ -143,8 +143,7 @@ reset_votes(Artist, Title) -> lock(Artist, Title) -> F = fun() -> [Head|_] = ask(Artist, Title), - Votes = Head#track.lock = true, - New = Head#track{lock = Votes}, + New = Head#track{locked = true}, mnesia:write(New) end, mnesia:transaction(F). @@ -152,8 +151,7 @@ lock(Artist, Title) -> unlock(Artist, Title) -> F = fun() -> [Head|_] = ask(Artist, Title), - Votes = Head#track.lock = false, - New = Head#track{lock = Votes}, + New = Head#track{locked = false}, mnesia:write(New) end, mnesia:transaction(F). -- cgit v1.2.3 From be34a99dbb4e516d7592d6a19d0c662b6d81ab17 Mon Sep 17 00:00:00 2001 From: Marco Ziener Date: Thu, 14 Oct 2010 15:52:57 +0200 Subject: Blub --- server/cldb.erl | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'server') diff --git a/server/cldb.erl b/server/cldb.erl index 9aad688..6f6f4d2 100644 --- a/server/cldb.erl +++ b/server/cldb.erl @@ -2,22 +2,31 @@ -module(cldb). -export([init/0]). --record(user, {name, passwd, votes}). +-record(user, {name, passwd, votes, rights}). init() -> mnesia:create_schema([node()]), mnesia:start(), - mnesia:create_table(track, [{attributes, record_info(fields, track)}]), + mnesia:create_table(user, [{attributes, record_info(fields, user)}]), io:format("Userdb up and running \n"). - ask(User, Pwd) -> F = fun() -> - mnesia:match_object({user, User, Pwd, _}), + mnesia:match_object({user, User, Pwd, '_'}) end, + mnesia:transaction(F). login(User, Pwd) -> {_, Reason} = ask(User, Pwd), Reason. + +register(User, Pwd, Root) -> + F = fun() -> + mnesia:write(#user{name = User, passwd = Pwd, votes = 5, rights = Root}) + end, + {_, Reason} = mnesia:transaction(F), + Reason. + + -- cgit v1.2.3 From 4ce4e290a0557e616650ddb004f70cff2082e757 Mon Sep 17 00:00:00 2001 From: Michael Wittig Date: Thu, 14 Oct 2010 15:59:37 +0200 Subject: next one --- server/media.erl | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'server') diff --git a/server/media.erl b/server/media.erl index 561a2c7..165338b 100644 --- a/server/media.erl +++ b/server/media.erl @@ -55,7 +55,11 @@ insert(Artist, Title, Filepath) -> end, mnesia:transaction(F). -% search the track with the highest votes and return {Artist, Title} +% Of course we need a query to find out whats actually the most wished for track. +% We will do it by requesting all the records from the database and then iteramte over just taking a look at the vote +% variable, so it is like list of integers. In case no tracks were voted for we just take the first track we find and play it. +% Of course it is locked afterwards so another will be choosen. + search_best([Head|Rest], Max_Votes, Track) -> if @@ -107,11 +111,7 @@ play(Artist, Title) -> {Port, {exit_status, 0}} -> start_playing(); {Port, {exit_status, S}} -> throw({commandfailed, S}) end. - - -% Of course we need a query to find out whats actually the most wished for track. -% We will do it by requesting all the records from the database and then iteramte over just taking a look at the vote -% variable, so it is like list of integers. In case no tracks were voted for we just take the first track we find and play it. Of course it is locked afterwards so another will be choosen. +%Increase the vote in the database so it will hopefully be played in the future vote(Artist, Title) -> F = fun() -> @@ -122,6 +122,8 @@ vote(Artist, Title) -> end, mnesia:transaction(F). +% decrease votes in database + devote(Artist, Title) -> F = fun() -> [Head|_] = ask(Artist, Title), @@ -131,6 +133,8 @@ devote(Artist, Title) -> end, mnesia:transaction(F). +% Reset votes to zero in database + reset_votes(Artist, Title) -> F = fun() -> [Head|_] = ask(Artist, Title), @@ -139,6 +143,7 @@ reset_votes(Artist, Title) -> end, mnesia:transaction(F). +% Lock a song lock(Artist, Title) -> F = fun() -> @@ -148,6 +153,8 @@ lock(Artist, Title) -> end, mnesia:transaction(F). +% Unlock a song... + unlock(Artist, Title) -> F = fun() -> [Head|_] = ask(Artist, Title), @@ -156,6 +163,9 @@ unlock(Artist, Title) -> end, mnesia:transaction(F). +% Lock a song if it was just played, after a Timeout it will be unlocked automaticly +% If all songs are locked, all will be unlocked. + lock_process(Artist, Title) -> lock(Artist, Title), receive -- cgit v1.2.3 From d4974ca3ef2f4e664a78912837989762997d14dd Mon Sep 17 00:00:00 2001 From: Marco Ziener Date: Thu, 14 Oct 2010 16:03:19 +0200 Subject: Finished --- server/cldb.erl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'server') diff --git a/server/cldb.erl b/server/cldb.erl index 6f6f4d2..3886685 100644 --- a/server/cldb.erl +++ b/server/cldb.erl @@ -29,4 +29,22 @@ register(User, Pwd, Root) -> {_, Reason} = mnesia:transaction(F), Reason. +decVote(User, Pwd) -> + F = fun() -> + [Head|_] = ask(User, Pwd), + Votes = Head#user.votes - 1, + New = Head#user{votes = Votes}, + mnesia:write(New) + end, + mnesia:transaction(F). + +incVote(User, Pwd) -> + F = fun() -> + [Head|_] = ask(User, Pwd), + Votes = Head#user.votes + 1, + New = Head#user{votes = Votes}, + mnesia:write(New) + end, + mnesia:transaction(F). + -- cgit v1.2.3 From cfa125e96062c4ccabc155f68c36bc8bcf754b61 Mon Sep 17 00:00:00 2001 From: Marco Ziener Date: Thu, 14 Oct 2010 16:04:26 +0200 Subject: ... --- server/cldb.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server') diff --git a/server/cldb.erl b/server/cldb.erl index 3886685..176576c 100644 --- a/server/cldb.erl +++ b/server/cldb.erl @@ -1,7 +1,7 @@ % The clientdatabase -module(cldb). --export([init/0]). +-export([init/0, ask/2, login/2, decVote/2, incVote/2, register/3]). -record(user, {name, passwd, votes, rights}). init() -> -- cgit v1.2.3 From bde55a9f9456b7ab38b8ae35a3dc65cf4044aabe Mon Sep 17 00:00:00 2001 From: Marco Ziener Date: Thu, 14 Oct 2010 16:14:18 +0200 Subject: Rights Check --- server/cldb.erl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'server') diff --git a/server/cldb.erl b/server/cldb.erl index 176576c..982aafc 100644 --- a/server/cldb.erl +++ b/server/cldb.erl @@ -1,7 +1,7 @@ % The clientdatabase -module(cldb). --export([init/0, ask/2, login/2, decVote/2, incVote/2, register/3]). +-export([init/0, ask/2, login/2, decVote/2, incVote/2, register/3, check_rights/2]). -record(user, {name, passwd, votes, rights}). init() -> @@ -47,4 +47,7 @@ incVote(User, Pwd) -> end, mnesia:transaction(F). +check_rights(User, Name) -> + {_, _, Rights} = ask(User, Name), + Rights. -- cgit v1.2.3