/*
* Copyright (c) 2019 Adubbz
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope 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, see .
*/
#pragma once
#include
#include
#include "ncm_icontentmetadatabase.hpp"
namespace sts::ncm {
class ContentMetaDatabaseInterface : public IContentMetaDatabase {
public:
ContentMetaDatabaseInterface(sts::kvdb::MemoryKeyValueStore* kvs, const char* mount_name) : IContentMetaDatabase(kvs, mount_name) {
}
ContentMetaDatabaseInterface(sts::kvdb::MemoryKeyValueStore* kvs) : IContentMetaDatabase(kvs) {
}
private:
Result GetContentIdByTypeImpl(ContentId* out, const ContentMetaKey& key, ContentType type, std::optional id_offset);
Result GetLatestContentMetaKeyImpl(ContentMetaKey* out_key, TitleId tid);
protected:
Result EnsureEnabled();
public:
virtual Result Set(ContentMetaKey key, InBuffer value) override;
virtual Result Get(Out out_size, ContentMetaKey key, OutBuffer out_value) override;
virtual Result Remove(ContentMetaKey key) override;
virtual Result GetContentIdByType(Out out_content_id, ContentMetaKey key, ContentType type) override;
virtual Result ListContentInfo(Out out_entries_written, OutBuffer out_info, ContentMetaKey key, u32 start_index) override;
virtual Result List(Out out_entries_total, Out out_entries_written, OutBuffer out_info, ContentMetaType type, TitleId application_title_id, TitleId title_id_min, TitleId title_id_max, ContentInstallType install_type) override;
virtual Result GetLatestContentMetaKey(Out out_key, TitleId tid) override;
virtual Result ListApplication(Out out_entries_total, Out out_entries_written, OutBuffer out_keys, ContentMetaType type) override;
virtual Result Has(Out out, ContentMetaKey key) override;
virtual Result HasAll(Out out, InBuffer keys) override;
virtual Result GetSize(Out out_size, ContentMetaKey key) override;
virtual Result GetRequiredSystemVersion(Out out_version, ContentMetaKey key) override;
virtual Result GetPatchId(Out out_patch_id, ContentMetaKey key) override;
virtual Result DisableForcibly() override;
virtual Result LookupOrphanContent(OutBuffer out_orphaned, InBuffer content_ids) override;
virtual Result Commit() override;
virtual Result HasContent(Out out, ContentMetaKey key, ContentId content_id) override;
virtual Result ListContentMetaInfo(Out out_entries_written, OutBuffer out_meta_info, ContentMetaKey key, u32 start_index) override;
virtual Result GetAttributes(Out out_attributes, ContentMetaKey key) override;
virtual Result GetRequiredApplicationVersion(Out out_version, ContentMetaKey key) override;
virtual Result GetContentIdByTypeAndIdOffset(Out out_content_id, ContentMetaKey key, ContentType type, u8 id_offset) override;
/* APIs. */
virtual Result GetLatestProgram(ContentId* out_content_id, TitleId title_id) override;
virtual Result GetLatestData(ContentId* out_content_id, TitleId title_id) override;
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(ContentMetaDatabaseInterface, Set),
MAKE_SERVICE_COMMAND_META(ContentMetaDatabaseInterface, Get),
MAKE_SERVICE_COMMAND_META(ContentMetaDatabaseInterface, Remove),
MAKE_SERVICE_COMMAND_META(ContentMetaDatabaseInterface, GetContentIdByType),
MAKE_SERVICE_COMMAND_META(ContentMetaDatabaseInterface, ListContentInfo),
MAKE_SERVICE_COMMAND_META(ContentMetaDatabaseInterface, List),
MAKE_SERVICE_COMMAND_META(ContentMetaDatabaseInterface, GetLatestContentMetaKey),
MAKE_SERVICE_COMMAND_META(ContentMetaDatabaseInterface, ListApplication),
MAKE_SERVICE_COMMAND_META(ContentMetaDatabaseInterface, Has),
MAKE_SERVICE_COMMAND_META(ContentMetaDatabaseInterface, HasAll),
MAKE_SERVICE_COMMAND_META(ContentMetaDatabaseInterface, GetSize),
MAKE_SERVICE_COMMAND_META(ContentMetaDatabaseInterface, GetRequiredSystemVersion),
MAKE_SERVICE_COMMAND_META(ContentMetaDatabaseInterface, GetPatchId),
MAKE_SERVICE_COMMAND_META(ContentMetaDatabaseInterface, DisableForcibly),
MAKE_SERVICE_COMMAND_META(ContentMetaDatabaseInterface, LookupOrphanContent),
MAKE_SERVICE_COMMAND_META(ContentMetaDatabaseInterface, Commit),
MAKE_SERVICE_COMMAND_META(ContentMetaDatabaseInterface, HasContent),
MAKE_SERVICE_COMMAND_META(ContentMetaDatabaseInterface, ListContentMetaInfo),
MAKE_SERVICE_COMMAND_META(ContentMetaDatabaseInterface, GetAttributes),
MAKE_SERVICE_COMMAND_META(ContentMetaDatabaseInterface, GetRequiredApplicationVersion, FirmwareVersion_200),
MAKE_SERVICE_COMMAND_META(ContentMetaDatabaseInterface, GetContentIdByTypeAndIdOffset, FirmwareVersion_500),
};
};
class OnMemoryContentMetaDatabaseInterface : public ContentMetaDatabaseInterface {
private:
enum class CommandId {
Set = 0,
Get = 1,
Remove = 2,
GetContentIdByType = 3,
ListContentInfo = 4,
List = 5,
GetLatestContentMetaKey = 6,
ListApplication = 7,
Has = 8,
HasAll = 9,
GetSize = 10,
GetRequiredSystemVersion = 11,
GetPatchId = 12,
DisableForcibly = 13,
LookupOrphanContent = 14,
Commit = 15,
HasContent = 16,
ListContentMetaInfo = 17,
GetAttributes = 18,
GetRequiredApplicationVersion = 19,
GetContentIdByTypeAndIdOffset = 20,
};
public:
OnMemoryContentMetaDatabaseInterface(sts::kvdb::MemoryKeyValueStore* kvs) : ContentMetaDatabaseInterface(kvs) {
}
public:
virtual Result GetLatestContentMetaKey(Out out_key, TitleId tid) override;
virtual Result LookupOrphanContent(OutBuffer out_orphaned, InBuffer content_ids) override;
virtual Result Commit() override;
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(OnMemoryContentMetaDatabaseInterface, Set),
MAKE_SERVICE_COMMAND_META(OnMemoryContentMetaDatabaseInterface, Get),
MAKE_SERVICE_COMMAND_META(OnMemoryContentMetaDatabaseInterface, Remove),
MAKE_SERVICE_COMMAND_META(OnMemoryContentMetaDatabaseInterface, GetContentIdByType),
MAKE_SERVICE_COMMAND_META(OnMemoryContentMetaDatabaseInterface, ListContentInfo),
MAKE_SERVICE_COMMAND_META(OnMemoryContentMetaDatabaseInterface, List),
MAKE_SERVICE_COMMAND_META(OnMemoryContentMetaDatabaseInterface, GetLatestContentMetaKey),
MAKE_SERVICE_COMMAND_META(OnMemoryContentMetaDatabaseInterface, ListApplication),
MAKE_SERVICE_COMMAND_META(OnMemoryContentMetaDatabaseInterface, Has),
MAKE_SERVICE_COMMAND_META(OnMemoryContentMetaDatabaseInterface, HasAll),
MAKE_SERVICE_COMMAND_META(OnMemoryContentMetaDatabaseInterface, GetSize),
MAKE_SERVICE_COMMAND_META(OnMemoryContentMetaDatabaseInterface, GetRequiredSystemVersion),
MAKE_SERVICE_COMMAND_META(OnMemoryContentMetaDatabaseInterface, GetPatchId),
MAKE_SERVICE_COMMAND_META(OnMemoryContentMetaDatabaseInterface, DisableForcibly),
MAKE_SERVICE_COMMAND_META(OnMemoryContentMetaDatabaseInterface, LookupOrphanContent),
MAKE_SERVICE_COMMAND_META(OnMemoryContentMetaDatabaseInterface, Commit),
MAKE_SERVICE_COMMAND_META(OnMemoryContentMetaDatabaseInterface, HasContent),
MAKE_SERVICE_COMMAND_META(OnMemoryContentMetaDatabaseInterface, ListContentMetaInfo),
MAKE_SERVICE_COMMAND_META(OnMemoryContentMetaDatabaseInterface, GetAttributes),
MAKE_SERVICE_COMMAND_META(OnMemoryContentMetaDatabaseInterface, GetRequiredApplicationVersion, FirmwareVersion_200),
MAKE_SERVICE_COMMAND_META(OnMemoryContentMetaDatabaseInterface, GetContentIdByTypeAndIdOffset, FirmwareVersion_500),
};
};
}