OutputCommands.cxx 2.2 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2017 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * http://www.musicpd.org
 *
 * 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.
 *
 * 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.
 */

#include "config.h"
#include "OutputCommands.hxx"
22
#include "Request.hxx"
23
#include "output/Print.hxx"
24
#include "output/OutputCommand.hxx"
25
#include "client/Client.hxx"
26
#include "client/Response.hxx"
27
#include "Partition.hxx"
28

29
CommandResult
30
handle_enableoutput(Client &client, Request args, Response &r)
31
{
32
	assert(args.size == 1);
33
	unsigned device = args.ParseUnsigned(0);
34

35
	if (!audio_output_enable_index(client.GetPartition().outputs, device)) {
36
		r.Error(ACK_ERROR_NO_EXIST, "No such audio output");
37
		return CommandResult::ERROR;
38 39
	}

40
	return CommandResult::OK;
41 42
}

43
CommandResult
44
handle_disableoutput(Client &client, Request args, Response &r)
45
{
46
	assert(args.size == 1);
47
	unsigned device = args.ParseUnsigned(0);
48

49
	if (!audio_output_disable_index(client.GetPartition().outputs, device)) {
50
		r.Error(ACK_ERROR_NO_EXIST, "No such audio output");
51
		return CommandResult::ERROR;
52 53
	}

54
	return CommandResult::OK;
55 56
}

57
CommandResult
58
handle_toggleoutput(Client &client, Request args, Response &r)
59
{
60
	assert(args.size == 1);
61
	unsigned device = args.ParseUnsigned(0);
62

63
	if (!audio_output_toggle_index(client.GetPartition().outputs, device)) {
64
		r.Error(ACK_ERROR_NO_EXIST, "No such audio output");
65
		return CommandResult::ERROR;
66 67
	}

68
	return CommandResult::OK;
69 70
}

71
CommandResult
72
handle_devices(Client &client, gcc_unused Request args, Response &r)
73
{
74 75
	assert(args.IsEmpty());

76
	printAudioDevices(r, client.GetPartition().outputs);
77
	return CommandResult::OK;
78
}