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
parent 13780c5c65
commit a8e955d3be
8 changed files with 70 additions and 1 deletions

View file

@ -226,6 +226,11 @@ namespace ams::ncm {
AMS_ASSERT(m_interface != nullptr);
R_RETURN(m_interface->GetPlatform(out, key));
}
Result HasAttributes(u8 *out, u8 attr_mask) {
AMS_ASSERT(m_interface != nullptr);
R_RETURN(m_interface->HasAttributes(out, attr_mask));
}
};
}

View file

@ -44,7 +44,8 @@
AMS_SF_METHOD_INFO(C, H, 23, Result, GetContentAccessibilities, (sf::Out<u8> out_accessibilities, const ncm::ContentMetaKey &key), (out_accessibilities, key), hos::Version_15_0_0) \
AMS_SF_METHOD_INFO(C, H, 24, Result, GetContentInfoByType, (sf::Out<ncm::ContentInfo> out_content_info, const ncm::ContentMetaKey &key, ncm::ContentType type), (out_content_info, key, type), hos::Version_15_0_0) \
AMS_SF_METHOD_INFO(C, H, 25, Result, GetContentInfoByTypeAndIdOffset, (sf::Out<ncm::ContentInfo> out_content_info, const ncm::ContentMetaKey &key, ncm::ContentType type, u8 id_offset), (out_content_info, key, type, id_offset), hos::Version_15_0_0) \
AMS_SF_METHOD_INFO(C, H, 26, Result, GetPlatform, (sf::Out<ncm::ContentMetaPlatform> out, const ncm::ContentMetaKey &key), (out, key), hos::Version_17_0_0)
AMS_SF_METHOD_INFO(C, H, 26, Result, GetPlatform, (sf::Out<ncm::ContentMetaPlatform> out, const ncm::ContentMetaKey &key), (out, key), hos::Version_17_0_0) \
AMS_SF_METHOD_INFO(C, H, 27, Result, HasAttributes, (sf::Out<u8> out, u8 attr_mask), (out, attr_mask), hos::Version_20_0_0)
AMS_SF_DEFINE_INTERFACE(ams::ncm, IContentMetaDatabase, AMS_NCM_I_CONTENT_META_DATABASE_INTERFACE_INFO, 0x58021FEC)

View file

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

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