SendObject now the owner of the object to be sent

This commit is contained in:
Ralph Wessel
2024-10-03 12:33:08 +01:00
parent 1a901b0a6c
commit 8539129e7c
5 changed files with 16 additions and 10 deletions
@@ -60,7 +60,9 @@ Cargo::Unique SendObject::getCargo(const active::serialise::Inventory::Item& ite
case idID:
return std::make_unique<StringWrap>(id);
case rootObjID:
return std::make_unique<PackageWrap>(base::get());
if (m_object)
return std::make_unique<PackageWrap>(*m_object);
return std::make_unique<NullPackage>();
default:
return nullptr; //Requested an unknown index
}
@@ -11,7 +11,7 @@ namespace connector::interfac::browser::bridge {
/*!
Class defining the primary content of a send
*/
class SendObject final : public active::serialise::Package, public std::reference_wrapper<active::serialise::Package> {
class SendObject final : public active::serialise::Package {
public:
using base = std::reference_wrapper<active::serialise::Package>;
@@ -21,9 +21,9 @@ namespace connector::interfac::browser::bridge {
/*!
Default constructor
@param objID The ID of the object to send
@param object A reference to the object
@param object The object to send
*/
SendObject(const speckle::utility::String& objID, active::serialise::Package& object) : base{object} {}
SendObject(const speckle::utility::String& objID, std::unique_ptr<active::serialise::Package> object) : m_object{std::move(object)} {}
// MARK: - Public variables
@@ -44,6 +44,10 @@ namespace connector::interfac::browser::bridge {
@return The requested cargo (nullptr on failure)
*/
Cargo::Unique getCargo(const active::serialise::Inventory::Item& item) const override;
private:
///The object to send
std::unique_ptr<active::serialise::Package> m_object;
};
}
@@ -48,9 +48,9 @@ namespace {
account: The account linked to the send
object: The object to be sent
--------------------------------------------------------------------*/
SendViaBrowserArgs::SendViaBrowserArgs(const ModelCard& modelCard, const Account& account, const SendObject& object) :
SendViaBrowserArgs::SendViaBrowserArgs(const ModelCard& modelCard, const Account& account, SendObject&& object) :
modelCardID(modelCard.getID()), projectID(modelCard.getProjectID()), modelID(modelCard.getModelID()), token{account.getToken()},
serverURL{account.getServerURL()}, accountID{account.getID()}, sendObject{object} {
serverURL{account.getServerURL()}, accountID{account.getID()}, sendObject{std::move(object)} {
} //SendViaBrowserArgs::SendViaBrowserArgs
@@ -35,7 +35,7 @@ namespace connector::interfac::browser::bridge {
@param account The account linked to the send
@param object The object to be sent
*/
SendViaBrowserArgs(const connector::record::ModelCard& modelCard, const speckle::record::cred::Account& account, const SendObject& object);
SendViaBrowserArgs(const connector::record::ModelCard& modelCard, const speckle::record::cred::Account& account, SendObject&& object);
// MARK: - Public variables
@@ -63,8 +63,8 @@ void Send::run(const String& modelCardID) const {
//We currently collect all detached object serialised data into a memory-based store - in future may be able to batch send and cache locally
DetachedMemoryStore detachedObjects;
//Collect targeted elements here
Record placeholder; //Using a placeholder as a test for now
SendObject toSend{placeholder.getID(), placeholder};
auto result = std::make_unique<SendViaBrowserArgs>(*modelCard, *account, toSend);
auto placeholder = std::make_unique<Record>(); //Using a placeholder as a test for now
SendObject toSend{placeholder->getID(), std::move(placeholder)};
auto result = std::make_unique<SendViaBrowserArgs>(*modelCard, *account, std::move(toSend));
getBridge()->sendEvent("sendByBrowser", std::move(result));
} //Send::run