2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2013-01-09 08:36:52 +01:00
|
|
|
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
2009-03-13 18:43:16 +01:00
|
|
|
* http://www.musicpd.org
|
2008-10-14 22:38:14 +02:00
|
|
|
*
|
|
|
|
* 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.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* 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.
|
2008-10-14 22:38:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Support library for the "idle" command.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "config.h"
|
2013-01-09 08:36:52 +01:00
|
|
|
#include "Idle.hxx"
|
2013-01-09 23:12:53 +01:00
|
|
|
#include "GlobalEvents.hxx"
|
2008-10-14 22:38:14 +02:00
|
|
|
|
2013-01-16 23:20:56 +01:00
|
|
|
#include <atomic>
|
|
|
|
|
2008-10-14 22:38:14 +02:00
|
|
|
#include <assert.h>
|
|
|
|
|
2013-01-16 23:20:56 +01:00
|
|
|
static std::atomic_uint idle_flags;
|
2008-10-14 22:38:14 +02:00
|
|
|
|
2008-11-22 13:26:21 +01:00
|
|
|
static const char *const idle_names[] = {
|
|
|
|
"database",
|
|
|
|
"stored_playlist",
|
|
|
|
"playlist",
|
|
|
|
"player",
|
|
|
|
"mixer",
|
|
|
|
"output",
|
|
|
|
"options",
|
2009-01-25 16:23:02 +01:00
|
|
|
"sticker",
|
2009-07-05 08:46:53 +02:00
|
|
|
"update",
|
2011-01-29 09:26:22 +01:00
|
|
|
"subscription",
|
|
|
|
"message",
|
2013-01-16 23:20:56 +01:00
|
|
|
nullptr
|
2008-11-22 13:26:21 +01:00
|
|
|
};
|
|
|
|
|
2008-10-14 22:38:14 +02:00
|
|
|
void
|
|
|
|
idle_add(unsigned flags)
|
|
|
|
{
|
|
|
|
assert(flags != 0);
|
|
|
|
|
2013-01-16 23:24:58 +01:00
|
|
|
unsigned old_flags = idle_flags.fetch_or(flags);
|
2008-10-14 22:38:14 +02:00
|
|
|
|
2013-01-16 23:24:58 +01:00
|
|
|
if ((old_flags & flags) != flags)
|
|
|
|
GlobalEvents::Emit(GlobalEvents::IDLE);
|
2008-10-14 22:38:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
idle_get(void)
|
|
|
|
{
|
2013-02-27 20:35:44 +01:00
|
|
|
return idle_flags.exchange(0);
|
2008-10-14 22:38:14 +02:00
|
|
|
}
|
2008-11-22 13:26:21 +01:00
|
|
|
|
|
|
|
const char*const*
|
|
|
|
idle_get_names(void)
|
|
|
|
{
|
|
|
|
return idle_names;
|
|
|
|
}
|