idle.c 1.78 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright (C) 2003-2011 The Music Player Daemon Project
3
 * http://www.musicpd.org
4 5 6 7 8 9 10 11 12 13
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
14 15 16 17
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 19 20 21 22 23 24
 */

/*
 * Support library for the "idle" command.
 *
 */

25
#include "config.h"
26
#include "idle.h"
27
#include "event_pipe.h"
28 29

#include <assert.h>
30
#include <glib.h>
31 32

static unsigned idle_flags;
33
static GMutex *idle_mutex = NULL;
34

35 36 37 38 39 40 41 42
static const char *const idle_names[] = {
	"database",
	"stored_playlist",
	"playlist",
	"player",
	"mixer",
	"output",
	"options",
43
	"sticker",
44
	"update",
45 46
	"subscription",
	"message",
47 48 49
        NULL
};

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
void
idle_init(void)
{
	g_assert(idle_mutex == NULL);
	idle_mutex = g_mutex_new();
}

void
idle_deinit(void)
{
	g_assert(idle_mutex != NULL);
	g_mutex_free(idle_mutex);
	idle_mutex = NULL;
}

65 66 67 68 69
void
idle_add(unsigned flags)
{
	assert(flags != 0);

70
	g_mutex_lock(idle_mutex);
71
	idle_flags |= flags;
72
	g_mutex_unlock(idle_mutex);
73

74
	event_pipe_emit(PIPE_EVENT_IDLE);
75 76 77 78 79 80 81
}

unsigned
idle_get(void)
{
	unsigned flags;

82
	g_mutex_lock(idle_mutex);
83 84
	flags = idle_flags;
	idle_flags = 0;
85
	g_mutex_unlock(idle_mutex);
86 87 88

	return flags;
}
89 90 91 92 93 94

const char*const*
idle_get_names(void)
{
        return idle_names;
}