Added Platform class

Console logging restricted to debug build
Some tidying
This commit is contained in:
Ralph Wessel
2024-08-30 13:32:41 +01:00
parent 49aae8d44f
commit 2911afa3e7
14 changed files with 187 additions and 174 deletions
@@ -41,7 +41,6 @@
21B67CE72C78D23B00FD64FC /* ConnectorConfig.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21B67CE42C78D23B00FD64FC /* ConnectorConfig.cpp */; };
21B67CEB2C78D27200FD64FC /* DocumentInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21B67CE82C78D27200FD64FC /* DocumentInfo.cpp */; };
21B67CF12C78D38000FD64FC /* GoAway.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21B67CF02C78D38000FD64FC /* GoAway.cpp */; };
21B67CF42C78D4D300FD64FC /* ComplexType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21B67CF22C78D4D300FD64FC /* ComplexType.cpp */; };
21B67CF72C78D4DE00FD64FC /* GetComplexType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21B67CF52C78D4DD00FD64FC /* GetComplexType.cpp */; };
21D1E9AD2BF14AF200957EAA /* BIMData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21D1E9152BF14AEC00957EAA /* BIMData.framework */; };
21D1E9AE2BF14AF200957EAA /* TeamworkPortalServerClient.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21D1E9162BF14AEC00957EAA /* TeamworkPortalServerClient.framework */; };
@@ -303,8 +302,6 @@
21B67CE92C78D27200FD64FC /* DocumentInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DocumentInfo.h; sourceTree = "<group>"; };
21B67CEF2C78D38000FD64FC /* GoAway.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GoAway.h; sourceTree = "<group>"; };
21B67CF02C78D38000FD64FC /* GoAway.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GoAway.cpp; sourceTree = "<group>"; };
21B67CF22C78D4D300FD64FC /* ComplexType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ComplexType.cpp; sourceTree = "<group>"; };
21B67CF32C78D4D300FD64FC /* ComplexType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ComplexType.h; sourceTree = "<group>"; };
21B67CF52C78D4DD00FD64FC /* GetComplexType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetComplexType.cpp; sourceTree = "<group>"; };
21B67CF62C78D4DE00FD64FC /* GetComplexType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GetComplexType.h; sourceTree = "<group>"; };
21D1E9152BF14AEC00957EAA /* BIMData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = BIMData.framework; path = "../Archicad 27/Support/Frameworks/BIMData.framework"; sourceTree = "<group>"; };
@@ -946,8 +943,6 @@
21B67CE22C78D1FB00FD64FC /* Arg */ = {
isa = PBXGroup;
children = (
21B67CF22C78D4D300FD64FC /* ComplexType.cpp */,
21B67CF32C78D4D300FD64FC /* ComplexType.h */,
21B67CE02C78D1FB00FD64FC /* SayHiArg.cpp */,
21B67CE12C78D1FB00FD64FC /* SayHiArg.h */,
);
@@ -1301,7 +1296,6 @@
21B67CE72C78D23B00FD64FC /* ConnectorConfig.cpp in Sources */,
21B67CAD2C77329800FD64FC /* GetSourceApplicationName.cpp in Sources */,
21B67CDC2C78C88000FD64FC /* SayHi.cpp in Sources */,
21B67CF42C78D4D300FD64FC /* ComplexType.cpp in Sources */,
21F69F122C677BC0008B6A06 /* ConnectorMenu.cpp in Sources */,
21F69F8D2C70D7EE008B6A06 /* GetAccounts.cpp in Sources */,
21B67CCC2C77670400FD64FC /* ModelCardDatabase.cpp in Sources */,
@@ -25,7 +25,7 @@ namespace connector::interfac::browser::bridge {
// MARK: - Public variables (NB: Assuming to class invariants or overrides for this data, so making public for simplicity)
///?
///True if the UI renders in dark mode
bool isDarkTheme = true;
// MARK: - Serialisation
@@ -1,89 +0,0 @@
#include "Connector/Interface/Browser/Bridge/Test/Arg/ComplexType.h"
#include "Active/Serialise/Item/Wrapper/ValueWrap.h"
#include <array>
using namespace active::serialise;
using namespace connector::interfac::browser::bridge;
using namespace speckle::utility;
namespace {
///Serialisation fields
enum FieldIndex {
unID,
countID,
isTestID,
};
///Serialisation field IDs
static std::array fieldID = {
Identity{"id"},
Identity{"count"},
Identity{"thisIsABoolean"},
};
}
//Hashing specialisation
template<>
struct std::hash<connector::interfac::browser::bridge::ComplexType> {
auto operator()(const connector::interfac::browser::bridge::ComplexType& obj) const {
return hash<std::string>()(obj.ID) ^ rotl(hash<int32_t>()(obj.count), 1) ^ rotl(hash<bool>()(obj.testBool), 2);
}
};
/*--------------------------------------------------------------------
Default constructor
--------------------------------------------------------------------*/
ComplexType::ComplexType() {
//This is the required test values
count = static_cast<int32_t>(std::hash<ComplexType>()(*this));
ID = String{count} + " - I am a string";
} //ComplexType::ComplexType
/*--------------------------------------------------------------------
Fill an inventory with the package items
inventory: The inventory to receive the package items
return: True if the package has added items to the inventory
--------------------------------------------------------------------*/
bool ComplexType::fillInventory(Inventory& inventory) const {
using enum Entry::Type;
inventory.merge(Inventory{
{
{ fieldID[unID], unID, element, !ID.empty() },
{ fieldID[countID], countID, element, count != 0 },
{ fieldID[isTestID], isTestID, element, testBool },
},
}.withType(&typeid(ComplexType)));
return true;
} //ComplexType::fillInventory
/*--------------------------------------------------------------------
Get the specified cargo
item: The inventory item to retrieve
return: The requested cargo (nullptr on failure)
--------------------------------------------------------------------*/
Cargo::Unique ComplexType::getCargo(const Inventory::Item& item) const {
if (item.ownerType != &typeid(ComplexType))
return nullptr;
using namespace active::serialise;
switch (item.index) {
case unID:
return std::make_unique<ValueWrap<String>>(ID);
case countID:
return std::make_unique<ValueWrap<int32_t>>(count);
case isTestID:
return std::make_unique<ValueWrap<bool>>(testBool);
default:
return nullptr; //Requested an unknown index
}
} //ComplexType::getCargo
@@ -1,51 +0,0 @@
#ifndef CONNECTOR_INTERFACE_BRIDGE_COMPLEX_TYPE
#define CONNECTOR_INTERFACE_BRIDGE_COMPLEX_TYPE
#include "Active/Serialise/Package/Package.h"
#include "Speckle/Utility/String.h"
namespace connector::interfac::browser::bridge {
/*!
Object for testing Javascript communication (with TestBridge binding)
*/
class ComplexType final : public active::serialise::Package {
public:
// MARK: - Types
using base = active::serialise::Package;
// MARK: - Constructors
/*!
Default constructor
*/
ComplexType();
// MARK: - Public variables
///Sample parameters for testing only
speckle::utility::String ID;
int32_t count = 0;
bool testBool = false;
// 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;
};
}
#endif //CONNECTOR_INTERFACE_BRIDGE_COMPLEX_TYPE
@@ -1,20 +1,117 @@
#include "Connector/Interface/Browser/Bridge/Test/GetComplexType.h"
#include "Active/Serialise/CargoHold.h"
#include "Active/Serialise/Item/Wrapper/ValueWrap.h"
#include "Active/Serialise/Package/PackageWrap.h"
#include "Connector/Interface/Browser/Bridge/Test/Arg/ComplexType.h"
using namespace active::serialise;
using namespace connector::interfac::browser::bridge;
using namespace speckle::utility;
namespace {
///Serialisation fields
enum FieldIndex {
unID,
countID,
isTestID,
};
///Serialisation field IDs
static std::array fieldID = {
Identity{"id"},
Identity{"count"},
Identity{"thisIsABoolean"},
};
/*!
Object for testing Javascript communication (with TestBridge binding)
*/
class ComplexType final : public active::serialise::Package {
public:
// MARK: - Types
using base = active::serialise::Package;
// MARK: - Constructors
/*!
Default constructor
*/
ComplexType();
// MARK: - Public variables
///Sample parameters for testing only
speckle::utility::String ID;
int32_t count = 0;
bool testBool = false;
// 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 {
using enum Entry::Type;
inventory.merge(Inventory{
{
{ fieldID[unID], unID, element, !ID.empty() },
{ fieldID[countID], countID, element, count != 0 },
{ fieldID[isTestID], isTestID, element, testBool },
},
}.withType(&typeid(ComplexType)));
return true;
}
/*!
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 {
if (item.ownerType != &typeid(ComplexType))
return nullptr;
using namespace active::serialise;
switch (item.index) {
case unID:
return std::make_unique<ValueWrap<String>>(ID);
case countID:
return std::make_unique<ValueWrap<int32_t>>(count);
case isTestID:
return std::make_unique<ValueWrap<bool>>(testBool);
default:
return nullptr; //Requested an unknown index
}
}
};
///Return type for retrieving the current configuration
using WrappedValue = CargoHold<PackageWrap, ComplexType>;
}
//Hashing specialisation
template<>
struct std::hash<ComplexType> {
auto operator()(const ComplexType& obj) const {
return hash<std::string>()(obj.ID) ^ rotl(hash<int32_t>()(obj.count), 1) ^ rotl(hash<bool>()(obj.testBool), 2);
}
};
/*--------------------------------------------------------------------
Default constructor
--------------------------------------------------------------------*/
ComplexType::ComplexType() {
//This is the required test values
count = static_cast<int32_t>(std::hash<ComplexType>()(*this));
ID = String{count} + " - I am a string";
} //ComplexType::ComplexType
/*--------------------------------------------------------------------
Default constructor
--------------------------------------------------------------------*/
@@ -1,7 +1,6 @@
#ifndef CONNECTOR_INTERFACE_BRIDGE_GET_CONFIG
#define CONNECTOR_INTERFACE_BRIDGE_GET_CONFIG
#include "Connector/Interface/Browser/Bridge/Test/Arg/ComplexType.h"
#include "Speckle/Interface/Browser/Bridge/BridgeMethod.h"
namespace connector::interfac::browser::bridge {
@@ -7,8 +7,9 @@
namespace connector::interfac::browser::bridge {
///Argument parameter for a string
using StringHold = active::serialise::CargoHold<active::serialise::ValueWrap<speckle::utility::String>, speckle::utility::String>;
///Argument for the parameters of a test message
///Argument type for this method
using TriggerEventWrapper = speckle::interfac::browser::bridge::JSArgType<StringHold>;
/*!
@@ -165,9 +165,7 @@ BrowserPalette::BrowserPalette() :
install(std::make_shared<AccountBridge>());
install(std::make_shared<BaseBridge>());
install(std::make_shared<ConfigBridge>());
#ifdef TESTING_MODE
install(std::make_shared<TestBridge>());
#endif
InitBrowserControl();
}
@@ -0,0 +1,37 @@
#include "Speckle/Environment/Platform.h"
#include <iostream>
using namespace speckle::environment;
using namespace speckle::utility;
namespace {
//An object representing the active addon
Platform m_platformInstance;
}
/*--------------------------------------------------------------------
Write a message to the console
message: The message to write
--------------------------------------------------------------------*/
void Platform::writeToConsole(const active::utility::String& message) {
#ifdef WINDOWS
//NB: std::cout doesn't write to the console in Windows by default
OutputDebugString((LPCTSTR)message.operator std::u16string().data());
#else
std::cout << message.data();
#endif
} //Platform::writeToConsole
/*--------------------------------------------------------------------
Get an object representing the parent process/application
return: The active application instance
--------------------------------------------------------------------*/
speckle::environment::Platform* speckle::environment::platform() {
return &m_platformInstance;
} //speckle::environment::platform
+32
View File
@@ -0,0 +1,32 @@
#ifndef SPECKLE_ENVIRONMENT_PLATFORM
#define SPECKLE_ENVIRONMENT_PLATFORM
#include "Speckle/Utility/String.h"
namespace speckle::environment {
/*!
A class representing the host platform/opterating system
*/
class Platform {
public:
// MARK: - Functions (const)
/*!
Write a message to the console
@param message The message to write
*/
void writeToConsole(const active::utility::String& message);
};
/*!
Get an object representing the host platform
@return The host platform
*/
speckle::environment::Platform* platform();
}
#endif //SPECKLE_ENVIRONMENT_PLATFORM
@@ -92,7 +92,7 @@ void BrowserBridge::sendEvent(speckle::utility::String eventName, std::unique_pt
return;
}
//Generate a custom requestID for the data
String requestID{Guid64{} + "_" + eventName};
String requestID{Guid64{} + String{"_"} + eventName};
cacheResult(std::move(data), requestID, false);
//Send a notification using the event name and request ID to signal that the data is available
m_portal->execute(getName() + ".emitResponseReady('" + eventName + "','" + requestID + "')");
@@ -1,6 +1,7 @@
#ifndef SPECKLE_INTERFACE_JS_PORTAL
#define SPECKLE_INTERFACE_JS_PORTAL
#include "Speckle/Environment/Platform.h"
#include "Speckle/Interface/Browser/JSObject.h"
#include "Speckle/Interface/Browser/PlatformBinding.h"
#include "Speckle/Utility/String.h"
@@ -72,14 +73,9 @@ namespace speckle::interfac::browser {
#ifdef ARCHICAD
try {
auto engine = getJSEngine();
speckle::utility::String log{"\nExecuted:\n" + code};
#ifdef macintosh
std::cout << log.data();
#else
OutputDebugString((LPCTSTR)log.operator std::u16string().data());
#ifdef DEBUG
speckle::environment::platform()->writeToConsole("\nExecuted:\n" + code + "\n");
#endif
auto result = engine ? engine->ExecuteJS(code) : false;
return result;
} catch(...) {
@@ -11,6 +11,7 @@
#include "Active/Serialise/Package/Package.h"
#include "Active/Serialise/Package/PackageWrap.h"
#include "Active/Serialise/XML/Item/XMLDateTime.h"
#include "Speckle/Environment/Platform.h"
#include <JSON/JDOMWriter.hpp>
#include <JSON/Value.hpp>
@@ -466,14 +467,9 @@ namespace {
--------------------------------------------------------------------*/
void JSBaseTransport::send(Cargo&& cargo, const Identity& identity, GS::Ref<JS::Base>& destination) const {
doJSBaseExport(cargo, JSBaseIdentity(identity).atStage(root), destination);
speckle::utility::String log{"\nSent:\n" + convertToJSON(destination)};
#ifdef macintosh
std::cout << log.data();
#else
OutputDebugString((LPCTSTR)log.operator std::u16string().data());
#ifdef DEBUG
speckle::environment::platform()->writeToConsole("\nSent:\n" + convertToJSON(destination) + "\n");
#endif
} //JSBaseTransport::send
@@ -487,14 +483,9 @@ void JSBaseTransport::send(Cargo&& cargo, const Identity& identity, GS::Ref<JS::
void JSBaseTransport::receive(Cargo&& cargo, const Identity& identity, GS::Ref<JS::Base> source) const {
if (!source)
throw std::system_error(makeJSBaseError(badSource));
speckle::utility::String log{"\nReceived:\n" + convertToJSON(source)};
#ifdef macintosh
std::cout << log.data();
#else
OutputDebugString((LPCTSTR)log.operator std::u16string().data());
#ifdef DEBUG
speckle::environment::platform()->writeToConsole("\nReceived:\n" + convertToJSON(source) + "\n");
#endif
doJSBaseImport(cargo, JSBaseIdentity(identity).atStage(root), *source);
} //JSBaseTransport::receive
@@ -12,6 +12,8 @@
210CC88F2C81A98500610F58 /* Guid64.h in Headers */ = {isa = PBXBuildFile; fileRef = 210CC88D2C81A98500610F58 /* Guid64.h */; };
210CC8902C81A98500610F58 /* Guid64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 210CC88E2C81A98500610F58 /* Guid64.cpp */; };
210CC8922C81AEBB00610F58 /* Guid32Tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 210CC8912C81AEBB00610F58 /* Guid32Tests.cpp */; };
210CC89F2C81E34400610F58 /* Platform.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 210CC89D2C81E34400610F58 /* Platform.cpp */; };
210CC8A02C81E34400610F58 /* Platform.h in Headers */ = {isa = PBXBuildFile; fileRef = 210CC89E2C81E34400610F58 /* Platform.h */; };
212A88132AE48821001EAFE7 /* libArchicad27.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 21379E082AE47A6400A1584C /* libArchicad27.a */; platformFilters = (macos, ); };
2193517B2C624FC100E5A69C /* MenuSubscriber.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 219351782C624FC100E5A69C /* MenuSubscriber.cpp */; };
2193518C2C62655700E5A69C /* MenuEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 219351892C62655700E5A69C /* MenuEvent.h */; };
@@ -78,6 +80,8 @@
210CC88D2C81A98500610F58 /* Guid64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Guid64.h; sourceTree = "<group>"; };
210CC88E2C81A98500610F58 /* Guid64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Guid64.cpp; sourceTree = "<group>"; };
210CC8912C81AEBB00610F58 /* Guid32Tests.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; path = Guid32Tests.cpp; sourceTree = "<group>"; };
210CC89D2C81E34400610F58 /* Platform.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Platform.cpp; sourceTree = "<group>"; };
210CC89E2C81E34400610F58 /* Platform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Platform.h; sourceTree = "<group>"; };
212A87EF2AE4868C001EAFE7 /* SpeckleLib-test.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SpeckleLib-test.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
21329F472BFA611C00B5C7AF /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
21329F632BFD452C00B5C7AF /* Environment.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = Environment.md; sourceTree = "<group>"; };
@@ -384,6 +388,8 @@
2167E2782C4911E2000827D3 /* CMakeLists.txt */,
21F93AEA2B2F406D009A2C5B /* Addon.cpp */,
21F93AE92B2F406D009A2C5B /* Addon.h */,
210CC89D2C81E34400610F58 /* Platform.cpp */,
210CC89E2C81E34400610F58 /* Platform.h */,
21329F632BFD452C00B5C7AF /* Environment.md */,
);
path = Environment;
@@ -397,6 +403,7 @@
buildActionMask = 2147483647;
files = (
210CC86F2C7E879700610F58 /* ArgumentBase.h in Headers */,
210CC8A02C81E34400610F58 /* Platform.h in Headers */,
21B67D0D2C7E0E8D00FD64FC /* ErrorReport.h in Headers */,
210CC88F2C81A98500610F58 /* Guid64.h in Headers */,
21B67D002C7CE15100FD64FC /* Exception.h in Headers */,
@@ -542,6 +549,7 @@
21F69FA42C729400008B6A06 /* Record.cpp in Sources */,
21F69F512C6CCC25008B6A06 /* BrowserBridge.cpp in Sources */,
21F69F3B2C6B880C008B6A06 /* JSBaseTransport.cpp in Sources */,
210CC89F2C81E34400610F58 /* Platform.cpp in Sources */,
21F69F962C71087A008B6A06 /* Account.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;