From 8539129e7cb74e0fa3b13b0bbe3a16fe4e501f3c Mon Sep 17 00:00:00 2001 From: Ralph Wessel Date: Thu, 3 Oct 2024 12:33:08 +0100 Subject: [PATCH] SendObject now the owner of the object to be sent --- .../Interface/Browser/Bridge/Send/Arg/SendObject.cpp | 4 +++- .../Interface/Browser/Bridge/Send/Arg/SendObject.h | 10 +++++++--- .../Browser/Bridge/Send/Arg/SendViaBrowserArgs.cpp | 4 ++-- .../Browser/Bridge/Send/Arg/SendViaBrowserArgs.h | 2 +- .../Connector/Interface/Browser/Bridge/Send/Send.cpp | 6 +++--- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendObject.cpp b/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendObject.cpp index 683d025..693b448 100644 --- a/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendObject.cpp +++ b/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendObject.cpp @@ -60,7 +60,9 @@ Cargo::Unique SendObject::getCargo(const active::serialise::Inventory::Item& ite case idID: return std::make_unique(id); case rootObjID: - return std::make_unique(base::get()); + if (m_object) + return std::make_unique(*m_object); + return std::make_unique(); default: return nullptr; //Requested an unknown index } diff --git a/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendObject.h b/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendObject.h index ae31520..7183965 100644 --- a/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendObject.h +++ b/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendObject.h @@ -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 { + class SendObject final : public active::serialise::Package { public: using base = std::reference_wrapper; @@ -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 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 m_object; }; } diff --git a/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendViaBrowserArgs.cpp b/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendViaBrowserArgs.cpp index 0e502e2..3644285 100644 --- a/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendViaBrowserArgs.cpp +++ b/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendViaBrowserArgs.cpp @@ -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 diff --git a/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendViaBrowserArgs.h b/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendViaBrowserArgs.h index 0e82858..c611732 100644 --- a/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendViaBrowserArgs.h +++ b/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendViaBrowserArgs.h @@ -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 diff --git a/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Send.cpp b/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Send.cpp index 4fa0250..63363cb 100644 --- a/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Send.cpp +++ b/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Send.cpp @@ -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(*modelCard, *account, toSend); + auto placeholder = std::make_unique(); //Using a placeholder as a test for now + SendObject toSend{placeholder->getID(), std::move(placeholder)}; + auto result = std::make_unique(*modelCard, *account, std::move(toSend)); getBridge()->sendEvent("sendByBrowser", std::move(result)); } //Send::run