Implemented skeleton of SendObject

This commit is contained in:
Ralph Wessel
2024-10-01 18:21:30 +01:00
parent e148094c81
commit 8ed2abea04
2 changed files with 22 additions and 100 deletions
@@ -1,7 +1,6 @@
#include "Connector/Interface/Browser/Bridge/Base/GetDocumentState.h"
#include "Active/Serialise/CargoHold.h"
#include "Active/Serialise/Package/Wrapper/ContainerWrap.h"
#include "Connector/Connector.h"
#include "Connector/Record/Model/ModelCard.h"
#include "Connector/Database/ModelCardDatabase.h"
@@ -1,17 +1,9 @@
#include "Connector/Interface/Browser/Bridge/Send/Send.h"
#include "Connector/Interface/Browser/Bridge/Send/Arg/SendObject.h"
#include "Active/Serialise/CargoHold.h"
#include "Active/Serialise/Package/Wrapper/PackageWrap.h"
#include "Connector/Connector.h"
#include "Connector/ConnectorResource.h"
#include "Connector/Database/ModelCardDatabase.h"
#include "Speckle/Interface/Browser/Bridge/BrowserBridge.h"
#include "Speckle/Serialise/Detached/Storage/DetachedMemoryStore.h"
#include "Speckle/Utility/Exception.h"
#include "Active/Serialise/Package/Wrapper/ContainerWrap.h"
using namespace active::serialise;
using namespace connector::interfac::browser::bridge;
using namespace speckle::database;
using namespace speckle::serialise;
using namespace speckle::utility;
@@ -19,55 +11,17 @@ namespace {
///Serialisation fields
enum FieldIndex {
errorID,
cardID,
idID,
totChildID,
batchesID,
};
///Serialisation field IDs
static std::array fieldID = {
Identity{"error"},
Identity{"modelCardId"},
Identity{"totalChildrenCount"},
Identity{"batches"},
};
/*!
A send error to return to the JS in the event of an error
*/
class SendError final : public active::serialise::Package {
public:
// MARK: - Constructors
/*!
Constructor
@param errMess The error message
@param card The ID of the model card associated with the wrror
*/
SendError(const String& errMess, const String& card) : message{errMess}, modelCardID{card} {}
// MARK: - Public variables
///The error message
String message;
///The ID of the model card associated with the data
String modelCardID;
// MARK: - Serialisation
/*!
Fill an inventory with the package items
@param inventory The inventory to receive the package items
@return True if the package has added items to the inventory
*/
bool fillInventory(active::serialise::Inventory& inventory) const override;
/*!
Get the specified cargo
@param item The inventory item to retrieve
@return The requested cargo (nullptr on failure)
*/
Cargo::Unique getCargo(const active::serialise::Inventory::Item& item) const override;
};
}
@@ -78,16 +32,17 @@ namespace {
return: True if the package has added items to the inventory
--------------------------------------------------------------------*/
bool SendError::fillInventory(active::serialise::Inventory& inventory) const {
bool SendObject::fillInventory(active::serialise::Inventory& inventory) const {
using enum Entry::Type;
inventory.merge(Inventory{
{
{ fieldID[errorID], errorID, element },
{ fieldID[cardID], cardID, element },
{ fieldID[idID], idID, element },
{ fieldID[totChildID], totChildID, element },
{ fieldID[batchesID], batchesID, element },
},
}.withType(&typeid(SendError)));
}.withType(&typeid(SendObject)));
return true;
} //SendError::fillInventory
} //SendObject::fillInventory
/*--------------------------------------------------------------------
@@ -97,50 +52,18 @@ bool SendError::fillInventory(active::serialise::Inventory& inventory) const {
return: The requested cargo (nullptr on failure)
--------------------------------------------------------------------*/
Cargo::Unique SendError::getCargo(const active::serialise::Inventory::Item& item) const {
if (item.ownerType != &typeid(SendError))
Cargo::Unique SendObject::getCargo(const active::serialise::Inventory::Item& item) const {
if (item.ownerType != &typeid(SendObject))
return nullptr;
using namespace active::serialise;
switch (item.index) {
case errorID:
return std::make_unique<ValueWrap<String>>(message);
case cardID:
return std::make_unique<ValueWrap<String>>(modelCardID);
case idID:
return std::make_unique<StringWrap>(id);
case totChildID:
return std::make_unique<Int32Wrap>(totalChildrenCount);
case batchesID:
return std::make_unique<ContainerWrap<std::vector<speckle::utility::String>>>(batches);
default:
return nullptr; //Requested an unknown index
}
} //SendError::getCargo
/*--------------------------------------------------------------------
Default constructor
--------------------------------------------------------------------*/
Send::Send() : BridgeMethod{"Send", [&](const SendArgs& args) {
run(args);
}} {}
/*--------------------------------------------------------------------
Send a specified model
modelCardID: The ID of the model to send
--------------------------------------------------------------------*/
void Send::run(const String& modelCardID) const {
//Find the specified model card
auto modelCardDatabase = connector()->getModelCardDatabase();
auto modelCard = modelCardDatabase->getCard(modelCardID);
if (!modelCard) {
getBridge()->sendEvent("setModelError",
std::make_unique<SendError>(connector()->getLocalString(errorString, modelCardNotFoundID), modelCardID));
return;
}
//Get the active project
auto project = connector()->getActiveProject().lock();
if (!project) {
getBridge()->sendEvent("setModelError",
std::make_unique<SendError>(connector()->getLocalString(errorString, noProjectOpenID), modelCardID));
return;
}
DetachedMemoryStore detachedObjects;
} //Send::run
} //SendObject::getCargo