Send bridge is updated:

- total children removed
- rootObject replaces batches (sent as an object rather than a string)
This commit is contained in:
Ralph Wessel
2024-10-03 12:05:48 +01:00
parent cc034191b4
commit 1a901b0a6c
10 changed files with 115 additions and 39 deletions
@@ -36,6 +36,7 @@
21AEF9EF2CAB5720000B8681 /* SendObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21AEF9EE2CAB5720000B8681 /* SendObject.cpp */; };
21AEF9F32CAC12D1000B8681 /* SendManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21AEF9F02CAC12D1000B8681 /* SendManager.cpp */; };
21AEF9FA2CAC3897000B8681 /* ConversionResult.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21AEF9F92CAC3897000B8681 /* ConversionResult.cpp */; };
21AEF9FD2CAD3FD8000B8681 /* GetSendSettings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21AEF9FB2CAD3FD8000B8681 /* GetSendSettings.cpp */; };
21B67CA32C769CB400FD64FC /* libActiveLib.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 21F69EF52C64FE91008B6A06 /* libActiveLib.a */; };
21B67CA42C769CB400FD64FC /* libArchicad27.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 21F69ECD2C64C035008B6A06 /* libArchicad27.a */; };
21B67CAC2C77329800FD64FC /* BaseBridge.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21B67CA52C77329800FD64FC /* BaseBridge.cpp */; };
@@ -321,6 +322,8 @@
21AEF9F12CAC12D1000B8681 /* SendManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SendManager.h; sourceTree = "<group>"; };
21AEF9F82CAC3897000B8681 /* ConversionResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConversionResult.h; sourceTree = "<group>"; };
21AEF9F92CAC3897000B8681 /* ConversionResult.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ConversionResult.cpp; sourceTree = "<group>"; };
21AEF9FB2CAD3FD8000B8681 /* GetSendSettings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetSendSettings.cpp; sourceTree = "<group>"; };
21AEF9FC2CAD3FD8000B8681 /* GetSendSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GetSendSettings.h; sourceTree = "<group>"; };
21B67CA52C77329800FD64FC /* BaseBridge.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BaseBridge.cpp; sourceTree = "<group>"; };
21B67CA62C77329800FD64FC /* BaseBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseBridge.h; sourceTree = "<group>"; };
21B67CA72C77329800FD64FC /* GetSourceApplicationName.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetSourceApplicationName.cpp; sourceTree = "<group>"; };
@@ -1071,6 +1074,8 @@
21AEF9E72CAB56E5000B8681 /* Arg */,
21D0BD962C8F13F30077E104 /* GetSendFilters.cpp */,
21D0BD952C8F13F30077E104 /* GetSendFilters.h */,
21AEF9FB2CAD3FD8000B8681 /* GetSendSettings.cpp */,
21AEF9FC2CAD3FD8000B8681 /* GetSendSettings.h */,
21D0BD8D2C8EE4490077E104 /* Send.cpp */,
21D0BD8A2C8EE4490077E104 /* Send.h */,
21D0BD5B2C89BFEA0077E104 /* SendBridge.cpp */,
@@ -1475,6 +1480,7 @@
21B67CEB2C78D27200FD64FC /* DocumentInfo.cpp in Sources */,
21B67CB92C774BFA00FD64FC /* GetConnectorVersion.cpp in Sources */,
21B67CD92C78C83800FD64FC /* TestBridge.cpp in Sources */,
21AEF9FD2CAD3FD8000B8681 /* GetSendSettings.cpp in Sources */,
214B7A372C764BCD00D586C1 /* UpdateConfig.cpp in Sources */,
21AEF9EC2CAB56E5000B8681 /* SendViaBrowserArgs.cpp in Sources */,
21FF70492CA1A7F400AAD99A /* RecordCollection.cpp in Sources */,
@@ -1,6 +1,7 @@
#include "Connector/Interface/Browser/Bridge/Send/Arg/SendObject.h"
#include "Active/Serialise/Package/Wrapper/ContainerWrap.h"
#include "Active/Serialise/Item/Wrapper/ValueWrap.h"
#include <array>
@@ -14,15 +15,13 @@ namespace {
///Serialisation fields
enum FieldIndex {
idID,
totChildID,
batchesID,
rootObjID,
};
///Serialisation field IDs
static std::array fieldID = {
Identity{"id"},
Identity{"totalChildrenCount"},
Identity{"batches"},
Identity{"rootObject"},
};
}
@@ -39,8 +38,7 @@ bool SendObject::fillInventory(active::serialise::Inventory& inventory) const {
inventory.merge(Inventory{
{
{ fieldID[idID], idID, element },
{ fieldID[totChildID], totChildID, element },
{ fieldID[batchesID], batchesID, element },
{ fieldID[rootObjID], rootObjID, element },
},
}.withType(&typeid(SendObject)));
return true;
@@ -61,10 +59,8 @@ Cargo::Unique SendObject::getCargo(const active::serialise::Inventory::Item& ite
switch (item.index) {
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);
case rootObjID:
return std::make_unique<PackageWrap>(base::get());
default:
return nullptr; //Requested an unknown index
}
@@ -11,26 +11,24 @@ namespace connector::interfac::browser::bridge {
/*!
Class defining the primary content of a send
*/
class SendObject final : public active::serialise::Package {
class SendObject final : public active::serialise::Package, public std::reference_wrapper<active::serialise::Package> {
public:
using base = std::reference_wrapper<active::serialise::Package>;
// MARK: - Constructors
/*!
Constructor
@param errMess The error message
@param card The ID of the model card associated with the wrror
*/
SendObject() {}
Default constructor
@param objID The ID of the object to send
@param object A reference to the object
*/
SendObject(const speckle::utility::String& objID, active::serialise::Package& object) : base{object} {}
// MARK: - Public variables
///The root object id which should be used for creating the version
speckle::utility::String id = "1234";
///The total number of children
int32_t totalChildrenCount = 0;
///JSON batches for the root object and child (detached) objects
std::vector<speckle::utility::String> batches;
// MARK: - Serialisation
@@ -46,10 +46,11 @@ namespace {
modelCard: The model card to populate into the send info for the browser
account: The account linked to the send
object: The object to be sent
--------------------------------------------------------------------*/
SendViaBrowserArgs::SendViaBrowserArgs(const ModelCard& modelCard, const Account& account) :
SendViaBrowserArgs::SendViaBrowserArgs(const ModelCard& modelCard, const Account& account, const SendObject& object) :
modelCardID(modelCard.getID()), projectID(modelCard.getProjectID()), modelID(modelCard.getModelID()), token{account.getToken()},
serverURL{account.getServerURL()}, accountID{account.getID()} {
serverURL{account.getServerURL()}, accountID{account.getID()}, sendObject{object} {
} //SendViaBrowserArgs::SendViaBrowserArgs
@@ -33,8 +33,9 @@ namespace connector::interfac::browser::bridge {
Constructor
@param modelCard The model card to populate into the send info for the browser
@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);
SendViaBrowserArgs(const connector::record::ModelCard& modelCard, const speckle::record::cred::Account& account, const SendObject& object);
// MARK: - Public variables
@@ -8,6 +8,7 @@
#include "Connector/Interface/Browser/Bridge/Send/Arg/SendError.h"
#include "Connector/Interface/Browser/Bridge/Send/Arg/SendViaBrowserArgs.h"
#include "Speckle/Database/AccountDatabase.h"
#include "Speckle/Database/Content/BIMRecord.h"
#include "Speckle/Interface/Browser/Bridge/BrowserBridge.h"
#include "Speckle/Record/Credentials/Account.h"
#include "Speckle/Serialise/Detached/Storage/DetachedMemoryStore.h"
@@ -61,7 +62,9 @@ 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;
auto result = std::make_unique<SendViaBrowserArgs>(*modelCard, *account);
//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);
getBridge()->sendEvent("sendByBrowser", std::move(result));
} //Send::run
@@ -1,4 +1,4 @@
#include "Speckle/Database/Content/Record.h"
#include "Speckle/Database/Content/BIMRecord.h"
#include "Speckle/Utility/Guid.h"
@@ -13,7 +13,7 @@ using namespace speckle::utility;
return: True if the package has added items to the inventory
--------------------------------------------------------------------*/
bool Record::fillInventory(active::serialise::Inventory& inventory) const {
bool BIMRecord::fillInventory(active::serialise::Inventory& inventory) const {
using enum Entry::Type;
inventory.merge(Inventory{
{
@@ -21,4 +21,4 @@ bool Record::fillInventory(active::serialise::Inventory& inventory) const {
},
}.withType(&typeid(base)));
return true;
} //Record::fillInventory
} //BIMRecord::fillInventory
@@ -1,5 +1,5 @@
#ifndef SPECKLE_DATABASE_RECORD
#define SPECKLE_DATABASE_RECORD
#ifndef SPECKLE_DATABASE_BIM_RECORD
#define SPECKLE_DATABASE_BIM_RECORD
#include "Active/Database/Content/Record.h"
#include "Speckle/Database/Identity/Link.h"
@@ -10,12 +10,12 @@ namespace speckle::database {
/*!
Base class for a database record
*/
class BIMRecord : public active::database::BIMRecord<BIMRecordID> {
class BIMRecord : public active::database::Record<BIMRecordID>{
public:
// MARK: - Types
using base = active::database::BIMRecord<BIMRecordID>;
using base = active::database::Record<BIMRecordID>;
///Unique pointer
using Unique = std::unique_ptr<BIMRecord>;
///Shared pointer
@@ -28,14 +28,13 @@ namespace speckle::database {
/*!
Default constructor
*/
BIMRecord() : base{active::utility::Guid{true}.operator active::utility::String(),
active::utility::Guid{true}.operator active::utility::String()} {} //TODO: Implement a better default for the ID
BIMRecord() : base{active::utility::Guid{true}, active::utility::Guid{true}} {} //TODO: Implement a better default for the ID
/*!
Constructor
@param ID The record ID
*/
BIMRecord(speckle::utility::String ID, speckle::utility::String::Option globID = std::nullopt) :
base{ID, globID.value_or(active::utility::Guid{true}.operator active::utility::String())} {}
BIMRecord(speckle::utility::Guid ID, speckle::utility::Guid::Option globID = std::nullopt) : //TODO: Implement a better default for the ID
base{ID, globID.value_or(active::utility::Guid{true})} {}
/*!
Destructor
*/
@@ -59,4 +58,4 @@ namespace speckle::database {
}
#endif //SPECKLE_DATABASE_RECORD
#endif //SPECKLE_DATABASE_BIM_RECORD
+54 -1
View File
@@ -6,6 +6,22 @@ using namespace active::serialise;
using namespace speckle::database;
using namespace speckle::utility;
namespace {
///Serialisation fields
enum FieldIndex {
speckleIDID,
speckleTypeID,
};
///Serialisation field IDs
static std::array fieldID = {
Identity{"id"},
Identity{"speckle_type"},
};
}
/*--------------------------------------------------------------------
Fill an inventory with the package items
@@ -17,8 +33,45 @@ bool Record::fillInventory(active::serialise::Inventory& inventory) const {
using enum Entry::Type;
inventory.merge(Inventory{
{
{ Identity{"id"}, active::database::record::FieldIndex::idIndex, element },
{ Identity{fieldID[speckleIDID]}, active::database::record::FieldIndex::idIndex, element },
},
}.withType(&typeid(base)));
inventory.merge(Inventory{
{
{ Identity{fieldID[speckleTypeID]}, speckleTypeID, element },
},
}.withType(&typeid(Record)));
return true;
} //Record::fillInventory
/*--------------------------------------------------------------------
Get the specified cargo
item: The inventory item to retrieve
return: The requested cargo (nullptr on failure)
--------------------------------------------------------------------*/
Cargo::Unique Record::getCargo(const Inventory::Item& item) const {
if (item.ownerType != &typeid(Record))
return base::getCargo(item);
using namespace active::serialise;
switch (item.index) {
case speckleTypeID:
//If the type is undefined, we're in a serialisation process and should populate it with whatever the object says it is
if (!m_type)
m_type = getSpeckleType();
return std::make_unique<StringWrap>(*m_type);
default:
return nullptr; //Requested an unknown index
}
} //Record::getCargo
/*--------------------------------------------------------------------
Set to the default package content
--------------------------------------------------------------------*/
void Record::setDefault() {
//Ensure the content starts with an empty (defined) string for deserialisation so we can discover the incoming type
m_type = String{};
} //Record::setDefault
+20 -1
View File
@@ -42,7 +42,12 @@ namespace speckle::database {
virtual ~Record() {}
// MARK: - Functions (const)
/*!
Get the speckle type identifier
@return The speckle type (relevant objects should override as required, but "Base" is still considered a type on its own)
*/
virtual speckle::utility::String getSpeckleType() const { return "Base"; }
// MARK: - Functions (mutating)
@@ -55,6 +60,20 @@ namespace speckle::database {
@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)
*/
active::serialise::Cargo::Unique getCargo(const active::serialise::Inventory::Item& item) const override;
/*!
Set to the default package content
*/
void setDefault() override;
private:
///Cache for the speckle type during serialisation operations
mutable speckle::utility::String::Option m_type;
};
}