~ubuntu-branches/ubuntu/utopic/mpd/utopic-proposed

« back to all changes in this revision

Viewing changes to src/update_remove.c

  • Committer: Package Import Robot
  • Author(s): Steve Kowalik
  • Date: 2013-11-12 18:17:40 UTC
  • mfrom: (2.2.36 sid)
  • Revision ID: package-import@ubuntu.com-20131112181740-72aa4zihehoobedp
Tags: 0.18.3-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Add libmp3lame-dev to Build-Depends, and enable LAME.
  - Read the user for the daemon from the config file in the init script.
  - Move avahi-daemon from Suggests to Recommends.
  - Added apport hook to include user configuration file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2003-2011 The Music Player Daemon Project
3
 
 * http://www.musicpd.org
4
 
 *
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.
9
 
 *
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.
14
 
 *
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.
18
 
 */
19
 
 
20
 
#include "config.h" /* must be first for large file support */
21
 
#include "update_remove.h"
22
 
#include "event_pipe.h"
23
 
#include "song.h"
24
 
#include "playlist.h"
25
 
#include "main.h"
26
 
 
27
 
#ifdef ENABLE_SQLITE
28
 
#include "sticker.h"
29
 
#include "song_sticker.h"
30
 
#endif
31
 
 
32
 
#include <glib.h>
33
 
 
34
 
#include <assert.h>
35
 
 
36
 
static const struct song *removed_song;
37
 
 
38
 
static GMutex *remove_mutex;
39
 
static GCond *remove_cond;
40
 
 
41
 
/**
42
 
 * Safely remove a song from the database.  This must be done in the
43
 
 * main task, to be sure that there is no pointer left to it.
44
 
 */
45
 
static void
46
 
song_remove_event(void)
47
 
{
48
 
        char *uri;
49
 
 
50
 
        assert(removed_song != NULL);
51
 
 
52
 
        uri = song_get_uri(removed_song);
53
 
        g_message("removing %s", uri);
54
 
        g_free(uri);
55
 
 
56
 
#ifdef ENABLE_SQLITE
57
 
        /* if the song has a sticker, remove it */
58
 
        if (sticker_enabled())
59
 
                sticker_song_delete(removed_song);
60
 
#endif
61
 
 
62
 
        playlist_delete_song(&g_playlist, global_player_control, removed_song);
63
 
 
64
 
        /* clear "removed_song" and send signal to update thread */
65
 
        g_mutex_lock(remove_mutex);
66
 
        removed_song = NULL;
67
 
        g_cond_signal(remove_cond);
68
 
        g_mutex_unlock(remove_mutex);
69
 
}
70
 
 
71
 
void
72
 
update_remove_global_init(void)
73
 
{
74
 
        remove_mutex = g_mutex_new();
75
 
        remove_cond = g_cond_new();
76
 
 
77
 
        event_pipe_register(PIPE_EVENT_DELETE, song_remove_event);
78
 
}
79
 
 
80
 
void
81
 
update_remove_global_finish(void)
82
 
{
83
 
        g_mutex_free(remove_mutex);
84
 
        g_cond_free(remove_cond);
85
 
}
86
 
 
87
 
void
88
 
update_remove_song(const struct song *song)
89
 
{
90
 
        assert(removed_song == NULL);
91
 
 
92
 
        removed_song = song;
93
 
 
94
 
        event_pipe_emit(PIPE_EVENT_DELETE);
95
 
 
96
 
        g_mutex_lock(remove_mutex);
97
 
 
98
 
        while (removed_song != NULL)
99
 
                g_cond_wait(remove_cond, remove_mutex);
100
 
 
101
 
        g_mutex_unlock(remove_mutex);
102
 
}