db/proxy: implement the group_mask parameter in VisitUniqueTags()
Closes #258
This commit is contained in:
parent
388768b3a6
commit
ac395429c3
1
NEWS
1
NEWS
|
@ -3,6 +3,7 @@ ver 0.20.19 (not yet released)
|
||||||
- validate absolute seek time, reject negative values
|
- validate absolute seek time, reject negative values
|
||||||
* database
|
* database
|
||||||
- proxy: fix "search already in progress" errors
|
- proxy: fix "search already in progress" errors
|
||||||
|
- proxy: implement "list ... group"
|
||||||
* input
|
* input
|
||||||
- mms: fix lockup bug and a crash bug
|
- mms: fix lockup bug and a crash bug
|
||||||
* decoder
|
* decoder
|
||||||
|
|
|
@ -325,6 +325,34 @@ SendConstraints(mpd_connection *connection, const DatabaseSelection &selection)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
SendGroupMask(mpd_connection *connection, tag_mask_t mask)
|
||||||
|
{
|
||||||
|
#if LIBMPDCLIENT_CHECK_VERSION(2,12,0)
|
||||||
|
for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i) {
|
||||||
|
if ((mask & (tag_mask_t(1) << i)) == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const auto tag = Convert(TagType(i));
|
||||||
|
if (tag == MPD_TAG_COUNT)
|
||||||
|
throw std::runtime_error("Unsupported tag");
|
||||||
|
|
||||||
|
if (!mpd_search_add_group_tag(connection, tag))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
#else
|
||||||
|
(void)connection;
|
||||||
|
(void)mask;
|
||||||
|
|
||||||
|
if (mask != 0)
|
||||||
|
throw std::runtime_error("Grouping requires libmpdclient 2.12");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
ProxyDatabase::ProxyDatabase(EventLoop &_loop, DatabaseListener &_listener,
|
ProxyDatabase::ProxyDatabase(EventLoop &_loop, DatabaseListener &_listener,
|
||||||
const ConfigBlock &block)
|
const ConfigBlock &block)
|
||||||
:Database(proxy_db_plugin),
|
:Database(proxy_db_plugin),
|
||||||
|
@ -761,7 +789,7 @@ ProxyDatabase::Visit(const DatabaseSelection &selection,
|
||||||
void
|
void
|
||||||
ProxyDatabase::VisitUniqueTags(const DatabaseSelection &selection,
|
ProxyDatabase::VisitUniqueTags(const DatabaseSelection &selection,
|
||||||
TagType tag_type,
|
TagType tag_type,
|
||||||
gcc_unused tag_mask_t group_mask,
|
tag_mask_t group_mask,
|
||||||
VisitTag visit_tag) const
|
VisitTag visit_tag) const
|
||||||
try {
|
try {
|
||||||
// TODO: eliminate the const_cast
|
// TODO: eliminate the const_cast
|
||||||
|
@ -772,32 +800,47 @@ try {
|
||||||
throw std::runtime_error("Unsupported tag");
|
throw std::runtime_error("Unsupported tag");
|
||||||
|
|
||||||
if (!mpd_search_db_tags(connection, tag_type2) ||
|
if (!mpd_search_db_tags(connection, tag_type2) ||
|
||||||
!SendConstraints(connection, selection))
|
!SendConstraints(connection, selection) ||
|
||||||
|
!SendGroupMask(connection, group_mask))
|
||||||
ThrowError(connection);
|
ThrowError(connection);
|
||||||
|
|
||||||
// TODO: use group_mask
|
|
||||||
|
|
||||||
if (!mpd_search_commit(connection))
|
if (!mpd_search_commit(connection))
|
||||||
ThrowError(connection);
|
ThrowError(connection);
|
||||||
|
|
||||||
while (auto *pair = mpd_recv_pair_tag(connection, tag_type2)) {
|
TagBuilder builder;
|
||||||
|
|
||||||
|
while (auto *pair = mpd_recv_pair(connection)) {
|
||||||
AtScopeExit(this, pair) {
|
AtScopeExit(this, pair) {
|
||||||
mpd_return_pair(connection, pair);
|
mpd_return_pair(connection, pair);
|
||||||
};
|
};
|
||||||
|
|
||||||
TagBuilder tag;
|
const auto current_type = tag_name_parse_i(pair->name);
|
||||||
tag.AddItem(tag_type, pair->value);
|
if (current_type == TAG_NUM_OF_ITEM_TYPES)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (tag.IsEmpty())
|
if (current_type == tag_type && !builder.IsEmpty()) {
|
||||||
|
try {
|
||||||
|
visit_tag(builder.Commit());
|
||||||
|
} catch (...) {
|
||||||
|
mpd_response_finish(connection);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.AddItem(current_type, pair->value);
|
||||||
|
|
||||||
|
if (!builder.HasType(current_type))
|
||||||
/* if no tag item has been added, then the
|
/* if no tag item has been added, then the
|
||||||
given value was not acceptable
|
given value was not acceptable
|
||||||
(e.g. empty); forcefully insert an empty
|
(e.g. empty); forcefully insert an empty
|
||||||
tag in this case, as the caller expects the
|
tag in this case, as the caller expects the
|
||||||
given tag type to be present */
|
given tag type to be present */
|
||||||
tag.AddEmptyItem(tag_type);
|
builder.AddEmptyItem(current_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!builder.IsEmpty()) {
|
||||||
try {
|
try {
|
||||||
visit_tag(tag.Commit());
|
visit_tag(builder.Commit());
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
mpd_response_finish(connection);
|
mpd_response_finish(connection);
|
||||||
throw;
|
throw;
|
||||||
|
|
Loading…
Reference in New Issue