configure.ac: Move OpenAL to Audio Output Plugins (nonstreaming), add header.
[mpd-mk.git] / src / update_remove.c
blobf7c2342a230823dc730840edbdb1926769a4018e
1 /*
2 * Copyright (C) 2003-2010 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "config.h" /* must be first for large file support */
21 #include "update_internal.h"
22 #include "notify.h"
23 #include "event_pipe.h"
24 #include "song.h"
25 #include "playlist.h"
27 #ifdef ENABLE_SQLITE
28 #include "sticker.h"
29 #include "song_sticker.h"
30 #endif
32 #include <glib.h>
34 #include <assert.h>
36 static const struct song *removed_song;
38 static struct notify remove_notify;
40 /**
41 * Safely remove a song from the database. This must be done in the
42 * main task, to be sure that there is no pointer left to it.
44 static void
45 song_remove_event(void)
47 char *uri;
49 assert(removed_song != NULL);
51 uri = song_get_uri(removed_song);
52 g_debug("removing: %s", uri);
53 g_free(uri);
55 #ifdef ENABLE_SQLITE
56 /* if the song has a sticker, remove it */
57 if (sticker_enabled())
58 sticker_song_delete(removed_song);
59 #endif
61 playlist_delete_song(&g_playlist, removed_song);
62 removed_song = NULL;
64 notify_signal(&remove_notify);
67 void
68 update_remove_global_init(void)
70 notify_init(&remove_notify);
72 event_pipe_register(PIPE_EVENT_DELETE, song_remove_event);
75 void
76 update_remove_global_finish(void)
78 notify_deinit(&remove_notify);
81 void
82 update_remove_song(const struct song *song)
84 assert(removed_song == NULL);
86 removed_song = song;
88 event_pipe_emit(PIPE_EVENT_DELETE);
90 do {
91 notify_wait(&remove_notify);
92 } while (removed_song != NULL);