mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 01:13:11 +02:00
Add AssetScriptingInterface methods for mapping
This commit is contained in:
parent
462f00077c
commit
7dd436a7a8
2 changed files with 92 additions and 3 deletions
|
@ -622,3 +622,39 @@ void AssetScriptingInterface::downloadData(QString urlString, QScriptValue callb
|
|||
|
||||
assetRequest->start();
|
||||
}
|
||||
|
||||
void AssetScriptingInterface::setMapping(QString path, QString hash, QScriptValue callback) {
|
||||
auto assetClient = DependencyManager::get<AssetClient>();
|
||||
auto request = assetClient->createSetMappingRequest(path, hash);
|
||||
|
||||
connect(request, &SetMappingRequest::finished, this, [this, callback](SetMappingRequest* request) mutable {
|
||||
QScriptValueList args { uint8_t(request->getError()) };
|
||||
|
||||
callback.call(_engine->currentContext()->thisObject(), args);
|
||||
|
||||
request->deleteLater();
|
||||
|
||||
});
|
||||
|
||||
request->start();
|
||||
}
|
||||
|
||||
void AssetScriptingInterface::getMapping(QString path, QScriptValue callback) {
|
||||
auto assetClient = DependencyManager::get<AssetClient>();
|
||||
auto request = assetClient->createGetMappingRequest(path);
|
||||
|
||||
connect(request, &GetMappingRequest::finished, this, [this, callback](GetMappingRequest* request) mutable {
|
||||
QScriptValueList args { uint8_t(request->getError()), request->getHash() };
|
||||
|
||||
callback.call(_engine->currentContext()->thisObject(), args);
|
||||
|
||||
request->deleteLater();
|
||||
|
||||
});
|
||||
|
||||
request->start();
|
||||
}
|
||||
|
||||
void AssetScriptingInterface::getAllMappings(QString path, QScriptValue callback) {
|
||||
}
|
||||
>>>>>>> 6dd3b1b... Add AssetScriptingInterface methods for mapping
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include "ReceivedMessage.h"
|
||||
#include "ResourceCache.h"
|
||||
|
||||
class GetMappingRequest;
|
||||
class SetMappingRequest;
|
||||
class AssetRequest;
|
||||
class AssetUpload;
|
||||
|
||||
|
@ -33,19 +35,61 @@ struct AssetInfo {
|
|||
int64_t size;
|
||||
};
|
||||
|
||||
using MappingOperationCallback = std::function<void(bool responseReceived, AssetServerError serverError, QSharedPointer<ReceivedMessage> message)>;
|
||||
using ReceivedAssetCallback = std::function<void(bool responseReceived, AssetServerError serverError, const QByteArray& data)>;
|
||||
using MappingOperationCallback = std::function<void(bool responseReceived, 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)>;
|
||||
|
||||
|
||||
class GetMappingRequest : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
GetMappingRequest(AssetPath path);
|
||||
|
||||
Q_INVOKABLE void start();
|
||||
|
||||
AssetHash getHash() { return _hash; }
|
||||
AssetServerError getError() { return _error; }
|
||||
|
||||
signals:
|
||||
void finished(GetMappingRequest* thisRequest);
|
||||
|
||||
private:
|
||||
AssetPath _path;
|
||||
AssetHash _hash;
|
||||
AssetServerError _error { AssetServerError::NoError };
|
||||
};
|
||||
|
||||
|
||||
class SetMappingRequest : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SetMappingRequest(AssetPath path, AssetHash hash);
|
||||
|
||||
Q_INVOKABLE void start();
|
||||
|
||||
AssetHash getHash() { return _hash; }
|
||||
AssetServerError getError() { return _error; }
|
||||
|
||||
signals:
|
||||
void finished(SetMappingRequest* thisRequest);
|
||||
|
||||
private:
|
||||
AssetPath _path;
|
||||
AssetHash _hash;
|
||||
AssetServerError _error { AssetServerError::NoError };
|
||||
};
|
||||
|
||||
|
||||
class AssetClient : public QObject, public Dependency {
|
||||
Q_OBJECT
|
||||
public:
|
||||
AssetClient();
|
||||
|
||||
Q_INVOKABLE AssetRequest* createRequest(const QString& hash, const QString& extension);
|
||||
Q_INVOKABLE GetMappingRequest* createGetMappingRequest(const AssetPath& path);
|
||||
Q_INVOKABLE SetMappingRequest* createSetMappingRequest(const AssetPath& path, const AssetHash& hash);
|
||||
Q_INVOKABLE AssetRequest* createRequest(const AssetHash& hash, const QString& extension);
|
||||
Q_INVOKABLE AssetUpload* createUpload(const QString& filename);
|
||||
Q_INVOKABLE AssetUpload* createUpload(const QByteArray& data, const QString& extension);
|
||||
|
||||
|
@ -56,6 +100,7 @@ public slots:
|
|||
void clearCache();
|
||||
|
||||
private slots:
|
||||
void handleAssetMappingOperationReply(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode);
|
||||
void handleAssetGetInfoReply(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode);
|
||||
void handleAssetGetReply(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode);
|
||||
void handleAssetUploadReply(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode);
|
||||
|
@ -63,7 +108,10 @@ private slots:
|
|||
void handleNodeKilled(SharedNodePointer node);
|
||||
|
||||
private:
|
||||
bool getAssetMapping(const QString& path, MappingOperationCallback callback);
|
||||
bool getAssetMapping(const AssetHash& hash, MappingOperationCallback callback);
|
||||
bool setAssetMapping(const QString& path, const AssetHash& hash, MappingOperationCallback callback);
|
||||
bool deleteAssetMapping(const AssetHash& hash, MappingOperationCallback callback);
|
||||
|
||||
bool getAssetInfo(const QString& hash, const QString& extension, GetInfoCallback callback);
|
||||
bool getAsset(const QString& hash, const QString& extension, DataOffset start, DataOffset end,
|
||||
ReceivedAssetCallback callback, ProgressCallback progressCallback);
|
||||
|
@ -82,6 +130,8 @@ private:
|
|||
|
||||
friend class AssetRequest;
|
||||
friend class AssetUpload;
|
||||
friend class GetMappingRequest;
|
||||
friend class SetMappingRequest;
|
||||
};
|
||||
|
||||
|
||||
|
@ -92,6 +142,9 @@ public:
|
|||
|
||||
Q_INVOKABLE void uploadData(QString data, QString extension, QScriptValue callback);
|
||||
Q_INVOKABLE void downloadData(QString url, QScriptValue downloadComplete);
|
||||
Q_INVOKABLE void setMapping(QString path, QString hash, QScriptValue callback);
|
||||
Q_INVOKABLE void getMapping(QString path, QScriptValue callback);
|
||||
Q_INVOKABLE void getAllMappings(QString path, QScriptValue callback);
|
||||
protected:
|
||||
QSet<AssetRequest*> _pendingRequests;
|
||||
QScriptEngine* _engine;
|
||||
|
|
Loading…
Reference in a new issue