2015-08-06 22:10:25 +02:00
|
|
|
/*
|
2021-01-01 19:54:25 +01:00
|
|
|
* Copyright 2003-2021 The Music Player Daemon Project
|
2015-08-06 22:10:25 +02:00
|
|
|
* 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 "Response.hxx"
|
|
|
|
#include "Client.hxx"
|
|
|
|
|
2021-05-21 20:35:29 +02:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
2017-02-07 16:52:59 +01:00
|
|
|
TagMask
|
2017-06-04 13:09:11 +02:00
|
|
|
Response::GetTagMask() const noexcept
|
2017-02-07 16:52:59 +01:00
|
|
|
{
|
|
|
|
return GetClient().tag_mask;
|
|
|
|
}
|
|
|
|
|
2015-08-06 22:10:25 +02:00
|
|
|
bool
|
2019-04-03 21:38:09 +02:00
|
|
|
Response::Write(const void *data, size_t length) noexcept
|
2015-08-06 22:10:25 +02:00
|
|
|
{
|
|
|
|
return client.Write(data, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-04-03 21:38:09 +02:00
|
|
|
Response::Write(const char *data) noexcept
|
2015-08-06 22:10:25 +02:00
|
|
|
{
|
2016-04-12 22:32:35 +02:00
|
|
|
return client.Write(data);
|
2015-08-06 22:10:25 +02:00
|
|
|
}
|
|
|
|
|
2021-05-21 20:35:29 +02:00
|
|
|
bool
|
|
|
|
Response::VFmt(fmt::string_view format_str, fmt::format_args args) noexcept
|
|
|
|
{
|
|
|
|
fmt::memory_buffer buffer;
|
|
|
|
fmt::vformat_to(buffer, format_str, args);
|
|
|
|
return Write(buffer.data(), buffer.size());
|
|
|
|
}
|
|
|
|
|
2019-08-12 14:17:35 +02:00
|
|
|
bool
|
|
|
|
Response::WriteBinary(ConstBuffer<void> payload) noexcept
|
|
|
|
{
|
2021-01-21 16:27:52 +01:00
|
|
|
assert(payload.size <= client.binary_limit);
|
2019-08-12 20:10:37 +02:00
|
|
|
|
2021-05-19 18:04:55 +02:00
|
|
|
return
|
2021-05-21 20:35:29 +02:00
|
|
|
Fmt("binary: {}\n", payload.size) &&
|
2019-08-12 14:17:35 +02:00
|
|
|
Write(payload.data, payload.size) &&
|
|
|
|
Write("\n");
|
|
|
|
}
|
|
|
|
|
2015-08-06 22:10:25 +02:00
|
|
|
void
|
2019-04-03 21:38:09 +02:00
|
|
|
Response::Error(enum ack code, const char *msg) noexcept
|
2015-08-06 22:10:25 +02:00
|
|
|
{
|
2021-05-25 16:11:35 +02:00
|
|
|
FmtError(code, FMT_STRING("{}"), msg);
|
2015-08-06 22:10:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-05-25 16:11:35 +02:00
|
|
|
Response::VFmtError(enum ack code,
|
|
|
|
fmt::string_view format_str, fmt::format_args args) noexcept
|
2015-08-06 22:10:25 +02:00
|
|
|
{
|
2021-05-27 15:03:12 +02:00
|
|
|
Fmt(FMT_STRING("ACK [{}@{}] {{{}}} "),
|
|
|
|
(int)code, list_index, command);
|
2015-08-14 18:57:44 +02:00
|
|
|
|
2021-05-25 16:11:35 +02:00
|
|
|
VFmt(format_str, std::move(args));
|
2015-08-14 18:57:44 +02:00
|
|
|
|
|
|
|
Write("\n");
|
2015-08-06 22:10:25 +02:00
|
|
|
}
|