summaryrefslogtreecommitdiff
path: root/src/command
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2018-07-05 19:07:05 +0200
committerMax Kellermann <max@musicpd.org>2018-07-05 19:07:05 +0200
commit3d3a1232b1d2b58d2cc05b2dd5c37f2256832693 (patch)
tree250933da4d5dc29145ce18e5a05a7f8da30396fd /src/command
parent09d4176210d66cf9e2d258b563a7811892c560f4 (diff)
tag/Handler: convert to class with virtual methods
Diffstat (limited to 'src/command')
-rw-r--r--src/command/FileCommands.cxx28
-rw-r--r--src/command/OtherCommands.cxx27
2 files changed, 27 insertions, 28 deletions
diff --git a/src/command/FileCommands.cxx b/src/command/FileCommands.cxx
index 488c6a798..744db8619 100644
--- a/src/command/FileCommands.cxx
+++ b/src/command/FileCommands.cxx
@@ -137,25 +137,24 @@ IsValidValue(const char *p) noexcept
return true;
}
-static void
-print_pair(const char *key, const char *value, void *ctx)
-{
- auto &r = *(Response *)ctx;
+class PrintCommentHandler final : public NullTagHandler {
+ Response &response;
- if (IsValidName(key) && IsValidValue(value))
- r.Format("%s: %s\n", key, value);
-}
+public:
+ explicit PrintCommentHandler(Response &_response) noexcept
+ :NullTagHandler(WANT_PAIR), response(_response) {}
-static constexpr TagHandler print_comment_handler = {
- nullptr,
- nullptr,
- print_pair,
+ void OnPair(const char *key, const char *value) noexcept override {
+ if (IsValidName(key) && IsValidValue(value))
+ response.Format("%s: %s\n", key, value);
+ }
};
static CommandResult
read_stream_comments(Response &r, const char *uri)
{
- if (!tag_stream_scan(uri, print_comment_handler, &r)) {
+ PrintCommentHandler h(r);
+ if (!tag_stream_scan(uri, h)) {
r.Error(ACK_ERROR_NO_EXIST, "Failed to load file");
return CommandResult::ERROR;
}
@@ -167,12 +166,13 @@ read_stream_comments(Response &r, const char *uri)
static CommandResult
read_file_comments(Response &r, const Path path_fs)
{
- if (!tag_file_scan(path_fs, print_comment_handler, &r)) {
+ PrintCommentHandler h(r);
+ if (!tag_file_scan(path_fs, h)) {
r.Error(ACK_ERROR_NO_EXIST, "Failed to load file");
return CommandResult::ERROR;
}
- ScanGenericTags(path_fs, print_comment_handler, &r);
+ ScanGenericTags(path_fs, h);
return CommandResult::OK;
diff --git a/src/command/OtherCommands.cxx b/src/command/OtherCommands.cxx
index b748ce2ff..b08468aca 100644
--- a/src/command/OtherCommands.cxx
+++ b/src/command/OtherCommands.cxx
@@ -93,15 +93,6 @@ handle_kill(gcc_unused Client &client, gcc_unused Request request,
return CommandResult::KILL;
}
-static void
-print_tag(TagType type, const char *value, void *ctx)
-{
- auto &r = *(Response *)ctx;
-
- if (r.GetClient().tag_mask.Test(type))
- tag_print(r, type, value);
-}
-
CommandResult
handle_listfiles(Client &client, Request args, Response &r)
{
@@ -149,16 +140,24 @@ handle_listfiles(Client &client, Request args, Response &r)
gcc_unreachable();
}
-static constexpr TagHandler print_tag_handler = {
- nullptr,
- print_tag,
- nullptr,
+class PrintTagHandler final : public NullTagHandler {
+ Response &response;
+
+public:
+ explicit PrintTagHandler(Response &_response) noexcept
+ :NullTagHandler(WANT_TAG), response(_response) {}
+
+ void OnTag(TagType type, const char *value) noexcept override {
+ if (response.GetClient().tag_mask.Test(type))
+ tag_print(response, type, value);
+ }
};
static CommandResult
handle_lsinfo_absolute(Response &r, const char *uri)
{
- if (!tag_stream_scan(uri, print_tag_handler, &r)) {
+ PrintTagHandler h(r);
+ if (!tag_stream_scan(uri, h)) {
r.Error(ACK_ERROR_NO_EXIST, "No such file");
return CommandResult::ERROR;
}