1f9b284de2
Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> # Conflicts: # Code/Editor/Plugins/ComponentEntityEditorPlugin/ComponentEntityEditorPlugin_precompiled.h # Code/Editor/Plugins/EditorCommon/EditorCommon_precompiled.h # Code/Editor/Plugins/EditorCommon/stdafx.cpp # Code/Editor/Plugins/FFMPEGPlugin/FFMPEGPlugin_precompiled.h # Code/Editor/Plugins/PerforcePlugin/PerforcePlugin_precompiled.h # Code/Editor/Plugins/ProjectSettingsTool/ProjectSettingsTool_precompiled.h # Code/Framework/AzToolsFramework/AzToolsFramework/AzToolsFramework_precompiled.h # Code/Tools/AssetProcessor/native/precompiled.h # Code/Tools/Standalone/StandaloneTools_precompiled.h # Gems/AssetMemoryAnalyzer/Code/Source/AssetMemoryAnalyzer_precompiled.h # Gems/Atom/Asset/ImageProcessingAtom/Code/Source/ImageProcessing_precompiled.h # Gems/Atom/RHI/DX12/Code/Source/RHI/Atom_RHI_DX12_precompiled.h # Gems/Atom/RHI/Metal/Code/Include/Platform/Mac/Atom_RHI_Metal_precompiled_Platform.h # Gems/Atom/RHI/Metal/Code/Include/Platform/iOS/Atom_RHI_Metal_precompiled_Platform.h # Gems/Atom/RHI/Metal/Code/Source/Atom_RHI_Metal_precompiled.h # Gems/Atom/RHI/Metal/Code/atom_rhi_metal_common_files.cmake # Gems/Atom/RHI/Null/Code/Source/Atom_RHI_Null_precompiled.h # Gems/Atom/RHI/Null/Code/atom_rhi_null_common_files.cmake # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Android/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Linux/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Mac/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Windows/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Source/Atom_RHI_Vulkan_precompiled.h # Gems/Atom/RHI/Vulkan/Code/Source/RHI/SwapChain.cpp # Gems/Atom/RHI/Vulkan/Code/atom_rhi_vulkan_common_files.cmake # Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomFont_precompiled.h # Gems/Blast/Code/Source/StdAfx.cpp # Gems/Camera/Code/Source/Camera_precompiled.h # Gems/EMotionFX/Code/Source/EMotionFX_precompiled.h # Gems/FastNoise/Code/Source/FastNoise_precompiled.h # Gems/Gestures/Code/Source/Gestures_precompiled.h # Gems/GradientSignal/Code/Source/GradientSignal_precompiled.h # Gems/GraphCanvas/Code/precompiled.h # Gems/ImGui/Code/Source/ImGui_precompiled.h # Gems/InAppPurchases/Code/Source/InAppPurchases_precompiled.h # Gems/LmbrCentral/Code/Source/LmbrCentral_precompiled.h # Gems/LmbrCentral/Code/Tests/ShapeGeometryUtilTest.cpp # Gems/LyShine/Code/Editor/UiCanvasEditor_precompiled.h # Gems/LyShine/Code/Source/Animation/LyShine_precompiled.h # Gems/LyShine/Code/Source/LyShine_precompiled.h # Gems/LyShineExamples/Code/Source/LyShineExamples_precompiled.h # Gems/Maestro/Code/Source/Cinematics/Maestro_precompiled.h # Gems/Maestro/Code/Source/Maestro_precompiled.h # Gems/MessagePopup/Code/Source/MessagePopup_precompiled.h # Gems/Metastream/Code/Source/Metastream_precompiled.h # Gems/Microphone/Code/Source/Microphone_precompiled.h # Gems/Multiplayer/Code/Source/Multiplayer_precompiled.h # Gems/PhysX/Code/NumericalMethods/Source/NumericalMethods_precompiled.h # Gems/PhysX/Code/Source/PhysXUnsupported_precompiled.h # Gems/PhysX/Code/Source/PhysX_precompiled.h # Gems/PhysX/Code/physx_unsupported_files.cmake # Gems/PhysXDebug/Code/Source/PhysXDebugUnsupported_precompiled.h # Gems/PhysXDebug/Code/Source/PhysXDebug_precompiled.h # Gems/ScriptCanvas/Code/Editor/precompiled.h # Gems/ScriptCanvas/Code/Source/precompiled.h # Gems/ScriptCanvasDeveloper/Code/Source/precompiled.h # Gems/ScriptCanvasPhysics/Code/Source/ScriptCanvasPhysics_precompiled.h # Gems/ScriptEvents/Code/Source/precompiled.h # Gems/ScriptEvents/Code/Tests/Editor/EditorTests.cpp # Gems/ScriptedEntityTweener/Code/Source/ScriptedEntityTweener_precompiled.h # Gems/SliceFavorites/Code/Source/SliceFavorites_precompiled.h # Gems/StartingPointCamera/Code/Source/StartingPointCamera_precompiled.h # Gems/StartingPointInput/Code/Source/StartingPointInput_precompiled.h # Gems/StartingPointMovement/Code/Source/StartingPointMovement_precompiled.h # Gems/SurfaceData/Code/Source/SurfaceData_precompiled.h # Gems/TextureAtlas/Code/Source/TextureAtlas_precompiled.h # Gems/TickBusOrderViewer/Code/Source/TickBusOrderViewer_precompiled.h # Gems/Twitch/Code/Source/Twitch_precompiled.h # Gems/VirtualGamepad/Code/Source/VirtualGamepad_precompiled.h # Gems/WhiteBox/Code/Source/WhiteBoxUnsupported_precompiled.h # Gems/WhiteBox/Code/Source/WhiteBox_precompiled.h
408 lines
13 KiB
C++
408 lines
13 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
|
|
#include <sstream>
|
|
#include <string.h>
|
|
|
|
#include <AzCore/RTTI/BehaviorContext.h>
|
|
#include <AzCore/Serialization/SerializeContext.h>
|
|
#include <Metastream_Traits_Platform.h>
|
|
|
|
#include "MetastreamGem.h"
|
|
|
|
#if AZ_TRAIT_METASTREAM_USE_CIVET
|
|
#include "CivetHttpServer.h"
|
|
#endif // AZ_TRAIT_METASTREAM_USE_CIVET
|
|
|
|
namespace Metastream
|
|
{
|
|
|
|
void Metastream::MetastreamReflectComponent::Reflect(AZ::ReflectContext* context)
|
|
{
|
|
if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
|
|
{
|
|
serializeContext->Class<MetastreamReflectComponent, AZ::Component>()
|
|
->Version(0)
|
|
;
|
|
}
|
|
|
|
AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context);
|
|
if (behaviorContext)
|
|
{
|
|
behaviorContext->EBus<MetastreamRequestBus>("MetastreamRequestBus")
|
|
->Event("StartHTTPServer", &MetastreamRequestBus::Events::StartHTTPServer)
|
|
->Event("StopHTTPServer", &MetastreamRequestBus::Events::StopHTTPServer)
|
|
|
|
->Event("AddStringToCache", &MetastreamRequestBus::Events::AddStringToCache)
|
|
->Event("AddBoolToCache", &MetastreamRequestBus::Events::AddBoolToCache)
|
|
->Event("AddDoubleToCache", &MetastreamRequestBus::Events::AddDoubleToCache)
|
|
->Event("AddUnsigned64ToCache", &MetastreamRequestBus::Events::AddUnsigned64ToCache)
|
|
->Event("AddSigned64ToCache", &MetastreamRequestBus::Events::AddSigned64ToCache)
|
|
->Event("AddEntityIdToCache", &MetastreamRequestBus::Events::AddEntityIdToCache)
|
|
|
|
->Event("AddArrayToCache", &MetastreamRequestBus::Events::AddArrayToCache)
|
|
->Event("AddObjectToCache", &MetastreamRequestBus::Events::AddObjectToCache)
|
|
|
|
->Event("AddArrayToObject", &MetastreamRequestBus::Events::AddArrayToObject)
|
|
->Event("AddObjectToObject", &MetastreamRequestBus::Events::AddObjectToObject)
|
|
->Event("AddObjectToArray", &MetastreamRequestBus::Events::AddObjectToArray)
|
|
|
|
->Event("AddStringToArray", &MetastreamRequestBus::Events::AddStringToArray)
|
|
->Event("AddBoolToArray", &MetastreamRequestBus::Events::AddBoolToArray)
|
|
->Event("AddDoubleToArray", &MetastreamRequestBus::Events::AddDoubleToArray)
|
|
->Event("AddUnsigned64ToArray", &MetastreamRequestBus::Events::AddUnsigned64ToArray)
|
|
->Event("AddSigned64ToArray", &MetastreamRequestBus::Events::AddSigned64ToArray)
|
|
->Event("AddEntityIdToArray", &MetastreamRequestBus::Events::AddEntityIdToArray)
|
|
|
|
->Event("AddStringToObject", &MetastreamRequestBus::Events::AddStringToObject)
|
|
->Event("AddBoolToObject", &MetastreamRequestBus::Events::AddBoolToObject)
|
|
->Event("AddDoubleToObject", &MetastreamRequestBus::Events::AddDoubleToObject)
|
|
->Event("AddUnsigned64ToObject", &MetastreamRequestBus::Events::AddUnsigned64ToObject)
|
|
->Event("AddSigned64ToObject", &MetastreamRequestBus::Events::AddSigned64ToObject)
|
|
->Event("AddEntityIdToObject", &MetastreamRequestBus::Events::AddEntityIdToObject)
|
|
;
|
|
}
|
|
}
|
|
|
|
|
|
MetastreamGem::MetastreamGem()
|
|
: m_serverEnabled(0)
|
|
, m_serverOptionsCVar(nullptr)
|
|
{
|
|
MetastreamAllocatorScope::ActivateAllocators();
|
|
m_descriptors.push_back(MetastreamReflectComponent::CreateDescriptor());
|
|
|
|
// Initialise the cache
|
|
m_cache = std::unique_ptr<DataCache>(new DataCache());
|
|
|
|
MetastreamRequestBus::Handler::BusConnect();
|
|
}
|
|
MetastreamGem::~MetastreamGem()
|
|
{
|
|
MetastreamRequestBus::Handler::BusDisconnect();
|
|
MetastreamAllocatorScope::DeactivateAllocators();
|
|
}
|
|
|
|
void MetastreamGem::OnSystemEvent(ESystemEvent event, [[maybe_unused]] UINT_PTR wparam, [[maybe_unused]] UINT_PTR lparam)
|
|
{
|
|
using namespace Metastream;
|
|
|
|
switch (event)
|
|
{
|
|
case ESYSTEM_EVENT_GAME_POST_INIT:
|
|
// All other Gems will exist at this point, for a full list of civet options, see https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md
|
|
//
|
|
// Note: 1) For security reasons, the option "enable_directory_listing" is forced to "no".
|
|
// 2) The following options are ignored for security reasons: enable_directory_listing, cgi_interpreter, run_as_user, put_delete_auth_file
|
|
// 3) Options are a set of key=value separated by the semi colon character. If a option needs to use the ';' or '='
|
|
// then use $semi or $equ.
|
|
//
|
|
m_serverOptionsCVar = REGISTER_STRING("metastream_serveroptions", "document_root=Gems/Metastream/Files;listening_ports=8082", VF_NULL, "Metastream HTTP Server options");
|
|
|
|
REGISTER_CVAR2("metastream_enabled", &m_serverEnabled, 0, VF_READONLY, "State of the Metastream HTTP server (READONLY)");
|
|
|
|
REGISTER_COMMAND("metastream_start", StartHTTPServerCmd, 0, "Starts the Metastream HTTP server");
|
|
REGISTER_COMMAND("metastream_stop", StopHTTPServerCmd, 0, "Stops the Metastream HTTP server");
|
|
|
|
break;
|
|
|
|
case ESYSTEM_EVENT_FULL_SHUTDOWN:
|
|
case ESYSTEM_EVENT_FAST_SHUTDOWN:
|
|
// Put your shutdown code here
|
|
// Other Gems may have been shutdown already, but none will have destructed
|
|
if (m_server.get())
|
|
{
|
|
m_server->Stop();
|
|
m_serverEnabled = 0;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
void MetastreamGem::AddStringToCache(const char* table, const char* key, const char* value)
|
|
{
|
|
if (m_cache.get())
|
|
{
|
|
m_cache->AddToCache(table, key, value);
|
|
}
|
|
}
|
|
|
|
void MetastreamGem::AddBoolToCache(const char* table, const char* key, bool value)
|
|
{
|
|
if (m_cache.get())
|
|
{
|
|
m_cache->AddToCache(table, key, value);
|
|
}
|
|
}
|
|
|
|
void MetastreamGem::AddVec3ToCache(const char* table, const char* key, const Vec3 & value)
|
|
{
|
|
if (m_cache.get())
|
|
{
|
|
m_cache->AddToCache(table, key, AZ::Vector3(value.x, value.y, value.z));
|
|
}
|
|
}
|
|
|
|
void MetastreamGem::AddDoubleToCache(const char* table, const char* key, double value)
|
|
{
|
|
if (m_cache.get())
|
|
{
|
|
m_cache->AddToCache(table, key, value);
|
|
}
|
|
}
|
|
|
|
void MetastreamGem::AddUnsigned64ToCache(const char* table, const char* key, AZ::u64 value)
|
|
{
|
|
if (m_cache.get())
|
|
{
|
|
m_cache->AddToCache(table, key, value);
|
|
}
|
|
}
|
|
|
|
void MetastreamGem::AddSigned64ToCache(const char* table, const char* key, AZ::s64 value)
|
|
{
|
|
if (m_cache.get())
|
|
{
|
|
m_cache->AddToCache(table, key, value);
|
|
}
|
|
}
|
|
|
|
void MetastreamGem::AddArrayToCache(const char* table, const char* key, const char* arrayName)
|
|
{
|
|
if (m_cache.get())
|
|
{
|
|
m_cache->AddArrayToCache(table, key, arrayName);
|
|
}
|
|
}
|
|
|
|
void MetastreamGem::AddObjectToCache(const char* table, const char* key, const char* objectName)
|
|
{
|
|
if (m_cache.get())
|
|
{
|
|
m_cache->AddObjectToCache(table, key, objectName);
|
|
}
|
|
}
|
|
|
|
void MetastreamGem::AddStringToArray(const char* table, const char* arrayName, const char* value)
|
|
{
|
|
if (m_cache.get())
|
|
{
|
|
m_cache->AddToArray(table, arrayName, value);
|
|
}
|
|
}
|
|
|
|
void MetastreamGem::AddBoolToArray(const char* table, const char* arrayName, bool value)
|
|
{
|
|
if (m_cache.get())
|
|
{
|
|
m_cache->AddToArray(table, arrayName, value);
|
|
}
|
|
}
|
|
|
|
void MetastreamGem::AddVec3ToArray(const char* table, const char* arrayName, const Vec3 & value)
|
|
{
|
|
if (m_cache.get())
|
|
{
|
|
m_cache->AddToArray(table, arrayName, AZStd::string::format("[%f,%f,%f]", value.x, value.y, value.z).c_str());
|
|
}
|
|
}
|
|
|
|
void MetastreamGem::AddDoubleToArray(const char* table, const char* arrayName, double value)
|
|
{
|
|
if (m_cache.get())
|
|
{
|
|
m_cache->AddToArray(table, arrayName, value);
|
|
}
|
|
}
|
|
|
|
void MetastreamGem::AddUnsigned64ToArray(const char* table, const char* arrayName, AZ::u64 value)
|
|
{
|
|
if (m_cache.get())
|
|
{
|
|
m_cache->AddToArray(table, arrayName, value);
|
|
}
|
|
}
|
|
|
|
void MetastreamGem::AddSigned64ToArray(const char* table, const char* arrayName, AZ::s64 value)
|
|
{
|
|
if (m_cache.get())
|
|
{
|
|
m_cache->AddToArray(table, arrayName, value);
|
|
}
|
|
}
|
|
|
|
void MetastreamGem::AddArrayToObject(const char* table, const char* destObjectName, const char *key, const char *srcArrayName)
|
|
{
|
|
if (m_cache.get())
|
|
{
|
|
m_cache->AddArrayToObject(table, destObjectName, key, srcArrayName);
|
|
}
|
|
}
|
|
|
|
void MetastreamGem::AddObjectToObject(const char* table, const char* destObjectName, const char *key, const char* sourceObjectName)
|
|
{
|
|
if (m_cache.get())
|
|
{
|
|
m_cache->AddObjectToObject(table, destObjectName, key, sourceObjectName);
|
|
}
|
|
}
|
|
|
|
void MetastreamGem::AddObjectToArray(const char* table, const char* destArrayName, const char* sourceObjectName)
|
|
{
|
|
if (m_cache.get())
|
|
{
|
|
m_cache->AddObjectToArray(table, destArrayName, sourceObjectName);
|
|
}
|
|
}
|
|
|
|
|
|
void MetastreamGem::AddStringToObject(const char *table, const char* objectName, const char* key, const char* value)
|
|
{
|
|
if (m_cache.get())
|
|
{
|
|
m_cache->AddToObject(table, objectName, key, value);
|
|
}
|
|
}
|
|
|
|
void MetastreamGem::AddBoolToObject(const char* table, const char* objectName, const char* key, bool value)
|
|
{
|
|
if (m_cache.get())
|
|
{
|
|
m_cache->AddToObject(table, objectName, key, value);
|
|
}
|
|
}
|
|
|
|
void MetastreamGem::AddVec3ToObject(const char *table, const char* objectName, const char* key, const Vec3 & value)
|
|
{
|
|
if (m_cache.get())
|
|
{
|
|
m_cache->AddToObject(table, objectName, key, AZ::Vector3(value.x, value.y, value.z));
|
|
}
|
|
}
|
|
|
|
void MetastreamGem::AddDoubleToObject(const char *table, const char* objectName, const char* key, double value)
|
|
{
|
|
if (m_cache.get())
|
|
{
|
|
m_cache->AddToObject(table, objectName, key, value);
|
|
}
|
|
}
|
|
|
|
void MetastreamGem::AddUnsigned64ToObject(const char *table, const char* objectName, const char* key, AZ::u64 value)
|
|
{
|
|
if (m_cache.get())
|
|
{
|
|
m_cache->AddToObject(table, objectName, key, value);
|
|
}
|
|
}
|
|
|
|
void MetastreamGem::AddSigned64ToObject(const char *table, const char* objectName, const char* key, AZ::s64 value)
|
|
{
|
|
if (m_cache.get())
|
|
{
|
|
m_cache->AddToObject(table, objectName, key, value);
|
|
}
|
|
}
|
|
|
|
|
|
bool MetastreamGem::StartHTTPServer()
|
|
{
|
|
if (!m_serverOptionsCVar)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
#if AZ_TRAIT_METASTREAM_USE_CIVET
|
|
// Start server if it is not started
|
|
if (!m_server.get())
|
|
{
|
|
// Initialise and start the HTTP server
|
|
m_server = std::unique_ptr<BaseHttpServer>(new CivetHttpServer(m_cache.get()));
|
|
string serverOptions = m_serverOptionsCVar->GetString();
|
|
CryLogAlways("Initializing Metastream: Options=\"%s\"", serverOptions.c_str());
|
|
|
|
bool result = m_server->Start(serverOptions.c_str());
|
|
if (result)
|
|
{
|
|
m_serverEnabled = 1;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
else
|
|
{
|
|
// Server already started
|
|
return true;
|
|
}
|
|
#endif // AZ_TRAIT_METASTREAM_USE_CIVET
|
|
|
|
// Metastream only supported on PC
|
|
return false;
|
|
}
|
|
|
|
void Metastream::MetastreamGem::StopHTTPServer()
|
|
{
|
|
// Stop server if it is started
|
|
if (m_server.get())
|
|
{
|
|
m_server->Stop();
|
|
m_server.reset();
|
|
|
|
ClearCache();
|
|
m_serverEnabled = 0;
|
|
}
|
|
}
|
|
|
|
void Metastream::MetastreamGem::StartHTTPServerCmd(IConsoleCmdArgs* /*args*/)
|
|
{
|
|
EBUS_EVENT(Metastream::MetastreamRequestBus, StartHTTPServer);
|
|
}
|
|
|
|
void Metastream::MetastreamGem::StopHTTPServerCmd(IConsoleCmdArgs* /*args*/)
|
|
{
|
|
EBUS_EVENT(Metastream::MetastreamRequestBus, StopHTTPServer);
|
|
}
|
|
|
|
// Unit test methods to get at m_cache and status
|
|
bool Metastream::MetastreamGem::IsServerEnabled() const
|
|
{
|
|
return (m_serverEnabled == 1);
|
|
}
|
|
|
|
std::string Metastream::MetastreamGem::GetDatabasesJSON() const
|
|
{
|
|
if (m_cache)
|
|
{
|
|
return m_cache->GetDatabasesJSON();
|
|
}
|
|
return "";
|
|
}
|
|
|
|
std::string Metastream::MetastreamGem::GetTableKeysJSON(const std::string& tableName) const
|
|
{
|
|
if (m_cache)
|
|
{
|
|
return m_cache->GetTableKeysJSON(tableName);
|
|
}
|
|
return "";
|
|
}
|
|
|
|
bool Metastream::MetastreamGem::ClearCache()
|
|
{
|
|
if (m_cache)
|
|
{
|
|
m_cache->ClearCache();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
AZ_DECLARE_MODULE_CLASS(Gem_Metastream, Metastream::MetastreamGem)
|