Idle.cxx 1.5 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright (C) 2003-2014 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"
Max Kellermann's avatar
Max Kellermann committed
26
#include "Idle.hxx"
27
#include "GlobalEvents.hxx"
28

29 30
#include <atomic>

31 32
#include <assert.h>

33
static std::atomic_uint idle_flags;
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
	"neighbor",
48
	nullptr
49 50
};

51 52 53 54 55
void
idle_add(unsigned flags)
{
	assert(flags != 0);

56
	unsigned old_flags = idle_flags.fetch_or(flags);
57

58 59
	if ((old_flags & flags) != flags)
		GlobalEvents::Emit(GlobalEvents::IDLE);
60 61 62 63 64
}

unsigned
idle_get(void)
{
65
	return idle_flags.exchange(0);
66
}
67 68 69 70 71 72

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