CR feedback; using namespace AssetUtils => inline AssetUtils::

This commit is contained in:
humbletim 2018-01-18 21:49:53 -05:00
parent d2a3a71f00
commit dfb1619dc6
15 changed files with 238 additions and 247 deletions

View file

@ -39,7 +39,6 @@
#include "SendAssetTask.h" #include "SendAssetTask.h"
#include "UploadAssetTask.h" #include "UploadAssetTask.h"
static const uint8_t MIN_CORES_FOR_MULTICORE = 4; static const uint8_t MIN_CORES_FOR_MULTICORE = 4;
static const uint8_t CPU_AFFINITY_COUNT_HIGH = 2; static const uint8_t CPU_AFFINITY_COUNT_HIGH = 2;
static const uint8_t CPU_AFFINITY_COUNT_LOW = 1; static const uint8_t CPU_AFFINITY_COUNT_LOW = 1;
@ -56,7 +55,7 @@ static const QString BAKED_MODEL_SIMPLE_NAME = "asset.fbx";
static const QString BAKED_TEXTURE_SIMPLE_NAME = "texture.ktx"; static const QString BAKED_TEXTURE_SIMPLE_NAME = "texture.ktx";
static const QString BAKED_SCRIPT_SIMPLE_NAME = "asset.js"; static const QString BAKED_SCRIPT_SIMPLE_NAME = "asset.js";
void AssetServer::bakeAsset(const AssetHash& assetHash, const AssetPath& assetPath, const QString& filePath) { void AssetServer::bakeAsset(const AssetUtils::AssetHash& assetHash, const AssetUtils::AssetPath& assetPath, const QString& filePath) {
qDebug() << "Starting bake for: " << assetPath << assetHash; qDebug() << "Starting bake for: " << assetPath << assetHash;
auto it = _pendingBakes.find(assetHash); auto it = _pendingBakes.find(assetHash);
if (it == _pendingBakes.end()) { if (it == _pendingBakes.end()) {
@ -74,23 +73,23 @@ void AssetServer::bakeAsset(const AssetHash& assetHash, const AssetPath& assetPa
} }
} }
QString AssetServer::getPathToAssetHash(const AssetHash& assetHash) { QString AssetServer::getPathToAssetHash(const AssetUtils::AssetHash& assetHash) {
return _filesDirectory.absoluteFilePath(assetHash); return _filesDirectory.absoluteFilePath(assetHash);
} }
std::pair<BakingStatus, QString> AssetServer::getAssetStatus(const AssetPath& path, const AssetHash& hash) { std::pair<AssetUtils::BakingStatus, QString> AssetServer::getAssetStatus(const AssetUtils::AssetPath& path, const AssetUtils::AssetHash& hash) {
auto it = _pendingBakes.find(hash); auto it = _pendingBakes.find(hash);
if (it != _pendingBakes.end()) { if (it != _pendingBakes.end()) {
return { (*it)->isBaking() ? Baking : Pending, "" }; return { (*it)->isBaking() ? AssetUtils::Baking : AssetUtils::Pending, "" };
} }
if (path.startsWith(HIDDEN_BAKED_CONTENT_FOLDER)) { if (path.startsWith(AssetUtils::HIDDEN_BAKED_CONTENT_FOLDER)) {
return { Baked, "" }; return { AssetUtils::Baked, "" };
} }
auto dotIndex = path.lastIndexOf("."); auto dotIndex = path.lastIndexOf(".");
if (dotIndex == -1) { if (dotIndex == -1) {
return { Irrelevant, "" }; return { AssetUtils::Irrelevant, "" };
} }
auto extension = path.mid(dotIndex + 1); auto extension = path.mid(dotIndex + 1);
@ -104,16 +103,16 @@ std::pair<BakingStatus, QString> AssetServer::getAssetStatus(const AssetPath& pa
} else if (BAKEABLE_SCRIPT_EXTENSIONS.contains(extension)) { } else if (BAKEABLE_SCRIPT_EXTENSIONS.contains(extension)) {
bakedFilename = BAKED_SCRIPT_SIMPLE_NAME; bakedFilename = BAKED_SCRIPT_SIMPLE_NAME;
} else { } else {
return { Irrelevant, "" }; return { AssetUtils::Irrelevant, "" };
} }
auto bakedPath = HIDDEN_BAKED_CONTENT_FOLDER + hash + "/" + bakedFilename; auto bakedPath = AssetUtils::HIDDEN_BAKED_CONTENT_FOLDER + hash + "/" + bakedFilename;
auto jt = _fileMappings.find(bakedPath); auto jt = _fileMappings.find(bakedPath);
if (jt != _fileMappings.end()) { if (jt != _fileMappings.end()) {
if (jt->second == hash) { if (jt->second == hash) {
return { NotBaked, "" }; return { AssetUtils::NotBaked, "" };
} else { } else {
return { Baked, "" }; return { AssetUtils::Baked, "" };
} }
} else { } else {
bool loaded; bool loaded;
@ -121,11 +120,11 @@ std::pair<BakingStatus, QString> AssetServer::getAssetStatus(const AssetPath& pa
std::tie(loaded, meta) = readMetaFile(hash); std::tie(loaded, meta) = readMetaFile(hash);
if (loaded && meta.failedLastBake) { if (loaded && meta.failedLastBake) {
return { Error, meta.lastBakeErrors }; return { AssetUtils::Error, meta.lastBakeErrors };
} }
} }
return { Pending, "" }; return { AssetUtils::Pending, "" };
} }
void AssetServer::bakeAssets() { void AssetServer::bakeAssets() {
@ -137,14 +136,14 @@ void AssetServer::bakeAssets() {
} }
} }
void AssetServer::maybeBake(const AssetPath& path, const AssetHash& hash) { void AssetServer::maybeBake(const AssetUtils::AssetPath& path, const AssetUtils::AssetHash& hash) {
if (needsToBeBaked(path, hash)) { if (needsToBeBaked(path, hash)) {
qDebug() << "Queuing bake of: " << path; qDebug() << "Queuing bake of: " << path;
bakeAsset(hash, path, getPathToAssetHash(hash)); bakeAsset(hash, path, getPathToAssetHash(hash));
} }
} }
void AssetServer::createEmptyMetaFile(const AssetHash& hash) { void AssetServer::createEmptyMetaFile(const AssetUtils::AssetHash& hash) {
QString metaFilePath = "atp:/" + hash + "/meta.json"; QString metaFilePath = "atp:/" + hash + "/meta.json";
QFile metaFile { metaFilePath }; QFile metaFile { metaFilePath };
@ -157,14 +156,14 @@ void AssetServer::createEmptyMetaFile(const AssetHash& hash) {
} }
} }
bool AssetServer::hasMetaFile(const AssetHash& hash) { bool AssetServer::hasMetaFile(const AssetUtils::AssetHash& hash) {
QString metaFilePath = HIDDEN_BAKED_CONTENT_FOLDER + hash + "/meta.json"; QString metaFilePath = AssetUtils::HIDDEN_BAKED_CONTENT_FOLDER + hash + "/meta.json";
return _fileMappings.find(metaFilePath) != _fileMappings.end(); return _fileMappings.find(metaFilePath) != _fileMappings.end();
} }
bool AssetServer::needsToBeBaked(const AssetPath& path, const AssetHash& assetHash) { bool AssetServer::needsToBeBaked(const AssetUtils::AssetPath& path, const AssetUtils::AssetHash& assetHash) {
if (path.startsWith(HIDDEN_BAKED_CONTENT_FOLDER)) { if (path.startsWith(AssetUtils::HIDDEN_BAKED_CONTENT_FOLDER)) {
return false; return false;
} }
@ -196,7 +195,7 @@ bool AssetServer::needsToBeBaked(const AssetPath& path, const AssetHash& assetHa
return false; return false;
} }
auto bakedPath = HIDDEN_BAKED_CONTENT_FOLDER + assetHash + "/" + bakedFilename; auto bakedPath = AssetUtils::HIDDEN_BAKED_CONTENT_FOLDER + assetHash + "/" + bakedFilename;
return _fileMappings.find(bakedPath) == _fileMappings.end(); return _fileMappings.find(bakedPath) == _fileMappings.end();
} }
@ -235,7 +234,7 @@ AssetServer::AssetServer(ReceivedMessage& message) :
ThreadedAssignment(message), ThreadedAssignment(message),
_transferTaskPool(this), _transferTaskPool(this),
_bakingTaskPool(this), _bakingTaskPool(this),
_filesizeLimit(MAX_UPLOAD_SIZE) _filesizeLimit(AssetUtils::MAX_UPLOAD_SIZE)
{ {
// store the current state of image compression so we can reset it when this assignment is complete // store the current state of image compression so we can reset it when this assignment is complete
_wasColorTextureCompressionEnabled = image::isColorTexturesCompressionEnabled(); _wasColorTextureCompressionEnabled = image::isColorTexturesCompressionEnabled();
@ -390,7 +389,7 @@ void AssetServer::completeSetup() {
// Check the asset directory to output some information about what we have // Check the asset directory to output some information about what we have
auto files = _filesDirectory.entryList(QDir::Files); auto files = _filesDirectory.entryList(QDir::Files);
QRegExp hashFileRegex { ASSET_HASH_REGEX_STRING }; QRegExp hashFileRegex { AssetUtils::ASSET_HASH_REGEX_STRING };
auto hashedFiles = files.filter(hashFileRegex); auto hashedFiles = files.filter(hashFileRegex);
qCInfo(asset_server) << "There are" << hashedFiles.size() << "asset files in the asset directory."; qCInfo(asset_server) << "There are" << hashedFiles.size() << "asset files in the asset directory.";
@ -410,9 +409,9 @@ void AssetServer::completeSetup() {
// get file size limit for an asset // get file size limit for an asset
static const QString ASSETS_FILESIZE_LIMIT_OPTION = "assets_filesize_limit"; static const QString ASSETS_FILESIZE_LIMIT_OPTION = "assets_filesize_limit";
auto assetsFilesizeLimitJSONValue = assetServerObject[ASSETS_FILESIZE_LIMIT_OPTION]; auto assetsFilesizeLimitJSONValue = assetServerObject[ASSETS_FILESIZE_LIMIT_OPTION];
auto assetsFilesizeLimit = (uint64_t)assetsFilesizeLimitJSONValue.toInt(MAX_UPLOAD_SIZE); auto assetsFilesizeLimit = (uint64_t)assetsFilesizeLimitJSONValue.toInt(AssetUtils::MAX_UPLOAD_SIZE);
if (assetsFilesizeLimit != 0 && assetsFilesizeLimit < MAX_UPLOAD_SIZE) { if (assetsFilesizeLimit != 0 && assetsFilesizeLimit < AssetUtils::MAX_UPLOAD_SIZE) {
_filesizeLimit = assetsFilesizeLimit * BITS_PER_MEGABITS; _filesizeLimit = assetsFilesizeLimit * BITS_PER_MEGABITS;
} }
@ -421,7 +420,7 @@ void AssetServer::completeSetup() {
} }
void AssetServer::cleanupUnmappedFiles() { void AssetServer::cleanupUnmappedFiles() {
QRegExp hashFileRegex { "^[a-f0-9]{" + QString::number(SHA256_HASH_HEX_LENGTH) + "}" }; QRegExp hashFileRegex { "^[a-f0-9]{" + QString::number(AssetUtils::SHA256_HASH_HEX_LENGTH) + "}" };
auto files = _filesDirectory.entryInfoList(QDir::Files); auto files = _filesDirectory.entryInfoList(QDir::Files);
@ -454,6 +453,8 @@ void AssetServer::cleanupUnmappedFiles() {
} }
void AssetServer::handleAssetMappingOperation(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode) { void AssetServer::handleAssetMappingOperation(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode) {
using AssetMappingOperationType = AssetUtils::AssetMappingOperationType;
MessageID messageID; MessageID messageID;
message->readPrimitive(&messageID); message->readPrimitive(&messageID);
@ -519,7 +520,7 @@ void AssetServer::handleGetMappingOperation(ReceivedMessage& message, SharedNode
if (!bakedRootFile.isEmpty()) { if (!bakedRootFile.isEmpty()) {
// we ran into an asset for which we could have a baked version, let's check if it's ready // we ran into an asset for which we could have a baked version, let's check if it's ready
bakedAssetPath = HIDDEN_BAKED_CONTENT_FOLDER + originalAssetHash + "/" + bakedRootFile; bakedAssetPath = AssetUtils::HIDDEN_BAKED_CONTENT_FOLDER + originalAssetHash + "/" + bakedRootFile;
auto bakedIt = _fileMappings.find(bakedAssetPath); auto bakedIt = _fileMappings.find(bakedAssetPath);
if (bakedIt != _fileMappings.end()) { if (bakedIt != _fileMappings.end()) {
@ -537,7 +538,7 @@ void AssetServer::handleGetMappingOperation(ReceivedMessage& message, SharedNode
} }
} }
replyPacket.writePrimitive(AssetServerError::NoError); replyPacket.writePrimitive(AssetUtils::AssetServerError::NoError);
if (wasRedirected) { if (wasRedirected) {
qDebug() << "Writing re-directed hash for" << originalAssetHash << "to" << redirectedAssetHash; qDebug() << "Writing re-directed hash for" << originalAssetHash << "to" << redirectedAssetHash;
@ -563,12 +564,12 @@ void AssetServer::handleGetMappingOperation(ReceivedMessage& message, SharedNode
} }
} }
} else { } else {
replyPacket.writePrimitive(AssetServerError::AssetNotFound); replyPacket.writePrimitive(AssetUtils::AssetServerError::AssetNotFound);
} }
} }
void AssetServer::handleGetAllMappingOperation(ReceivedMessage& message, SharedNodePointer senderNode, NLPacketList& replyPacket) { void AssetServer::handleGetAllMappingOperation(ReceivedMessage& message, SharedNodePointer senderNode, NLPacketList& replyPacket) {
replyPacket.writePrimitive(AssetServerError::NoError); replyPacket.writePrimitive(AssetUtils::AssetServerError::NoError);
uint32_t count = (uint32_t)_fileMappings.size(); uint32_t count = (uint32_t)_fileMappings.size();
@ -580,11 +581,11 @@ void AssetServer::handleGetAllMappingOperation(ReceivedMessage& message, SharedN
replyPacket.writeString(mapping); replyPacket.writeString(mapping);
replyPacket.write(QByteArray::fromHex(hash.toUtf8())); replyPacket.write(QByteArray::fromHex(hash.toUtf8()));
BakingStatus status; AssetUtils::BakingStatus status;
QString lastBakeErrors; QString lastBakeErrors;
std::tie(status, lastBakeErrors) = getAssetStatus(mapping, hash); std::tie(status, lastBakeErrors) = getAssetStatus(mapping, hash);
replyPacket.writePrimitive(status); replyPacket.writePrimitive(status);
if (status == Error) { if (status == AssetUtils::Error) {
replyPacket.writeString(lastBakeErrors); replyPacket.writeString(lastBakeErrors);
} }
} }
@ -594,22 +595,22 @@ void AssetServer::handleSetMappingOperation(ReceivedMessage& message, SharedNode
if (senderNode->getCanWriteToAssetServer()) { if (senderNode->getCanWriteToAssetServer()) {
QString assetPath = message.readString(); QString assetPath = message.readString();
auto assetHash = message.read(SHA256_HASH_LENGTH).toHex(); auto assetHash = message.read(AssetUtils::SHA256_HASH_LENGTH).toHex();
// don't process a set mapping operation that is inside the hidden baked folder // don't process a set mapping operation that is inside the hidden baked folder
if (assetPath.startsWith(HIDDEN_BAKED_CONTENT_FOLDER)) { if (assetPath.startsWith(AssetUtils::HIDDEN_BAKED_CONTENT_FOLDER)) {
qCDebug(asset_server) << "Refusing to process a set mapping operation inside" << HIDDEN_BAKED_CONTENT_FOLDER; qCDebug(asset_server) << "Refusing to process a set mapping operation inside" << AssetUtils::HIDDEN_BAKED_CONTENT_FOLDER;
replyPacket.writePrimitive(AssetServerError::PermissionDenied); replyPacket.writePrimitive(AssetUtils::AssetServerError::PermissionDenied);
} else { } else {
if (setMapping(assetPath, assetHash)) { if (setMapping(assetPath, assetHash)) {
replyPacket.writePrimitive(AssetServerError::NoError); replyPacket.writePrimitive(AssetUtils::AssetServerError::NoError);
} else { } else {
replyPacket.writePrimitive(AssetServerError::MappingOperationFailed); replyPacket.writePrimitive(AssetUtils::AssetServerError::MappingOperationFailed);
} }
} }
} else { } else {
replyPacket.writePrimitive(AssetServerError::PermissionDenied); replyPacket.writePrimitive(AssetUtils::AssetServerError::PermissionDenied);
} }
} }
@ -623,21 +624,21 @@ void AssetServer::handleDeleteMappingsOperation(ReceivedMessage& message, Shared
for (int i = 0; i < numberOfDeletedMappings; ++i) { for (int i = 0; i < numberOfDeletedMappings; ++i) {
auto mapping = message.readString(); auto mapping = message.readString();
if (!mapping.startsWith(HIDDEN_BAKED_CONTENT_FOLDER)) { if (!mapping.startsWith(AssetUtils::HIDDEN_BAKED_CONTENT_FOLDER)) {
mappingsToDelete << mapping; mappingsToDelete << mapping;
} else { } else {
qCDebug(asset_server) << "Refusing to delete mapping" << mapping qCDebug(asset_server) << "Refusing to delete mapping" << mapping
<< "that is inside" << HIDDEN_BAKED_CONTENT_FOLDER; << "that is inside" << AssetUtils::HIDDEN_BAKED_CONTENT_FOLDER;
} }
} }
if (deleteMappings(mappingsToDelete)) { if (deleteMappings(mappingsToDelete)) {
replyPacket.writePrimitive(AssetServerError::NoError); replyPacket.writePrimitive(AssetUtils::AssetServerError::NoError);
} else { } else {
replyPacket.writePrimitive(AssetServerError::MappingOperationFailed); replyPacket.writePrimitive(AssetUtils::AssetServerError::MappingOperationFailed);
} }
} else { } else {
replyPacket.writePrimitive(AssetServerError::PermissionDenied); replyPacket.writePrimitive(AssetUtils::AssetServerError::PermissionDenied);
} }
} }
@ -646,20 +647,20 @@ void AssetServer::handleRenameMappingOperation(ReceivedMessage& message, SharedN
QString oldPath = message.readString(); QString oldPath = message.readString();
QString newPath = message.readString(); QString newPath = message.readString();
if (oldPath.startsWith(HIDDEN_BAKED_CONTENT_FOLDER) || newPath.startsWith(HIDDEN_BAKED_CONTENT_FOLDER)) { if (oldPath.startsWith(AssetUtils::HIDDEN_BAKED_CONTENT_FOLDER) || newPath.startsWith(AssetUtils::HIDDEN_BAKED_CONTENT_FOLDER)) {
qCDebug(asset_server) << "Cannot rename" << oldPath << "to" << newPath qCDebug(asset_server) << "Cannot rename" << oldPath << "to" << newPath
<< "since one of the paths is inside" << HIDDEN_BAKED_CONTENT_FOLDER; << "since one of the paths is inside" << AssetUtils::HIDDEN_BAKED_CONTENT_FOLDER;
replyPacket.writePrimitive(AssetServerError::PermissionDenied); replyPacket.writePrimitive(AssetUtils::AssetServerError::PermissionDenied);
} else { } else {
if (renameMapping(oldPath, newPath)) { if (renameMapping(oldPath, newPath)) {
replyPacket.writePrimitive(AssetServerError::NoError); replyPacket.writePrimitive(AssetUtils::AssetServerError::NoError);
} else { } else {
replyPacket.writePrimitive(AssetServerError::MappingOperationFailed); replyPacket.writePrimitive(AssetUtils::AssetServerError::MappingOperationFailed);
} }
} }
} else { } else {
replyPacket.writePrimitive(AssetServerError::PermissionDenied); replyPacket.writePrimitive(AssetUtils::AssetServerError::PermissionDenied);
} }
} }
@ -678,12 +679,12 @@ void AssetServer::handleSetBakingEnabledOperation(ReceivedMessage& message, Shar
} }
if (setBakingEnabled(mappings, enabled)) { if (setBakingEnabled(mappings, enabled)) {
replyPacket.writePrimitive(AssetServerError::NoError); replyPacket.writePrimitive(AssetUtils::AssetServerError::NoError);
} else { } else {
replyPacket.writePrimitive(AssetServerError::MappingOperationFailed); replyPacket.writePrimitive(AssetUtils::AssetServerError::MappingOperationFailed);
} }
} else { } else {
replyPacket.writePrimitive(AssetServerError::PermissionDenied); replyPacket.writePrimitive(AssetUtils::AssetServerError::PermissionDenied);
} }
} }
@ -691,15 +692,15 @@ void AssetServer::handleAssetGetInfo(QSharedPointer<ReceivedMessage> message, Sh
QByteArray assetHash; QByteArray assetHash;
MessageID messageID; MessageID messageID;
if (message->getSize() < qint64(SHA256_HASH_LENGTH + sizeof(messageID))) { if (message->getSize() < qint64(AssetUtils::SHA256_HASH_LENGTH + sizeof(messageID))) {
qCDebug(asset_server) << "ERROR bad file request"; qCDebug(asset_server) << "ERROR bad file request";
return; return;
} }
message->readPrimitive(&messageID); message->readPrimitive(&messageID);
assetHash = message->readWithoutCopy(SHA256_HASH_LENGTH); assetHash = message->readWithoutCopy(AssetUtils::SHA256_HASH_LENGTH);
auto size = qint64(sizeof(MessageID) + SHA256_HASH_LENGTH + sizeof(AssetServerError) + sizeof(qint64)); auto size = qint64(sizeof(MessageID) + AssetUtils::SHA256_HASH_LENGTH + sizeof(AssetUtils::AssetServerError) + sizeof(qint64));
auto replyPacket = NLPacket::create(PacketType::AssetGetInfoReply, size, true); auto replyPacket = NLPacket::create(PacketType::AssetGetInfoReply, size, true);
QByteArray hexHash = assetHash.toHex(); QByteArray hexHash = assetHash.toHex();
@ -712,11 +713,11 @@ void AssetServer::handleAssetGetInfo(QSharedPointer<ReceivedMessage> message, Sh
if (fileInfo.exists() && fileInfo.isReadable()) { if (fileInfo.exists() && fileInfo.isReadable()) {
qCDebug(asset_server) << "Opening file: " << fileInfo.filePath(); qCDebug(asset_server) << "Opening file: " << fileInfo.filePath();
replyPacket->writePrimitive(AssetServerError::NoError); replyPacket->writePrimitive(AssetUtils::AssetServerError::NoError);
replyPacket->writePrimitive(fileInfo.size()); replyPacket->writePrimitive(fileInfo.size());
} else { } else {
qCDebug(asset_server) << "Asset not found: " << QString(hexHash); qCDebug(asset_server) << "Asset not found: " << QString(hexHash);
replyPacket->writePrimitive(AssetServerError::AssetNotFound); replyPacket->writePrimitive(AssetUtils::AssetServerError::AssetNotFound);
} }
auto nodeList = DependencyManager::get<NodeList>(); auto nodeList = DependencyManager::get<NodeList>();
@ -725,7 +726,7 @@ void AssetServer::handleAssetGetInfo(QSharedPointer<ReceivedMessage> message, Sh
void AssetServer::handleAssetGet(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode) { void AssetServer::handleAssetGet(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode) {
auto minSize = qint64(sizeof(MessageID) + SHA256_HASH_LENGTH + sizeof(DataOffset) + sizeof(DataOffset)); auto minSize = qint64(sizeof(MessageID) + AssetUtils::SHA256_HASH_LENGTH + sizeof(AssetUtils::DataOffset) + sizeof(AssetUtils::DataOffset));
if (message->getSize() < minSize) { if (message->getSize() < minSize) {
qCDebug(asset_server) << "ERROR bad file request"; qCDebug(asset_server) << "ERROR bad file request";
@ -749,14 +750,14 @@ void AssetServer::handleAssetUpload(QSharedPointer<ReceivedMessage> message, Sha
// for now this also means it isn't allowed to add assets // for now this also means it isn't allowed to add assets
// so return a packet with error that indicates that // so return a packet with error that indicates that
auto permissionErrorPacket = NLPacket::create(PacketType::AssetUploadReply, sizeof(MessageID) + sizeof(AssetServerError), true); auto permissionErrorPacket = NLPacket::create(PacketType::AssetUploadReply, sizeof(MessageID) + sizeof(AssetUtils::AssetServerError), true);
MessageID messageID; MessageID messageID;
message->readPrimitive(&messageID); message->readPrimitive(&messageID);
// write the message ID and a permission denied error // write the message ID and a permission denied error
permissionErrorPacket->writePrimitive(messageID); permissionErrorPacket->writePrimitive(messageID);
permissionErrorPacket->writePrimitive(AssetServerError::PermissionDenied); permissionErrorPacket->writePrimitive(AssetUtils::AssetServerError::PermissionDenied);
// send off the packet // send off the packet
auto nodeList = DependencyManager::get<NodeList>(); auto nodeList = DependencyManager::get<NodeList>();
@ -863,12 +864,12 @@ bool AssetServer::loadMappingsFromFile() {
continue; continue;
} }
if (!isValidFilePath(key)) { if (!AssetUtils::isValidFilePath(key)) {
qCWarning(asset_server) << "Will not keep mapping for" << key << "since it is not a valid path."; qCWarning(asset_server) << "Will not keep mapping for" << key << "since it is not a valid path.";
continue; continue;
} }
if (!isValidHash(value.toString())) { if (!AssetUtils::isValidHash(value.toString())) {
qCWarning(asset_server) << "Will not keep mapping for" << key << "since it does not have a valid hash."; qCWarning(asset_server) << "Will not keep mapping for" << key << "since it does not have a valid hash.";
continue; continue;
} }
@ -918,15 +919,15 @@ bool AssetServer::writeMappingsToFile() {
return false; return false;
} }
bool AssetServer::setMapping(AssetPath path, AssetHash hash) { bool AssetServer::setMapping(AssetUtils::AssetPath path, AssetUtils::AssetHash hash) {
path = path.trimmed(); path = path.trimmed();
if (!isValidFilePath(path)) { if (!AssetUtils::isValidFilePath(path)) {
qCWarning(asset_server) << "Cannot set a mapping for invalid path:" << path << "=>" << hash; qCWarning(asset_server) << "Cannot set a mapping for invalid path:" << path << "=>" << hash;
return false; return false;
} }
if (!isValidHash(hash)) { if (!AssetUtils::isValidHash(hash)) {
qCWarning(asset_server) << "Cannot set a mapping for invalid hash" << path << "=>" << hash; qCWarning(asset_server) << "Cannot set a mapping for invalid hash" << path << "=>" << hash;
return false; return false;
} }
@ -958,23 +959,23 @@ bool AssetServer::setMapping(AssetPath path, AssetHash hash) {
} }
} }
bool pathIsFolder(const AssetPath& path) { bool pathIsFolder(const AssetUtils::AssetPath& path) {
return path.endsWith('/'); return path.endsWith('/');
} }
void AssetServer::removeBakedPathsForDeletedAsset(AssetHash hash) { void AssetServer::removeBakedPathsForDeletedAsset(AssetUtils::AssetHash hash) {
// we deleted the file with this hash // we deleted the file with this hash
// check if we had baked content for that file that should also now be removed // check if we had baked content for that file that should also now be removed
// by calling deleteMappings for the hidden baked content folder for this hash // by calling deleteMappings for the hidden baked content folder for this hash
AssetPathList hiddenBakedFolder { HIDDEN_BAKED_CONTENT_FOLDER + hash + "/" }; AssetUtils::AssetPathList hiddenBakedFolder { AssetUtils::HIDDEN_BAKED_CONTENT_FOLDER + hash + "/" };
qCDebug(asset_server) << "Deleting baked content below" << hiddenBakedFolder << "since" << hash << "was deleted"; qCDebug(asset_server) << "Deleting baked content below" << hiddenBakedFolder << "since" << hash << "was deleted";
deleteMappings(hiddenBakedFolder); deleteMappings(hiddenBakedFolder);
} }
bool AssetServer::deleteMappings(const AssetPathList& paths) { bool AssetServer::deleteMappings(const AssetUtils::AssetPathList& paths) {
// take a copy of the current mappings in case persistence of these deletes fails // take a copy of the current mappings in case persistence of these deletes fails
auto oldMappings = _fileMappings; auto oldMappings = _fileMappings;
@ -1060,11 +1061,11 @@ bool AssetServer::deleteMappings(const AssetPathList& paths) {
} }
} }
bool AssetServer::renameMapping(AssetPath oldPath, AssetPath newPath) { bool AssetServer::renameMapping(AssetUtils::AssetPath oldPath, AssetUtils::AssetPath newPath) {
oldPath = oldPath.trimmed(); oldPath = oldPath.trimmed();
newPath = newPath.trimmed(); newPath = newPath.trimmed();
if (!isValidFilePath(oldPath) || !isValidFilePath(newPath)) { if (!AssetUtils::isValidFilePath(oldPath) || !AssetUtils::isValidFilePath(newPath)) {
qCWarning(asset_server) << "Cannot perform rename with invalid paths - both should have leading forward and no ending slashes:" qCWarning(asset_server) << "Cannot perform rename with invalid paths - both should have leading forward and no ending slashes:"
<< oldPath << "=>" << newPath; << oldPath << "=>" << newPath;
@ -1164,8 +1165,8 @@ static const QString BAKED_ASSET_SIMPLE_FBX_NAME = "asset.fbx";
static const QString BAKED_ASSET_SIMPLE_TEXTURE_NAME = "texture.ktx"; static const QString BAKED_ASSET_SIMPLE_TEXTURE_NAME = "texture.ktx";
static const QString BAKED_ASSET_SIMPLE_JS_NAME = "asset.js"; static const QString BAKED_ASSET_SIMPLE_JS_NAME = "asset.js";
QString getBakeMapping(const AssetHash& hash, const QString& relativeFilePath) { QString getBakeMapping(const AssetUtils::AssetHash& hash, const QString& relativeFilePath) {
return HIDDEN_BAKED_CONTENT_FOLDER + hash + "/" + relativeFilePath; return AssetUtils::HIDDEN_BAKED_CONTENT_FOLDER + hash + "/" + relativeFilePath;
} }
void AssetServer::handleFailedBake(QString originalAssetHash, QString assetPath, QString errors) { void AssetServer::handleFailedBake(QString originalAssetHash, QString assetPath, QString errors) {
@ -1197,7 +1198,7 @@ void AssetServer::handleCompletedBake(QString originalAssetHash, QString origina
qDebug() << "File path: " << filePath; qDebug() << "File path: " << filePath;
AssetHash bakedFileHash; AssetUtils::AssetHash bakedFileHash;
if (file.open(QIODevice::ReadOnly)) { if (file.open(QIODevice::ReadOnly)) {
QCryptographicHash hasher(QCryptographicHash::Sha256); QCryptographicHash hasher(QCryptographicHash::Sha256);
@ -1290,8 +1291,8 @@ static const QString BAKE_VERSION_KEY = "bake_version";
static const QString FAILED_LAST_BAKE_KEY = "failed_last_bake"; static const QString FAILED_LAST_BAKE_KEY = "failed_last_bake";
static const QString LAST_BAKE_ERRORS_KEY = "last_bake_errors"; static const QString LAST_BAKE_ERRORS_KEY = "last_bake_errors";
std::pair<bool, AssetMeta> AssetServer::readMetaFile(AssetHash hash) { std::pair<bool, AssetMeta> AssetServer::readMetaFile(AssetUtils::AssetHash hash) {
auto metaFilePath = HIDDEN_BAKED_CONTENT_FOLDER + hash + "/" + "meta.json"; auto metaFilePath = AssetUtils::HIDDEN_BAKED_CONTENT_FOLDER + hash + "/" + "meta.json";
auto it = _fileMappings.find(metaFilePath); auto it = _fileMappings.find(metaFilePath);
if (it == _fileMappings.end()) { if (it == _fileMappings.end()) {
@ -1335,7 +1336,7 @@ std::pair<bool, AssetMeta> AssetServer::readMetaFile(AssetHash hash) {
return { false, {} }; return { false, {} };
} }
bool AssetServer::writeMetaFile(AssetHash originalAssetHash, const AssetMeta& meta) { bool AssetServer::writeMetaFile(AssetUtils::AssetHash originalAssetHash, const AssetMeta& meta) {
// construct the JSON that will be in the meta file // construct the JSON that will be in the meta file
QJsonObject metaFileObject; QJsonObject metaFileObject;
@ -1349,7 +1350,7 @@ bool AssetServer::writeMetaFile(AssetHash originalAssetHash, const AssetMeta& me
auto metaFileJSON = metaFileDoc.toJson(); auto metaFileJSON = metaFileDoc.toJson();
// get a hash for the contents of the meta-file // get a hash for the contents of the meta-file
AssetHash metaFileHash = QCryptographicHash::hash(metaFileJSON, QCryptographicHash::Sha256).toHex(); AssetUtils::AssetHash metaFileHash = QCryptographicHash::hash(metaFileJSON, QCryptographicHash::Sha256).toHex();
// create the meta file in our files folder, named by the hash of its contents // create the meta file in our files folder, named by the hash of its contents
QFile metaFile(_filesDirectory.absoluteFilePath(metaFileHash)); QFile metaFile(_filesDirectory.absoluteFilePath(metaFileHash));
@ -1359,7 +1360,7 @@ bool AssetServer::writeMetaFile(AssetHash originalAssetHash, const AssetMeta& me
metaFile.close(); metaFile.close();
// add a mapping to the meta file so it doesn't get deleted because it is unmapped // add a mapping to the meta file so it doesn't get deleted because it is unmapped
auto metaFileMapping = HIDDEN_BAKED_CONTENT_FOLDER + originalAssetHash + "/" + "meta.json"; auto metaFileMapping = AssetUtils::HIDDEN_BAKED_CONTENT_FOLDER + originalAssetHash + "/" + "meta.json";
return setMapping(metaFileMapping, metaFileHash); return setMapping(metaFileMapping, metaFileHash);
} else { } else {
@ -1367,7 +1368,7 @@ bool AssetServer::writeMetaFile(AssetHash originalAssetHash, const AssetMeta& me
} }
} }
bool AssetServer::setBakingEnabled(const AssetPathList& paths, bool enabled) { bool AssetServer::setBakingEnabled(const AssetUtils::AssetPathList& paths, bool enabled) {
for (const auto& path : paths) { for (const auto& path : paths) {
auto it = _fileMappings.find(path); auto it = _fileMappings.find(path);
if (it != _fileMappings.end()) { if (it != _fileMappings.end()) {

View file

@ -21,8 +21,6 @@
#include "AssetUtils.h" #include "AssetUtils.h"
#include "ReceivedMessage.h" #include "ReceivedMessage.h"
using namespace AssetUtils;
namespace std { namespace std {
template <> template <>
struct hash<QString> { struct hash<QString> {
@ -76,29 +74,29 @@ private:
bool writeMappingsToFile(); bool writeMappingsToFile();
/// Set the mapping for path to hash /// Set the mapping for path to hash
bool setMapping(AssetPath path, AssetHash hash); bool setMapping(AssetUtils::AssetPath path, AssetUtils::AssetHash hash);
/// Delete mapping `path`. Returns `true` if deletion of mappings succeeds, else `false`. /// Delete mapping `path`. Returns `true` if deletion of mappings succeeds, else `false`.
bool deleteMappings(const AssetPathList& paths); bool deleteMappings(const AssetUtils::AssetPathList& paths);
/// Rename mapping from `oldPath` to `newPath`. Returns true if successful /// Rename mapping from `oldPath` to `newPath`. Returns true if successful
bool renameMapping(AssetPath oldPath, AssetPath newPath); bool renameMapping(AssetUtils::AssetPath oldPath, AssetUtils::AssetPath newPath);
bool setBakingEnabled(const AssetPathList& paths, bool enabled); bool setBakingEnabled(const AssetUtils::AssetPathList& paths, bool enabled);
/// Delete any unmapped files from the local asset directory /// Delete any unmapped files from the local asset directory
void cleanupUnmappedFiles(); void cleanupUnmappedFiles();
QString getPathToAssetHash(const AssetHash& assetHash); QString getPathToAssetHash(const AssetUtils::AssetHash& assetHash);
std::pair<BakingStatus, QString> getAssetStatus(const AssetPath& path, const AssetHash& hash); std::pair<AssetUtils::BakingStatus, QString> getAssetStatus(const AssetUtils::AssetPath& path, const AssetUtils::AssetHash& hash);
void bakeAssets(); void bakeAssets();
void maybeBake(const AssetPath& path, const AssetHash& hash); void maybeBake(const AssetUtils::AssetPath& path, const AssetUtils::AssetHash& hash);
void createEmptyMetaFile(const AssetHash& hash); void createEmptyMetaFile(const AssetUtils::AssetHash& hash);
bool hasMetaFile(const AssetHash& hash); bool hasMetaFile(const AssetUtils::AssetHash& hash);
bool needsToBeBaked(const AssetPath& path, const AssetHash& assetHash); bool needsToBeBaked(const AssetUtils::AssetPath& path, const AssetUtils::AssetHash& assetHash);
void bakeAsset(const AssetHash& assetHash, const AssetPath& assetPath, const QString& filePath); void bakeAsset(const AssetUtils::AssetHash& assetHash, const AssetUtils::AssetPath& assetPath, const QString& filePath);
/// Move baked content for asset to baked directory and update baked status /// Move baked content for asset to baked directory and update baked status
void handleCompletedBake(QString originalAssetHash, QString assetPath, QString bakedTempOutputDir, void handleCompletedBake(QString originalAssetHash, QString assetPath, QString bakedTempOutputDir,
@ -107,11 +105,11 @@ private:
void handleAbortedBake(QString originalAssetHash, QString assetPath); void handleAbortedBake(QString originalAssetHash, QString assetPath);
/// Create meta file to describe baked content for original asset /// Create meta file to describe baked content for original asset
std::pair<bool, AssetMeta> readMetaFile(AssetHash hash); std::pair<bool, AssetMeta> readMetaFile(AssetUtils::AssetHash hash);
bool writeMetaFile(AssetHash originalAssetHash, const AssetMeta& meta = AssetMeta()); bool writeMetaFile(AssetUtils::AssetHash originalAssetHash, const AssetMeta& meta = AssetMeta());
/// Remove baked paths when the original asset is deleteds /// Remove baked paths when the original asset is deleteds
void removeBakedPathsForDeletedAsset(AssetHash originalAssetHash); void removeBakedPathsForDeletedAsset(AssetUtils::AssetHash originalAssetHash);
Mappings _fileMappings; Mappings _fileMappings;
@ -121,7 +119,7 @@ private:
/// Task pool for handling uploads and downloads of assets /// Task pool for handling uploads and downloads of assets
QThreadPool _transferTaskPool; QThreadPool _transferTaskPool;
QHash<AssetHash, std::shared_ptr<BakeAssetTask>> _pendingBakes; QHash<AssetUtils::AssetHash, std::shared_ptr<BakeAssetTask>> _pendingBakes;
QThreadPool _bakingTaskPool; QThreadPool _bakingTaskPool;
bool _wasColorTextureCompressionEnabled { false }; bool _wasColorTextureCompressionEnabled { false };

View file

@ -24,7 +24,7 @@ static const int OVEN_STATUS_CODE_ABORT { 2 };
std::once_flag registerMetaTypesFlag; std::once_flag registerMetaTypesFlag;
BakeAssetTask::BakeAssetTask(const AssetHash& assetHash, const AssetPath& assetPath, const QString& filePath) : BakeAssetTask::BakeAssetTask(const AssetUtils::AssetHash& assetHash, const AssetUtils::AssetPath& assetPath, const QString& filePath) :
_assetHash(assetHash), _assetHash(assetHash),
_assetPath(assetPath), _assetPath(assetPath),
_filePath(filePath) _filePath(filePath)

View file

@ -22,12 +22,10 @@
#include <AssetUtils.h> #include <AssetUtils.h>
using namespace AssetUtils;
class BakeAssetTask : public QObject, public QRunnable { class BakeAssetTask : public QObject, public QRunnable {
Q_OBJECT Q_OBJECT
public: public:
BakeAssetTask(const AssetHash& assetHash, const AssetPath& assetPath, const QString& filePath); BakeAssetTask(const AssetUtils::AssetHash& assetHash, const AssetUtils::AssetPath& assetPath, const QString& filePath);
bool isBaking() { return _isBaking.load(); } bool isBaking() { return _isBaking.load(); }
@ -43,8 +41,8 @@ signals:
private: private:
std::atomic<bool> _isBaking { false }; std::atomic<bool> _isBaking { false };
AssetHash _assetHash; AssetUtils::AssetHash _assetHash;
AssetPath _assetPath; AssetUtils::AssetPath _assetPath;
QString _filePath; QString _filePath;
std::unique_ptr<QProcess> _ovenProcess { nullptr }; std::unique_ptr<QProcess> _ovenProcess { nullptr };
std::atomic<bool> _wasAborted { false }; std::atomic<bool> _wasAborted { false };

View file

@ -40,7 +40,7 @@ void SendAssetTask::run() {
ByteRange byteRange; ByteRange byteRange;
_message->readPrimitive(&messageID); _message->readPrimitive(&messageID);
QByteArray assetHash = _message->read(SHA256_HASH_LENGTH); QByteArray assetHash = _message->read(AssetUtils::SHA256_HASH_LENGTH);
// `start` and `end` indicate the range of data to retrieve for the asset identified by `assetHash`. // `start` and `end` indicate the range of data to retrieve for the asset identified by `assetHash`.
// `start` is inclusive, `end` is exclusive. Requesting `start` = 1, `end` = 10 will retrieve 9 bytes of data, // `start` is inclusive, `end` is exclusive. Requesting `start` = 1, `end` = 10 will retrieve 9 bytes of data,
@ -61,7 +61,7 @@ void SendAssetTask::run() {
replyPacketList->writePrimitive(messageID); replyPacketList->writePrimitive(messageID);
if (!byteRange.isValid()) { if (!byteRange.isValid()) {
replyPacketList->writePrimitive(AssetServerError::InvalidByteRange); replyPacketList->writePrimitive(AssetUtils::AssetServerError::InvalidByteRange);
} else { } else {
QString filePath = _resourcesDir.filePath(QString(hexHash)); QString filePath = _resourcesDir.filePath(QString(hexHash));
@ -75,7 +75,7 @@ void SendAssetTask::run() {
// check if we're being asked to read data that we just don't have // check if we're being asked to read data that we just don't have
// because of the file size // because of the file size
if (file.size() < byteRange.fromInclusive || file.size() < byteRange.toExclusive) { if (file.size() < byteRange.fromInclusive || file.size() < byteRange.toExclusive) {
replyPacketList->writePrimitive(AssetServerError::InvalidByteRange); replyPacketList->writePrimitive(AssetUtils::AssetServerError::InvalidByteRange);
qCDebug(networking) << "Bad byte range: " << hexHash << " " qCDebug(networking) << "Bad byte range: " << hexHash << " "
<< byteRange.fromInclusive << ":" << byteRange.toExclusive; << byteRange.fromInclusive << ":" << byteRange.toExclusive;
} else { } else {
@ -86,7 +86,7 @@ void SendAssetTask::run() {
// this range is positive, meaning we just need to seek into the file and then read from there // this range is positive, meaning we just need to seek into the file and then read from there
file.seek(byteRange.fromInclusive); file.seek(byteRange.fromInclusive);
replyPacketList->writePrimitive(AssetServerError::NoError); replyPacketList->writePrimitive(AssetUtils::AssetServerError::NoError);
replyPacketList->writePrimitive(size); replyPacketList->writePrimitive(size);
replyPacketList->write(file.read(size)); replyPacketList->write(file.read(size));
} else { } else {
@ -95,7 +95,7 @@ void SendAssetTask::run() {
// seek to the part of the file where the negative range begins // seek to the part of the file where the negative range begins
file.seek(file.size() + byteRange.fromInclusive); file.seek(file.size() + byteRange.fromInclusive);
replyPacketList->writePrimitive(AssetServerError::NoError); replyPacketList->writePrimitive(AssetUtils::AssetServerError::NoError);
replyPacketList->writePrimitive(size); replyPacketList->writePrimitive(size);
// first write everything from the negative range to the end of the file // first write everything from the negative range to the end of the file
@ -107,7 +107,7 @@ void SendAssetTask::run() {
file.close(); file.close();
} else { } else {
qCDebug(networking) << "Asset not found: " << filePath << "(" << hexHash << ")"; qCDebug(networking) << "Asset not found: " << filePath << "(" << hexHash << ")";
replyPacketList->writePrimitive(AssetServerError::AssetNotFound); replyPacketList->writePrimitive(AssetUtils::AssetServerError::AssetNotFound);
} }
} }

View file

@ -20,8 +20,6 @@
#include "ClientServerUtils.h" #include "ClientServerUtils.h"
using namespace AssetUtils;
UploadAssetTask::UploadAssetTask(QSharedPointer<ReceivedMessage> receivedMessage, SharedNodePointer senderNode, UploadAssetTask::UploadAssetTask(QSharedPointer<ReceivedMessage> receivedMessage, SharedNodePointer senderNode,
const QDir& resourcesDir, uint64_t filesizeLimit) : const QDir& resourcesDir, uint64_t filesizeLimit) :
_receivedMessage(receivedMessage), _receivedMessage(receivedMessage),
@ -51,7 +49,7 @@ void UploadAssetTask::run() {
replyPacket->writePrimitive(messageID); replyPacket->writePrimitive(messageID);
if (fileSize > _filesizeLimit) { if (fileSize > _filesizeLimit) {
replyPacket->writePrimitive(AssetServerError::AssetTooLarge); replyPacket->writePrimitive(AssetUtils::AssetServerError::AssetTooLarge);
} else { } else {
QByteArray fileData = buffer.read(fileSize); QByteArray fileData = buffer.read(fileSize);
@ -72,7 +70,7 @@ void UploadAssetTask::run() {
existingCorrectFile = true; existingCorrectFile = true;
replyPacket->writePrimitive(AssetServerError::NoError); replyPacket->writePrimitive(AssetUtils::AssetServerError::NoError);
replyPacket->write(hash); replyPacket->write(hash);
} else { } else {
qDebug() << "Overwriting an existing file whose contents did not match the expected hash: " << hexHash; qDebug() << "Overwriting an existing file whose contents did not match the expected hash: " << hexHash;
@ -85,7 +83,7 @@ void UploadAssetTask::run() {
qDebug() << "Wrote file" << hexHash << "to disk. Upload complete"; qDebug() << "Wrote file" << hexHash << "to disk. Upload complete";
file.close(); file.close();
replyPacket->writePrimitive(AssetServerError::NoError); replyPacket->writePrimitive(AssetUtils::AssetServerError::NoError);
replyPacket->write(hash); replyPacket->write(hash);
} else { } else {
qWarning() << "Failed to upload or write to file" << hexHash << " - upload failed."; qWarning() << "Failed to upload or write to file" << hexHash << " - upload failed.";
@ -97,7 +95,7 @@ void UploadAssetTask::run() {
qWarning() << "Removal of failed upload file" << hexHash << "failed."; qWarning() << "Removal of failed upload file" << hexHash << "failed.";
} }
replyPacket->writePrimitive(AssetServerError::FileOperationFailed); replyPacket->writePrimitive(AssetUtils::AssetServerError::FileOperationFailed);
} }
} }

View file

@ -263,7 +263,7 @@ void AssetMappingModel::refresh() {
for (auto& mapping : mappings) { for (auto& mapping : mappings) {
auto& path = mapping.first; auto& path = mapping.first;
if (path.startsWith(HIDDEN_BAKED_CONTENT_FOLDER)) { if (path.startsWith(AssetUtils::HIDDEN_BAKED_CONTENT_FOLDER)) {
// Hide baked mappings // Hide baked mappings
continue; continue;
} }
@ -306,7 +306,7 @@ void AssetMappingModel::refresh() {
auto statusString = isFolder ? "--" : bakingStatusToString(mapping.second.status); auto statusString = isFolder ? "--" : bakingStatusToString(mapping.second.status);
lastItem->setData(statusString, Qt::UserRole + 5); lastItem->setData(statusString, Qt::UserRole + 5);
lastItem->setData(mapping.second.bakingErrors, Qt::UserRole + 6); lastItem->setData(mapping.second.bakingErrors, Qt::UserRole + 6);
if (mapping.second.status == Pending) { if (mapping.second.status == AssetUtils::Pending) {
++numPendingBakes; ++numPendingBakes;
} }
} }

View file

@ -34,8 +34,6 @@
MessageID AssetClient::_currentID = 0; MessageID AssetClient::_currentID = 0;
using AssetUtils::AssetMappingOperationType;
AssetClient::AssetClient() { AssetClient::AssetClient() {
_cacheDir = qApp->property(hifi::properties::APP_LOCAL_DATA_PATH).toString(); _cacheDir = qApp->property(hifi::properties::APP_LOCAL_DATA_PATH).toString();
setCustomDeleter([](Dependency* dependency){ setCustomDeleter([](Dependency* dependency){
@ -140,7 +138,7 @@ void AssetClient::handleAssetMappingOperationReply(QSharedPointer<ReceivedMessag
MessageID messageID; MessageID messageID;
message->readPrimitive(&messageID); message->readPrimitive(&messageID);
AssetServerError error; AssetUtils::AssetServerError error;
message->readPrimitive(&error); message->readPrimitive(&error);
// Check if we have any pending requests for this node // Check if we have any pending requests for this node
@ -176,7 +174,7 @@ bool haveAssetServer() {
return true; return true;
} }
GetMappingRequest* AssetClient::createGetMappingRequest(const AssetPath& path) { GetMappingRequest* AssetClient::createGetMappingRequest(const AssetUtils::AssetPath& path) {
auto request = new GetMappingRequest(path); auto request = new GetMappingRequest(path);
request->moveToThread(thread()); request->moveToThread(thread());
@ -192,7 +190,7 @@ GetAllMappingsRequest* AssetClient::createGetAllMappingsRequest() {
return request; return request;
} }
DeleteMappingsRequest* AssetClient::createDeleteMappingsRequest(const AssetPathList& paths) { DeleteMappingsRequest* AssetClient::createDeleteMappingsRequest(const AssetUtils::AssetPathList& paths) {
auto request = new DeleteMappingsRequest(paths); auto request = new DeleteMappingsRequest(paths);
request->moveToThread(thread()); request->moveToThread(thread());
@ -200,7 +198,7 @@ DeleteMappingsRequest* AssetClient::createDeleteMappingsRequest(const AssetPathL
return request; return request;
} }
SetMappingRequest* AssetClient::createSetMappingRequest(const AssetPath& path, const AssetHash& hash) { SetMappingRequest* AssetClient::createSetMappingRequest(const AssetUtils::AssetPath& path, const AssetUtils::AssetHash& hash) {
auto request = new SetMappingRequest(path, hash); auto request = new SetMappingRequest(path, hash);
request->moveToThread(thread()); request->moveToThread(thread());
@ -208,7 +206,7 @@ SetMappingRequest* AssetClient::createSetMappingRequest(const AssetPath& path, c
return request; return request;
} }
RenameMappingRequest* AssetClient::createRenameMappingRequest(const AssetPath& oldPath, const AssetPath& newPath) { RenameMappingRequest* AssetClient::createRenameMappingRequest(const AssetUtils::AssetPath& oldPath, const AssetUtils::AssetPath& newPath) {
auto request = new RenameMappingRequest(oldPath, newPath); auto request = new RenameMappingRequest(oldPath, newPath);
request->moveToThread(thread()); request->moveToThread(thread());
@ -216,7 +214,7 @@ RenameMappingRequest* AssetClient::createRenameMappingRequest(const AssetPath& o
return request; return request;
} }
SetBakingEnabledRequest* AssetClient::createSetBakingEnabledRequest(const AssetPathList& path, bool enabled) { SetBakingEnabledRequest* AssetClient::createSetBakingEnabledRequest(const AssetUtils::AssetPathList& path, bool enabled) {
auto bakingEnabledRequest = new SetBakingEnabledRequest(path, enabled); auto bakingEnabledRequest = new SetBakingEnabledRequest(path, enabled);
bakingEnabledRequest->moveToThread(thread()); bakingEnabledRequest->moveToThread(thread());
@ -224,7 +222,7 @@ SetBakingEnabledRequest* AssetClient::createSetBakingEnabledRequest(const AssetP
return bakingEnabledRequest; return bakingEnabledRequest;
} }
AssetRequest* AssetClient::createRequest(const AssetHash& hash, const ByteRange& byteRange) { AssetRequest* AssetClient::createRequest(const AssetUtils::AssetHash& hash, const ByteRange& byteRange) {
auto request = new AssetRequest(hash, byteRange); auto request = new AssetRequest(hash, byteRange);
// Move to the AssetClient thread in case we are not currently on that thread (which will usually be the case) // Move to the AssetClient thread in case we are not currently on that thread (which will usually be the case)
@ -249,7 +247,7 @@ AssetUpload* AssetClient::createUpload(const QByteArray& data) {
return upload; return upload;
} }
MessageID AssetClient::getAsset(const QString& hash, DataOffset start, DataOffset end, MessageID AssetClient::getAsset(const QString& hash, AssetUtils::DataOffset start, AssetUtils::DataOffset end,
ReceivedAssetCallback callback, ProgressCallback progressCallback) { ReceivedAssetCallback callback, ProgressCallback progressCallback) {
Q_ASSERT(QThread::currentThread() == thread()); Q_ASSERT(QThread::currentThread() == thread());
@ -284,7 +282,7 @@ MessageID AssetClient::getAsset(const QString& hash, DataOffset start, DataOffse
} }
} }
callback(false, AssetServerError::NoError, QByteArray()); callback(false, AssetUtils::AssetServerError::NoError, QByteArray());
return INVALID_MESSAGE_ID; return INVALID_MESSAGE_ID;
} }
@ -310,7 +308,7 @@ MessageID AssetClient::getAssetInfo(const QString& hash, GetInfoCallback callbac
} }
} }
callback(false, AssetServerError::NoError, { "", 0 }); callback(false, AssetUtils::AssetServerError::NoError, { "", 0 });
return INVALID_MESSAGE_ID; return INVALID_MESSAGE_ID;
} }
@ -321,12 +319,12 @@ void AssetClient::handleAssetGetInfoReply(QSharedPointer<ReceivedMessage> messag
message->readPrimitive(&messageID); message->readPrimitive(&messageID);
auto assetHash = message->read(AssetUtils::SHA256_HASH_LENGTH); auto assetHash = message->read(AssetUtils::SHA256_HASH_LENGTH);
AssetServerError error; AssetUtils::AssetServerError error;
message->readPrimitive(&error); message->readPrimitive(&error);
AssetInfo info { assetHash.toHex(), 0 }; AssetInfo info { assetHash.toHex(), 0 };
if (error == AssetServerError::NoError) { if (error == AssetUtils::AssetServerError::NoError) {
message->readPrimitive(&info.size); message->readPrimitive(&info.size);
} }
@ -359,10 +357,10 @@ void AssetClient::handleAssetGetReply(QSharedPointer<ReceivedMessage> message, S
MessageID messageID; MessageID messageID;
message->readHeadPrimitive(&messageID); message->readHeadPrimitive(&messageID);
AssetServerError error; AssetUtils::AssetServerError error;
message->readHeadPrimitive(&error); message->readHeadPrimitive(&error);
DataOffset length = 0; AssetUtils::DataOffset length = 0;
if (!error) { if (!error) {
message->readHeadPrimitive(&length); message->readHeadPrimitive(&length);
} else { } else {
@ -415,7 +413,7 @@ void AssetClient::handleAssetGetReply(QSharedPointer<ReceivedMessage> message, S
} }
void AssetClient::handleProgressCallback(const QWeakPointer<Node>& node, MessageID messageID, void AssetClient::handleProgressCallback(const QWeakPointer<Node>& node, MessageID messageID,
qint64 size, DataOffset length) { qint64 size, AssetUtils::DataOffset length) {
auto senderNode = node.toStrongRef(); auto senderNode = node.toStrongRef();
if (!senderNode) { if (!senderNode) {
@ -441,7 +439,7 @@ void AssetClient::handleProgressCallback(const QWeakPointer<Node>& node, Message
callbacks.progressCallback(size, length); callbacks.progressCallback(size, length);
} }
void AssetClient::handleCompleteCallback(const QWeakPointer<Node>& node, MessageID messageID, DataOffset length) { void AssetClient::handleCompleteCallback(const QWeakPointer<Node>& node, MessageID messageID, AssetUtils::DataOffset length) {
auto senderNode = node.toStrongRef(); auto senderNode = node.toStrongRef();
if (!senderNode) { if (!senderNode) {
@ -475,9 +473,9 @@ void AssetClient::handleCompleteCallback(const QWeakPointer<Node>& node, Message
} }
if (message->failed() || length != message->getBytesLeftToRead()) { if (message->failed() || length != message->getBytesLeftToRead()) {
callbacks.completeCallback(false, AssetServerError::NoError, QByteArray()); callbacks.completeCallback(false, AssetUtils::AssetServerError::NoError, QByteArray());
} else { } else {
callbacks.completeCallback(true, AssetServerError::NoError, message->readAll()); callbacks.completeCallback(true, AssetUtils::AssetServerError::NoError, message->readAll());
} }
// We should never get to this point without the associated senderNode and messageID // We should never get to this point without the associated senderNode and messageID
@ -488,7 +486,7 @@ void AssetClient::handleCompleteCallback(const QWeakPointer<Node>& node, Message
} }
MessageID AssetClient::getAssetMapping(const AssetPath& path, MappingOperationCallback callback) { MessageID AssetClient::getAssetMapping(const AssetUtils::AssetPath& path, MappingOperationCallback callback) {
Q_ASSERT(QThread::currentThread() == thread()); Q_ASSERT(QThread::currentThread() == thread());
auto nodeList = DependencyManager::get<NodeList>(); auto nodeList = DependencyManager::get<NodeList>();
@ -500,7 +498,7 @@ MessageID AssetClient::getAssetMapping(const AssetPath& path, MappingOperationCa
auto messageID = ++_currentID; auto messageID = ++_currentID;
packetList->writePrimitive(messageID); packetList->writePrimitive(messageID);
packetList->writePrimitive(AssetMappingOperationType::Get); packetList->writePrimitive(AssetUtils::AssetMappingOperationType::Get);
packetList->writeString(path); packetList->writeString(path);
@ -511,7 +509,7 @@ MessageID AssetClient::getAssetMapping(const AssetPath& path, MappingOperationCa
} }
} }
callback(false, AssetServerError::NoError, QSharedPointer<ReceivedMessage>()); callback(false, AssetUtils::AssetServerError::NoError, QSharedPointer<ReceivedMessage>());
return INVALID_MESSAGE_ID; return INVALID_MESSAGE_ID;
} }
@ -527,7 +525,7 @@ MessageID AssetClient::getAllAssetMappings(MappingOperationCallback callback) {
auto messageID = ++_currentID; auto messageID = ++_currentID;
packetList->writePrimitive(messageID); packetList->writePrimitive(messageID);
packetList->writePrimitive(AssetMappingOperationType::GetAll); packetList->writePrimitive(AssetUtils::AssetMappingOperationType::GetAll);
if (nodeList->sendPacketList(std::move(packetList), *assetServer) != -1) { if (nodeList->sendPacketList(std::move(packetList), *assetServer) != -1) {
_pendingMappingRequests[assetServer][messageID] = callback; _pendingMappingRequests[assetServer][messageID] = callback;
@ -536,11 +534,11 @@ MessageID AssetClient::getAllAssetMappings(MappingOperationCallback callback) {
} }
} }
callback(false, AssetServerError::NoError, QSharedPointer<ReceivedMessage>()); callback(false, AssetUtils::AssetServerError::NoError, QSharedPointer<ReceivedMessage>());
return INVALID_MESSAGE_ID; return INVALID_MESSAGE_ID;
} }
MessageID AssetClient::deleteAssetMappings(const AssetPathList& paths, MappingOperationCallback callback) { MessageID AssetClient::deleteAssetMappings(const AssetUtils::AssetPathList& paths, MappingOperationCallback callback) {
auto nodeList = DependencyManager::get<NodeList>(); auto nodeList = DependencyManager::get<NodeList>();
SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer); SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer);
@ -550,7 +548,7 @@ MessageID AssetClient::deleteAssetMappings(const AssetPathList& paths, MappingOp
auto messageID = ++_currentID; auto messageID = ++_currentID;
packetList->writePrimitive(messageID); packetList->writePrimitive(messageID);
packetList->writePrimitive(AssetMappingOperationType::Delete); packetList->writePrimitive(AssetUtils::AssetMappingOperationType::Delete);
packetList->writePrimitive(int(paths.size())); packetList->writePrimitive(int(paths.size()));
@ -565,11 +563,11 @@ MessageID AssetClient::deleteAssetMappings(const AssetPathList& paths, MappingOp
} }
} }
callback(false, AssetServerError::NoError, QSharedPointer<ReceivedMessage>()); callback(false, AssetUtils::AssetServerError::NoError, QSharedPointer<ReceivedMessage>());
return INVALID_MESSAGE_ID; return INVALID_MESSAGE_ID;
} }
MessageID AssetClient::setAssetMapping(const QString& path, const AssetHash& hash, MappingOperationCallback callback) { MessageID AssetClient::setAssetMapping(const QString& path, const AssetUtils::AssetHash& hash, MappingOperationCallback callback) {
Q_ASSERT(QThread::currentThread() == thread()); Q_ASSERT(QThread::currentThread() == thread());
auto nodeList = DependencyManager::get<NodeList>(); auto nodeList = DependencyManager::get<NodeList>();
@ -581,7 +579,7 @@ MessageID AssetClient::setAssetMapping(const QString& path, const AssetHash& has
auto messageID = ++_currentID; auto messageID = ++_currentID;
packetList->writePrimitive(messageID); packetList->writePrimitive(messageID);
packetList->writePrimitive(AssetMappingOperationType::Set); packetList->writePrimitive(AssetUtils::AssetMappingOperationType::Set);
packetList->writeString(path); packetList->writeString(path);
packetList->write(QByteArray::fromHex(hash.toUtf8())); packetList->write(QByteArray::fromHex(hash.toUtf8()));
@ -593,11 +591,11 @@ MessageID AssetClient::setAssetMapping(const QString& path, const AssetHash& has
} }
} }
callback(false, AssetServerError::NoError, QSharedPointer<ReceivedMessage>()); callback(false, AssetUtils::AssetServerError::NoError, QSharedPointer<ReceivedMessage>());
return INVALID_MESSAGE_ID; return INVALID_MESSAGE_ID;
} }
MessageID AssetClient::renameAssetMapping(const AssetPath& oldPath, const AssetPath& newPath, MappingOperationCallback callback) { MessageID AssetClient::renameAssetMapping(const AssetUtils::AssetPath& oldPath, const AssetUtils::AssetPath& newPath, MappingOperationCallback callback) {
auto nodeList = DependencyManager::get<NodeList>(); auto nodeList = DependencyManager::get<NodeList>();
SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer); SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer);
@ -607,7 +605,7 @@ MessageID AssetClient::renameAssetMapping(const AssetPath& oldPath, const AssetP
auto messageID = ++_currentID; auto messageID = ++_currentID;
packetList->writePrimitive(messageID); packetList->writePrimitive(messageID);
packetList->writePrimitive(AssetMappingOperationType::Rename); packetList->writePrimitive(AssetUtils::AssetMappingOperationType::Rename);
packetList->writeString(oldPath); packetList->writeString(oldPath);
packetList->writeString(newPath); packetList->writeString(newPath);
@ -620,11 +618,11 @@ MessageID AssetClient::renameAssetMapping(const AssetPath& oldPath, const AssetP
} }
} }
callback(false, AssetServerError::NoError, QSharedPointer<ReceivedMessage>()); callback(false, AssetUtils::AssetServerError::NoError, QSharedPointer<ReceivedMessage>());
return INVALID_MESSAGE_ID; return INVALID_MESSAGE_ID;
} }
MessageID AssetClient::setBakingEnabled(const AssetPathList& paths, bool enabled, MappingOperationCallback callback) { MessageID AssetClient::setBakingEnabled(const AssetUtils::AssetPathList& paths, bool enabled, MappingOperationCallback callback) {
auto nodeList = DependencyManager::get<NodeList>(); auto nodeList = DependencyManager::get<NodeList>();
SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer); SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer);
@ -634,7 +632,7 @@ MessageID AssetClient::setBakingEnabled(const AssetPathList& paths, bool enabled
auto messageID = ++_currentID; auto messageID = ++_currentID;
packetList->writePrimitive(messageID); packetList->writePrimitive(messageID);
packetList->writePrimitive(AssetMappingOperationType::SetBakingEnabled); packetList->writePrimitive(AssetUtils::AssetMappingOperationType::SetBakingEnabled);
packetList->writePrimitive(enabled); packetList->writePrimitive(enabled);
@ -651,7 +649,7 @@ MessageID AssetClient::setBakingEnabled(const AssetPathList& paths, bool enabled
} }
} }
callback(false, AssetServerError::NoError, QSharedPointer<ReceivedMessage>()); callback(false, AssetUtils::AssetServerError::NoError, QSharedPointer<ReceivedMessage>());
return INVALID_MESSAGE_ID; return INVALID_MESSAGE_ID;
} }
@ -735,7 +733,7 @@ MessageID AssetClient::uploadAsset(const QByteArray& data, UploadResultCallback
} }
} }
callback(false, AssetServerError::NoError, QString()); callback(false, AssetUtils::AssetServerError::NoError, QString());
return INVALID_MESSAGE_ID; return INVALID_MESSAGE_ID;
} }
@ -745,7 +743,7 @@ void AssetClient::handleAssetUploadReply(QSharedPointer<ReceivedMessage> message
MessageID messageID; MessageID messageID;
message->readPrimitive(&messageID); message->readPrimitive(&messageID);
AssetServerError error; AssetUtils::AssetServerError error;
message->readPrimitive(&error); message->readPrimitive(&error);
QString hashString; QString hashString;
@ -792,7 +790,7 @@ void AssetClient::handleNodeKilled(SharedNodePointer node) {
auto messageMapIt = _pendingUploads.find(node); auto messageMapIt = _pendingUploads.find(node);
if (messageMapIt != _pendingUploads.end()) { if (messageMapIt != _pendingUploads.end()) {
for (const auto& value : messageMapIt->second) { for (const auto& value : messageMapIt->second) {
value.second(false, AssetServerError::NoError, ""); value.second(false, AssetUtils::AssetServerError::NoError, "");
} }
messageMapIt->second.clear(); messageMapIt->second.clear();
} }
@ -824,7 +822,7 @@ void AssetClient::forceFailureOfPendingRequests(SharedNodePointer node) {
disconnect(message.data(), nullptr, this, nullptr); disconnect(message.data(), nullptr, this, nullptr);
} }
value.second.completeCallback(false, AssetServerError::NoError, QByteArray()); value.second.completeCallback(false, AssetUtils::AssetServerError::NoError, QByteArray());
} }
messageMapIt->second.clear(); messageMapIt->second.clear();
} }
@ -835,7 +833,7 @@ void AssetClient::forceFailureOfPendingRequests(SharedNodePointer node) {
if (messageMapIt != _pendingInfoRequests.end()) { if (messageMapIt != _pendingInfoRequests.end()) {
AssetInfo info { "", 0 }; AssetInfo info { "", 0 };
for (const auto& value : messageMapIt->second) { for (const auto& value : messageMapIt->second) {
value.second(false, AssetServerError::NoError, info); value.second(false, AssetUtils::AssetServerError::NoError, info);
} }
messageMapIt->second.clear(); messageMapIt->second.clear();
} }
@ -845,7 +843,7 @@ void AssetClient::forceFailureOfPendingRequests(SharedNodePointer node) {
auto messageMapIt = _pendingMappingRequests.find(node); auto messageMapIt = _pendingMappingRequests.find(node);
if (messageMapIt != _pendingMappingRequests.end()) { if (messageMapIt != _pendingMappingRequests.end()) {
for (const auto& value : messageMapIt->second) { for (const auto& value : messageMapIt->second) {
value.second(false, AssetServerError::NoError, QSharedPointer<ReceivedMessage>()); value.second(false, AssetUtils::AssetServerError::NoError, QSharedPointer<ReceivedMessage>());
} }
messageMapIt->second.clear(); messageMapIt->second.clear();
} }

View file

@ -42,12 +42,10 @@ struct AssetInfo {
int64_t size; int64_t size;
}; };
using namespace AssetUtils; using MappingOperationCallback = std::function<void(bool responseReceived, AssetUtils::AssetServerError serverError, QSharedPointer<ReceivedMessage> message)>;
using ReceivedAssetCallback = std::function<void(bool responseReceived, AssetUtils::AssetServerError serverError, const QByteArray& data)>;
using MappingOperationCallback = std::function<void(bool responseReceived, AssetServerError serverError, QSharedPointer<ReceivedMessage> message)>; using GetInfoCallback = std::function<void(bool responseReceived, AssetUtils::AssetServerError serverError, AssetInfo info)>;
using ReceivedAssetCallback = std::function<void(bool responseReceived, AssetServerError serverError, const QByteArray& data)>; using UploadResultCallback = std::function<void(bool responseReceived, AssetUtils::AssetServerError serverError, const QString& hash)>;
using GetInfoCallback = std::function<void(bool responseReceived, AssetServerError serverError, AssetInfo info)>;
using UploadResultCallback = std::function<void(bool responseReceived, AssetServerError serverError, const QString& hash)>;
using ProgressCallback = std::function<void(qint64 totalReceived, qint64 total)>; using ProgressCallback = std::function<void(qint64 totalReceived, qint64 total)>;
class AssetClient : public QObject, public Dependency { class AssetClient : public QObject, public Dependency {
@ -55,13 +53,13 @@ class AssetClient : public QObject, public Dependency {
public: public:
AssetClient(); AssetClient();
Q_INVOKABLE GetMappingRequest* createGetMappingRequest(const AssetPath& path); Q_INVOKABLE GetMappingRequest* createGetMappingRequest(const AssetUtils::AssetPath& path);
Q_INVOKABLE GetAllMappingsRequest* createGetAllMappingsRequest(); Q_INVOKABLE GetAllMappingsRequest* createGetAllMappingsRequest();
Q_INVOKABLE DeleteMappingsRequest* createDeleteMappingsRequest(const AssetPathList& paths); Q_INVOKABLE DeleteMappingsRequest* createDeleteMappingsRequest(const AssetUtils::AssetPathList& paths);
Q_INVOKABLE SetMappingRequest* createSetMappingRequest(const AssetPath& path, const AssetHash& hash); Q_INVOKABLE SetMappingRequest* createSetMappingRequest(const AssetUtils::AssetPath& path, const AssetUtils::AssetHash& hash);
Q_INVOKABLE RenameMappingRequest* createRenameMappingRequest(const AssetPath& oldPath, const AssetPath& newPath); Q_INVOKABLE RenameMappingRequest* createRenameMappingRequest(const AssetUtils::AssetPath& oldPath, const AssetUtils::AssetPath& newPath);
Q_INVOKABLE SetBakingEnabledRequest* createSetBakingEnabledRequest(const AssetPathList& path, bool enabled); Q_INVOKABLE SetBakingEnabledRequest* createSetBakingEnabledRequest(const AssetUtils::AssetPathList& path, bool enabled);
Q_INVOKABLE AssetRequest* createRequest(const AssetHash& hash, const ByteRange& byteRange = ByteRange()); Q_INVOKABLE AssetRequest* createRequest(const AssetUtils::AssetHash& hash, const ByteRange& byteRange = ByteRange());
Q_INVOKABLE AssetUpload* createUpload(const QString& filename); Q_INVOKABLE AssetUpload* createUpload(const QString& filename);
Q_INVOKABLE AssetUpload* createUpload(const QByteArray& data); Q_INVOKABLE AssetUpload* createUpload(const QByteArray& data);
@ -82,15 +80,15 @@ private slots:
void handleNodeClientConnectionReset(SharedNodePointer node); void handleNodeClientConnectionReset(SharedNodePointer node);
private: private:
MessageID getAssetMapping(const AssetHash& hash, MappingOperationCallback callback); MessageID getAssetMapping(const AssetUtils::AssetHash& hash, MappingOperationCallback callback);
MessageID getAllAssetMappings(MappingOperationCallback callback); MessageID getAllAssetMappings(MappingOperationCallback callback);
MessageID setAssetMapping(const QString& path, const AssetHash& hash, MappingOperationCallback callback); MessageID setAssetMapping(const QString& path, const AssetUtils::AssetHash& hash, MappingOperationCallback callback);
MessageID deleteAssetMappings(const AssetPathList& paths, MappingOperationCallback callback); MessageID deleteAssetMappings(const AssetUtils::AssetPathList& paths, MappingOperationCallback callback);
MessageID renameAssetMapping(const AssetPath& oldPath, const AssetPath& newPath, MappingOperationCallback callback); MessageID renameAssetMapping(const AssetUtils::AssetPath& oldPath, const AssetUtils::AssetPath& newPath, MappingOperationCallback callback);
MessageID setBakingEnabled(const AssetPathList& paths, bool enabled, MappingOperationCallback callback); MessageID setBakingEnabled(const AssetUtils::AssetPathList& paths, bool enabled, MappingOperationCallback callback);
MessageID getAssetInfo(const QString& hash, GetInfoCallback callback); MessageID getAssetInfo(const QString& hash, GetInfoCallback callback);
MessageID getAsset(const QString& hash, DataOffset start, DataOffset end, MessageID getAsset(const QString& hash, AssetUtils::DataOffset start, AssetUtils::DataOffset end,
ReceivedAssetCallback callback, ProgressCallback progressCallback); ReceivedAssetCallback callback, ProgressCallback progressCallback);
MessageID uploadAsset(const QByteArray& data, UploadResultCallback callback); MessageID uploadAsset(const QByteArray& data, UploadResultCallback callback);
@ -99,8 +97,8 @@ private:
bool cancelGetAssetRequest(MessageID id); bool cancelGetAssetRequest(MessageID id);
bool cancelUploadAssetRequest(MessageID id); bool cancelUploadAssetRequest(MessageID id);
void handleProgressCallback(const QWeakPointer<Node>& node, MessageID messageID, qint64 size, DataOffset length); void handleProgressCallback(const QWeakPointer<Node>& node, MessageID messageID, qint64 size, AssetUtils::DataOffset length);
void handleCompleteCallback(const QWeakPointer<Node>& node, MessageID messageID, DataOffset length); void handleCompleteCallback(const QWeakPointer<Node>& node, MessageID messageID, AssetUtils::DataOffset length);
void forceFailureOfPendingRequests(SharedNodePointer node); void forceFailureOfPendingRequests(SharedNodePointer node);

View file

@ -80,7 +80,7 @@ void AssetRequest::start() {
auto hash = _hash; auto hash = _hash;
_assetRequestID = assetClient->getAsset(_hash, _byteRange.fromInclusive, _byteRange.toExclusive, _assetRequestID = assetClient->getAsset(_hash, _byteRange.fromInclusive, _byteRange.toExclusive,
[this, that, hash](bool responseReceived, AssetServerError serverError, const QByteArray& data) { [this, that, hash](bool responseReceived, AssetUtils::AssetServerError serverError, const QByteArray& data) {
if (!that) { if (!that) {
qCWarning(asset_client) << "Got reply for dead asset request " << hash << "- error code" << _error; qCWarning(asset_client) << "Got reply for dead asset request " << hash << "- error code" << _error;
@ -91,12 +91,12 @@ void AssetRequest::start() {
if (!responseReceived) { if (!responseReceived) {
_error = NetworkError; _error = NetworkError;
} else if (serverError != AssetServerError::NoError) { } else if (serverError != AssetUtils::AssetServerError::NoError) {
switch (serverError) { switch (serverError) {
case AssetServerError::AssetNotFound: case AssetUtils::AssetServerError::AssetNotFound:
_error = NotFound; _error = NotFound;
break; break;
case AssetServerError::InvalidByteRange: case AssetUtils::AssetServerError::InvalidByteRange:
_error = InvalidByteRange; _error = InvalidByteRange;
break; break;
default: default:

View file

@ -68,7 +68,7 @@ void AssetResourceRequest::doSend() {
} }
} }
void AssetResourceRequest::requestMappingForPath(const AssetPath& path) { void AssetResourceRequest::requestMappingForPath(const AssetUtils::AssetPath& path) {
auto statTracker = DependencyManager::get<StatTracker>(); auto statTracker = DependencyManager::get<StatTracker>();
statTracker->incrementStat(STAT_ATP_MAPPING_REQUEST_STARTED); statTracker->incrementStat(STAT_ATP_MAPPING_REQUEST_STARTED);
@ -140,7 +140,7 @@ void AssetResourceRequest::requestMappingForPath(const AssetPath& path) {
_assetMappingRequest->start(); _assetMappingRequest->start();
} }
void AssetResourceRequest::requestHash(const AssetHash& hash) { void AssetResourceRequest::requestHash(const AssetUtils::AssetHash& hash) {
// Make request to atp // Make request to atp
auto assetClient = DependencyManager::get<AssetClient>(); auto assetClient = DependencyManager::get<AssetClient>();
_assetRequest = assetClient->createRequest(hash, _byteRange); _assetRequest = assetClient->createRequest(hash, _byteRange);

View file

@ -34,8 +34,8 @@ private slots:
private: private:
static bool urlIsAssetHash(const QUrl& url); static bool urlIsAssetHash(const QUrl& url);
void requestMappingForPath(const AssetPath& path); void requestMappingForPath(const AssetUtils::AssetPath& path);
void requestHash(const AssetHash& hash); void requestHash(const AssetUtils::AssetHash& hash);
GetMappingRequest* _assetMappingRequest { nullptr }; GetMappingRequest* _assetMappingRequest { nullptr };
AssetRequest* _assetRequest { nullptr }; AssetRequest* _assetRequest { nullptr };

View file

@ -81,21 +81,21 @@ void AssetUpload::start() {
qCDebug(asset_client) << "Attempting to upload" << _filename << "to asset-server."; qCDebug(asset_client) << "Attempting to upload" << _filename << "to asset-server.";
} }
assetClient->uploadAsset(_data, [this](bool responseReceived, AssetServerError error, const QString& hash){ assetClient->uploadAsset(_data, [this](bool responseReceived, AssetUtils::AssetServerError error, const QString& hash){
if (!responseReceived) { if (!responseReceived) {
_error = NetworkError; _error = NetworkError;
} else { } else {
switch (error) { switch (error) {
case AssetServerError::NoError: case AssetUtils::AssetServerError::NoError:
_error = NoError; _error = NoError;
break; break;
case AssetServerError::AssetTooLarge: case AssetUtils::AssetServerError::AssetTooLarge:
_error = TooLarge; _error = TooLarge;
break; break;
case AssetServerError::PermissionDenied: case AssetUtils::AssetServerError::PermissionDenied:
_error = PermissionDenied; _error = PermissionDenied;
break; break;
case AssetServerError::FileOperationFailed: case AssetUtils::AssetServerError::FileOperationFailed:
_error = ServerFileError; _error = ServerFileError;
break; break;
default: default:

View file

@ -51,13 +51,13 @@ QString MappingRequest::getErrorString() const {
} }
} }
GetMappingRequest::GetMappingRequest(const AssetPath& path) : _path(path.trimmed()) { GetMappingRequest::GetMappingRequest(const AssetUtils::AssetPath& path) : _path(path.trimmed()) {
}; };
void GetMappingRequest::doStart() { void GetMappingRequest::doStart() {
// short circuit the request if the path is invalid // short circuit the request if the path is invalid
if (!isValidFilePath(_path)) { if (!AssetUtils::isValidFilePath(_path)) {
_error = MappingRequest::InvalidPath; _error = MappingRequest::InvalidPath;
emit finished(this); emit finished(this);
return; return;
@ -66,17 +66,17 @@ void GetMappingRequest::doStart() {
auto assetClient = DependencyManager::get<AssetClient>(); auto assetClient = DependencyManager::get<AssetClient>();
_mappingRequestID = assetClient->getAssetMapping(_path, _mappingRequestID = assetClient->getAssetMapping(_path,
[this, assetClient](bool responseReceived, AssetServerError error, QSharedPointer<ReceivedMessage> message) { [this, assetClient](bool responseReceived, AssetUtils::AssetServerError error, QSharedPointer<ReceivedMessage> message) {
_mappingRequestID = INVALID_MESSAGE_ID; _mappingRequestID = INVALID_MESSAGE_ID;
if (!responseReceived) { if (!responseReceived) {
_error = NetworkError; _error = NetworkError;
} else { } else {
switch (error) { switch (error) {
case AssetServerError::NoError: case AssetUtils::AssetServerError::NoError:
_error = NoError; _error = NoError;
break; break;
case AssetServerError::AssetNotFound: case AssetUtils::AssetServerError::AssetNotFound:
_error = NotFound; _error = NotFound;
break; break;
default: default:
@ -86,7 +86,7 @@ void GetMappingRequest::doStart() {
} }
if (!_error) { if (!_error) {
_hash = message->read(SHA256_HASH_LENGTH).toHex(); _hash = message->read(AssetUtils::SHA256_HASH_LENGTH).toHex();
// check the boolean to see if this request got re-directed // check the boolean to see if this request got re-directed
quint8 wasRedirected; quint8 wasRedirected;
@ -112,7 +112,7 @@ GetAllMappingsRequest::GetAllMappingsRequest() {
void GetAllMappingsRequest::doStart() { void GetAllMappingsRequest::doStart() {
auto assetClient = DependencyManager::get<AssetClient>(); auto assetClient = DependencyManager::get<AssetClient>();
_mappingRequestID = assetClient->getAllAssetMappings( _mappingRequestID = assetClient->getAllAssetMappings(
[this, assetClient](bool responseReceived, AssetServerError error, QSharedPointer<ReceivedMessage> message) { [this, assetClient](bool responseReceived, AssetUtils::AssetServerError error, QSharedPointer<ReceivedMessage> message) {
_mappingRequestID = INVALID_MESSAGE_ID; _mappingRequestID = INVALID_MESSAGE_ID;
@ -120,7 +120,7 @@ void GetAllMappingsRequest::doStart() {
_error = NetworkError; _error = NetworkError;
} else { } else {
switch (error) { switch (error) {
case AssetServerError::NoError: case AssetUtils::AssetServerError::NoError:
_error = NoError; _error = NoError;
break; break;
default: default:
@ -135,11 +135,11 @@ void GetAllMappingsRequest::doStart() {
message->readPrimitive(&numberOfMappings); message->readPrimitive(&numberOfMappings);
for (uint32_t i = 0; i < numberOfMappings; ++i) { for (uint32_t i = 0; i < numberOfMappings; ++i) {
auto path = message->readString(); auto path = message->readString();
auto hash = message->read(SHA256_HASH_LENGTH).toHex(); auto hash = message->read(AssetUtils::SHA256_HASH_LENGTH).toHex();
BakingStatus status; AssetUtils::BakingStatus status;
QString lastBakeErrors; QString lastBakeErrors;
message->readPrimitive(&status); message->readPrimitive(&status);
if (status == BakingStatus::Error) { if (status == AssetUtils::BakingStatus::Error) {
lastBakeErrors = message->readString(); lastBakeErrors = message->readString();
} }
_mappings[path] = { hash, status, lastBakeErrors }; _mappings[path] = { hash, status, lastBakeErrors };
@ -149,7 +149,7 @@ void GetAllMappingsRequest::doStart() {
}); });
}; };
SetMappingRequest::SetMappingRequest(const AssetPath& path, const AssetHash& hash) : SetMappingRequest::SetMappingRequest(const AssetUtils::AssetPath& path, const AssetUtils::AssetHash& hash) :
_path(path.trimmed()), _path(path.trimmed()),
_hash(hash) _hash(hash)
{ {
@ -159,8 +159,8 @@ SetMappingRequest::SetMappingRequest(const AssetPath& path, const AssetHash& has
void SetMappingRequest::doStart() { void SetMappingRequest::doStart() {
// short circuit the request if the hash or path are invalid // short circuit the request if the hash or path are invalid
auto validPath = isValidFilePath(_path); auto validPath = AssetUtils::isValidFilePath(_path);
auto validHash = isValidHash(_hash); auto validHash = AssetUtils::isValidHash(_hash);
if (!validPath || !validHash) { if (!validPath || !validHash) {
_error = !validPath ? MappingRequest::InvalidPath : MappingRequest::InvalidHash; _error = !validPath ? MappingRequest::InvalidPath : MappingRequest::InvalidHash;
emit finished(this); emit finished(this);
@ -170,17 +170,17 @@ void SetMappingRequest::doStart() {
auto assetClient = DependencyManager::get<AssetClient>(); auto assetClient = DependencyManager::get<AssetClient>();
_mappingRequestID = assetClient->setAssetMapping(_path, _hash, _mappingRequestID = assetClient->setAssetMapping(_path, _hash,
[this, assetClient](bool responseReceived, AssetServerError error, QSharedPointer<ReceivedMessage> message) { [this, assetClient](bool responseReceived, AssetUtils::AssetServerError error, QSharedPointer<ReceivedMessage> message) {
_mappingRequestID = INVALID_MESSAGE_ID; _mappingRequestID = INVALID_MESSAGE_ID;
if (!responseReceived) { if (!responseReceived) {
_error = NetworkError; _error = NetworkError;
} else { } else {
switch (error) { switch (error) {
case AssetServerError::NoError: case AssetUtils::AssetServerError::NoError:
_error = NoError; _error = NoError;
break; break;
case AssetServerError::PermissionDenied: case AssetUtils::AssetServerError::PermissionDenied:
_error = PermissionDenied; _error = PermissionDenied;
break; break;
default: default:
@ -193,7 +193,7 @@ void SetMappingRequest::doStart() {
}); });
}; };
DeleteMappingsRequest::DeleteMappingsRequest(const AssetPathList& paths) : _paths(paths) { DeleteMappingsRequest::DeleteMappingsRequest(const AssetUtils::AssetPathList& paths) : _paths(paths) {
for (auto& path : _paths) { for (auto& path : _paths) {
path = path.trimmed(); path = path.trimmed();
} }
@ -203,7 +203,7 @@ void DeleteMappingsRequest::doStart() {
// short circuit the request if any of the paths are invalid // short circuit the request if any of the paths are invalid
for (auto& path : _paths) { for (auto& path : _paths) {
if (!isValidPath(path)) { if (!AssetUtils::isValidPath(path)) {
_error = MappingRequest::InvalidPath; _error = MappingRequest::InvalidPath;
emit finished(this); emit finished(this);
return; return;
@ -213,17 +213,17 @@ void DeleteMappingsRequest::doStart() {
auto assetClient = DependencyManager::get<AssetClient>(); auto assetClient = DependencyManager::get<AssetClient>();
_mappingRequestID = assetClient->deleteAssetMappings(_paths, _mappingRequestID = assetClient->deleteAssetMappings(_paths,
[this, assetClient](bool responseReceived, AssetServerError error, QSharedPointer<ReceivedMessage> message) { [this, assetClient](bool responseReceived, AssetUtils::AssetServerError error, QSharedPointer<ReceivedMessage> message) {
_mappingRequestID = INVALID_MESSAGE_ID; _mappingRequestID = INVALID_MESSAGE_ID;
if (!responseReceived) { if (!responseReceived) {
_error = NetworkError; _error = NetworkError;
} else { } else {
switch (error) { switch (error) {
case AssetServerError::NoError: case AssetUtils::AssetServerError::NoError:
_error = NoError; _error = NoError;
break; break;
case AssetServerError::PermissionDenied: case AssetUtils::AssetServerError::PermissionDenied:
_error = PermissionDenied; _error = PermissionDenied;
break; break;
default: default:
@ -236,7 +236,7 @@ void DeleteMappingsRequest::doStart() {
}); });
}; };
RenameMappingRequest::RenameMappingRequest(const AssetPath& oldPath, const AssetPath& newPath) : RenameMappingRequest::RenameMappingRequest(const AssetUtils::AssetPath& oldPath, const AssetUtils::AssetPath& newPath) :
_oldPath(oldPath.trimmed()), _oldPath(oldPath.trimmed()),
_newPath(newPath.trimmed()) _newPath(newPath.trimmed())
{ {
@ -246,7 +246,7 @@ RenameMappingRequest::RenameMappingRequest(const AssetPath& oldPath, const Asset
void RenameMappingRequest::doStart() { void RenameMappingRequest::doStart() {
// short circuit the request if either of the paths are invalid // short circuit the request if either of the paths are invalid
if (!isValidFilePath(_oldPath) || !isValidFilePath(_newPath)) { if (!AssetUtils::isValidFilePath(_oldPath) || !AssetUtils::isValidFilePath(_newPath)) {
_error = InvalidPath; _error = InvalidPath;
emit finished(this); emit finished(this);
return; return;
@ -255,17 +255,17 @@ void RenameMappingRequest::doStart() {
auto assetClient = DependencyManager::get<AssetClient>(); auto assetClient = DependencyManager::get<AssetClient>();
_mappingRequestID = assetClient->renameAssetMapping(_oldPath, _newPath, _mappingRequestID = assetClient->renameAssetMapping(_oldPath, _newPath,
[this, assetClient](bool responseReceived, AssetServerError error, QSharedPointer<ReceivedMessage> message) { [this, assetClient](bool responseReceived, AssetUtils::AssetServerError error, QSharedPointer<ReceivedMessage> message) {
_mappingRequestID = INVALID_MESSAGE_ID; _mappingRequestID = INVALID_MESSAGE_ID;
if (!responseReceived) { if (!responseReceived) {
_error = NetworkError; _error = NetworkError;
} else { } else {
switch (error) { switch (error) {
case AssetServerError::NoError: case AssetUtils::AssetServerError::NoError:
_error = NoError; _error = NoError;
break; break;
case AssetServerError::PermissionDenied: case AssetUtils::AssetServerError::PermissionDenied:
_error = PermissionDenied; _error = PermissionDenied;
break; break;
default: default:
@ -278,7 +278,7 @@ void RenameMappingRequest::doStart() {
}); });
} }
SetBakingEnabledRequest::SetBakingEnabledRequest(const AssetPathList& paths, bool enabled) : _paths(paths), _enabled(enabled) { SetBakingEnabledRequest::SetBakingEnabledRequest(const AssetUtils::AssetPathList& paths, bool enabled) : _paths(paths), _enabled(enabled) {
for (auto& path : _paths) { for (auto& path : _paths) {
path = path.trimmed(); path = path.trimmed();
} }
@ -288,7 +288,7 @@ void SetBakingEnabledRequest::doStart() {
// short circuit the request if any of the paths are invalid // short circuit the request if any of the paths are invalid
for (auto& path : _paths) { for (auto& path : _paths) {
if (!isValidPath(path)) { if (!AssetUtils::isValidPath(path)) {
_error = MappingRequest::InvalidPath; _error = MappingRequest::InvalidPath;
emit finished(this); emit finished(this);
return; return;
@ -298,17 +298,17 @@ void SetBakingEnabledRequest::doStart() {
auto assetClient = DependencyManager::get<AssetClient>(); auto assetClient = DependencyManager::get<AssetClient>();
_mappingRequestID = assetClient->setBakingEnabled(_paths, _enabled, _mappingRequestID = assetClient->setBakingEnabled(_paths, _enabled,
[this, assetClient](bool responseReceived, AssetServerError error, QSharedPointer<ReceivedMessage> message) { [this, assetClient](bool responseReceived, AssetUtils::AssetServerError error, QSharedPointer<ReceivedMessage> message) {
_mappingRequestID = INVALID_MESSAGE_ID; _mappingRequestID = INVALID_MESSAGE_ID;
if (!responseReceived) { if (!responseReceived) {
_error = NetworkError; _error = NetworkError;
} else { } else {
switch (error) { switch (error) {
case AssetServerError::NoError: case AssetUtils::AssetServerError::NoError:
_error = NoError; _error = NoError;
break; break;
case AssetServerError::PermissionDenied: case AssetUtils::AssetServerError::PermissionDenied:
_error = PermissionDenied; _error = PermissionDenied;
break; break;
default: default:
@ -319,4 +319,4 @@ void SetBakingEnabledRequest::doStart() {
emit finished(this); emit finished(this);
}); });
}; };

View file

@ -50,10 +50,10 @@ private:
class GetMappingRequest : public MappingRequest { class GetMappingRequest : public MappingRequest {
Q_OBJECT Q_OBJECT
public: public:
GetMappingRequest(const AssetPath& path); GetMappingRequest(const AssetUtils::AssetPath& path);
AssetHash getHash() const { return _hash; } AssetUtils::AssetHash getHash() const { return _hash; }
AssetPath getRedirectedPath() const { return _redirectedPath; } AssetUtils::AssetPath getRedirectedPath() const { return _redirectedPath; }
bool wasRedirected() const { return _wasRedirected; } bool wasRedirected() const { return _wasRedirected; }
signals: signals:
@ -62,21 +62,21 @@ signals:
private: private:
virtual void doStart() override; virtual void doStart() override;
AssetPath _path; AssetUtils::AssetPath _path;
AssetHash _hash; AssetUtils::AssetHash _hash;
AssetPath _redirectedPath; AssetUtils::AssetPath _redirectedPath;
bool _wasRedirected { false }; bool _wasRedirected { false };
}; };
class SetMappingRequest : public MappingRequest { class SetMappingRequest : public MappingRequest {
Q_OBJECT Q_OBJECT
public: public:
SetMappingRequest(const AssetPath& path, const AssetHash& hash); SetMappingRequest(const AssetUtils::AssetPath& path, const AssetUtils::AssetHash& hash);
AssetPath getPath() const { return _path; } AssetUtils::AssetPath getPath() const { return _path; }
AssetHash getHash() const { return _hash; } AssetUtils::AssetHash getHash() const { return _hash; }
signals: signals:
void finished(SetMappingRequest* thisRequest); void finished(SetMappingRequest* thisRequest);
@ -84,14 +84,14 @@ signals:
private: private:
virtual void doStart() override; virtual void doStart() override;
AssetPath _path; AssetUtils::AssetPath _path;
AssetHash _hash; AssetUtils::AssetHash _hash;
}; };
class DeleteMappingsRequest : public MappingRequest { class DeleteMappingsRequest : public MappingRequest {
Q_OBJECT Q_OBJECT
public: public:
DeleteMappingsRequest(const AssetPathList& path); DeleteMappingsRequest(const AssetUtils::AssetPathList& path);
signals: signals:
void finished(DeleteMappingsRequest* thisRequest); void finished(DeleteMappingsRequest* thisRequest);
@ -99,13 +99,13 @@ signals:
private: private:
virtual void doStart() override; virtual void doStart() override;
AssetPathList _paths; AssetUtils::AssetPathList _paths;
}; };
class RenameMappingRequest : public MappingRequest { class RenameMappingRequest : public MappingRequest {
Q_OBJECT Q_OBJECT
public: public:
RenameMappingRequest(const AssetPath& oldPath, const AssetPath& newPath); RenameMappingRequest(const AssetUtils::AssetPath& oldPath, const AssetUtils::AssetPath& newPath);
signals: signals:
void finished(RenameMappingRequest* thisRequest); void finished(RenameMappingRequest* thisRequest);
@ -113,8 +113,8 @@ signals:
private: private:
virtual void doStart() override; virtual void doStart() override;
AssetPath _oldPath; AssetUtils::AssetPath _oldPath;
AssetPath _newPath; AssetUtils::AssetPath _newPath;
}; };
class GetAllMappingsRequest : public MappingRequest { class GetAllMappingsRequest : public MappingRequest {
@ -122,7 +122,7 @@ class GetAllMappingsRequest : public MappingRequest {
public: public:
GetAllMappingsRequest(); GetAllMappingsRequest();
AssetMapping getMappings() const { return _mappings; } AssetUtils::AssetMapping getMappings() const { return _mappings; }
signals: signals:
void finished(GetAllMappingsRequest* thisRequest); void finished(GetAllMappingsRequest* thisRequest);
@ -130,13 +130,13 @@ signals:
private: private:
virtual void doStart() override; virtual void doStart() override;
AssetMapping _mappings; AssetUtils::AssetMapping _mappings;
}; };
class SetBakingEnabledRequest : public MappingRequest { class SetBakingEnabledRequest : public MappingRequest {
Q_OBJECT Q_OBJECT
public: public:
SetBakingEnabledRequest(const AssetPathList& path, bool enabled); SetBakingEnabledRequest(const AssetUtils::AssetPathList& path, bool enabled);
signals: signals:
void finished(SetBakingEnabledRequest* thisRequest); void finished(SetBakingEnabledRequest* thisRequest);
@ -144,7 +144,7 @@ signals:
private: private:
virtual void doStart() override; virtual void doStart() override;
AssetPathList _paths; AssetUtils::AssetPathList _paths;
bool _enabled; bool _enabled;
}; };