// // AssetClient.h // libraries/networking/src // // Created by Ryan Huffman on 2015/07/21 // Copyright 2015 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #ifndef hifi_AssetClient_h #define hifi_AssetClient_h #include #include #include "AssetUtils.h" #include "LimitedNodeList.h" #include "NLPacket.h" #include "Node.h" class AssetRequest; class AssetUpload; struct AssetInfo { QString hash; int64_t size; }; using ReceivedAssetCallback = std::function; using GetInfoCallback = std::function; using UploadResultCallback = std::function; class AssetClient : public QObject, public Dependency { Q_OBJECT public: AssetClient(); Q_INVOKABLE void init(); Q_INVOKABLE AssetRequest* createRequest(const QString& hash, const QString& extension); Q_INVOKABLE AssetUpload* createUpload(const QString& filename); private slots: void handleAssetGetInfoReply(QSharedPointer packet, SharedNodePointer senderNode); void handleAssetGetReply(QSharedPointer packetList, SharedNodePointer senderNode); void handleAssetUploadReply(QSharedPointer packet, SharedNodePointer senderNode); void handleNodeKilled(SharedNodePointer node); private: bool getAssetInfo(const QString& hash, const QString& extension, GetInfoCallback callback); bool getAsset(const QString& hash, const QString& extension, DataOffset start, DataOffset end, ReceivedAssetCallback callback); bool uploadAsset(const QByteArray& data, const QString& extension, UploadResultCallback callback); static MessageID _currentID; std::unordered_map> _pendingRequests; std::unordered_map> _pendingInfoRequests; std::unordered_map> _pendingUploads; friend class AssetRequest; friend class AssetUpload; }; #endif