aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorMarco Ziener <mziener@lavabit.com>2010-10-14 14:22:02 +0200
committerMarco Ziener <mziener@lavabit.com>2010-10-14 14:22:02 +0200
commit181245f3cf74febd231d8072a8f1f8f038b0ee31 (patch)
tree89d281975e22e173350d7aa95ca3e14ebe7711ff /server
parent10419216d9c2c3d71997229d605df9321a94c113 (diff)
downloaderlang-181245f3cf74febd231d8072a8f1f8f038b0ee31.tar.gz
erlang-181245f3cf74febd231d8072a8f1f8f038b0ee31.tar.xz
erlang-181245f3cf74febd231d8072a8f1f8f038b0ee31.zip
Additional Serverfu
Diffstat (limited to 'server')
-rw-r--r--server/media.erl38
1 files changed, 32 insertions, 6 deletions
diff --git a/server/media.erl b/server/media.erl
index fb1d951..1463715 100644
--- a/server/media.erl
+++ b/server/media.erl
@@ -1,6 +1,7 @@
-module(media).
-export([init/0,insert/3, ask/2, all/0, play/3, vote/2, devote/2]).
-define(TESTPATTERN, "../ac/*.mp3").
+-define(TIMEOUT, 10000).
% Since we are not willing to calculate and deliver all the id3 tags everytime they are requested,
% we try to get something persistent with mnesia.
@@ -19,10 +20,11 @@
init() ->
mnesia:create_schema([node()]),
mnesia:start(),
- mnesia:create_table(track, [{index, [y]}, {attributes, record_info(fields, track)}]),
+ mnesia:create_table(track, [{attributes, record_info(fields, track)}]),
read_files(filelib:wildcard(?TESTPATTERN),0,0),
io:format("Initialisation of mnesia successful.\n"),
- start_playing().
+ start_playing(),
+ io:format("Starting to play music\n").
read_files([FN|Rest],Total,Fail) ->
case id3v2:read_file(FN) of
@@ -35,15 +37,17 @@ read_files([FN|Rest],Total,Fail) ->
end;
read_files([],Total,Fail) -> io:format("Total: ~w, Failed: ~w~n", [Total, Fail]).
-% Basic insertion of entrys into the database. Some entries are left out because they are 0 or false.
+
% Our Runloop to play music all the time, play waits on exit_status
+
start_playing() ->
{Artist, Title} = search_best(media:all(), 0,0),
play(Artist, Title, "muh").
-%insert The Track into the database
+% Basic insertion of entrys into the database. Some entries are left out because they are 0 or false.
+
insert(Artist, Title, Filepath) ->
F = fun() ->
mnesia:write(#track{artist = Artist, title = Title, votes = 0, locked = false, filepath = Filepath})
@@ -115,5 +119,27 @@ devote(Artist, Title) ->
end,
mnesia:transaction(F).
-top() ->
- All = all().
+lock(Artist, Title) ->
+ F = fun() ->
+ [Head|_] = ask(Artist, Title),
+ Votes = Head#track.votes -1,
+ New = Head#track(votes = Votes),
+ mnesia:write(New),
+ end,
+ mnesia:transaction(F).
+
+unlock(Artist, Title) ->
+ F = fun() ->
+ [Head|_] = ask(Artist, Title),
+ Votes = Head#track.votes -1,
+ New = Head#track{votes = Votes},
+ mnesia:write(New),
+ end,
+ mnesia:transaction(F).
+
+lock_prozess(Artist, Title) ->
+ lock(Artist, Title),
+ receive
+ after TIMEOUT unlock(Artist, Title).
+
+