ncm: update to implement new ContentMetaDatabase function for 20.0.0

This commit is contained in:
Michael Scire 2025-04-30 23:27:36 -07:00 committed by SciresM
parent b1ca5b4049
commit 791edf87a0
8 changed files with 70 additions and 1 deletions

View file

@ -534,4 +534,34 @@ namespace ams::ncm {
R_SUCCEED();
}
Result ContentMetaDatabaseImpl::HasAttributes(sf::Out<u8> out, u8 attribute_mask) {
R_TRY(this->EnsureEnabled());
/* Create a variable to hold the combined attributes. */
u8 combined_attributes = 0;
/* Iterate over all entries. */
for (auto &entry : *m_kvs) {
/* Obtain the content meta for the key. */
const void *meta;
size_t meta_size;
R_TRY(this->GetContentMetaPointer(&meta, &meta_size, entry.GetKey()));
/* Create a reader. */
ContentMetaReader reader(meta, meta_size);
/* Accumulate the set attributes from the current entry. */
combined_attributes |= (reader.GetHeader()->attributes) & attribute_mask;
/* If all the attributes we're looking for have been found, we're done. */
if ((combined_attributes & attribute_mask) == attribute_mask) {
break;
}
}
/* Set the output. */
*out = combined_attributes;
R_SUCCEED();
}
}

View file

@ -65,6 +65,7 @@ namespace ams::ncm {
virtual Result GetContentInfoByType(sf::Out<ContentInfo> out_content_info, const ContentMetaKey &key, ContentType type) override;
virtual Result GetContentInfoByTypeAndIdOffset(sf::Out<ContentInfo> out_content_info, const ContentMetaKey &key, ContentType type, u8 id_offset) override;
virtual Result GetPlatform(sf::Out<ncm::ContentMetaPlatform> out, const ContentMetaKey &key) override;
virtual Result HasAttributes(sf::Out<u8> out, u8 attr_mask) override;
};
}

View file

@ -81,6 +81,7 @@ namespace ams::ncm {
virtual Result GetContentInfoByType(sf::Out<ContentInfo> out_content_info, const ContentMetaKey &key, ContentType type) = 0;
virtual Result GetContentInfoByTypeAndIdOffset(sf::Out<ContentInfo> out_content_info, const ContentMetaKey &key, ContentType type, u8 id_offset) = 0;
virtual Result GetPlatform(sf::Out<ncm::ContentMetaPlatform> out, const ContentMetaKey &key) = 0;
virtual Result HasAttributes(sf::Out<u8> out, u8 attr_mask) = 0;
};
static_assert(ncm::IsIContentMetaDatabase<ContentMetaDatabaseImplBase>);

View file

@ -463,4 +463,28 @@ namespace ams::ncm {
}));
}
Result IntegratedContentMetaDatabaseImpl::HasAttributes(sf::Out<u8> out, u8 attr_mask) {
/* Lock ourselves. */
std::scoped_lock lk(m_mutex);
/* Check that we're enabled. */
R_TRY(this->EnsureEnabled());
/* Test whether we have the attributes on all databases. */
u8 combined_attributes = 0;
R_TRY(m_list.ForAll([&](const auto &data) {
/* Check the current database. */
u8 cur_attr = 0;
R_TRY(data.interface->HasAttributes(std::addressof(cur_attr), attr_mask));
/* Accumulate the attributes found in the current interface. */
combined_attributes |= cur_attr;
R_SUCCEED();
}));
/* Set the output. */
*out = combined_attributes;
R_SUCCEED();
}
}

View file

@ -191,6 +191,12 @@ namespace ams::ncm {
static_assert(sizeof(ncm::ContentMetaPlatform) == sizeof(u8));
R_RETURN(ncmContentMetaDatabaseGetPlatform(std::addressof(m_srv), reinterpret_cast<u8 *>(out.GetPointer()), Convert(key)));
}
Result HasAttributes(sf::Out<u8> out, u8 attr_mask) {
/* TODO: libnx bindings */
AMS_UNUSED(out, attr_mask);
AMS_ABORT();
}
};
static_assert(ncm::IsIContentMetaDatabase<RemoteContentMetaDatabaseImpl>);
#endif