MetastreamGem.h 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/Component/Component.h>
  10. #include <Metastream/MetastreamBus.h>
  11. #include <CryCommon/IConsole.h>
  12. #include <IGem.h>
  13. #include "BaseHttpServer.h"
  14. #include "DataCache.h"
  15. namespace Metastream
  16. {
  17. class MetastreamReflectComponent
  18. : public AZ::Component
  19. {
  20. public:
  21. AZ_COMPONENT(MetastreamReflectComponent, "{7777F7C2-5CD5-4DCE-BA53-086A8E14CEAF}");
  22. static void Reflect(AZ::ReflectContext* context);
  23. void Activate() override {}
  24. void Deactivate() override {}
  25. };
  26. class MetastreamGem
  27. : public CryHooksModule
  28. , public MetastreamRequestBus::Handler
  29. {
  30. public:
  31. AZ_RTTI(MetastreamGem, "{0BACF38B-9774-4771-89E2-B099EA9E3FE7}", CryHooksModule);
  32. AZ_CLASS_ALLOCATOR(MetastreamGem, AZ::SystemAllocator)
  33. MetastreamGem();
  34. ~MetastreamGem() override;
  35. void OnSystemEvent(ESystemEvent event, UINT_PTR wparam, UINT_PTR lparam) override;
  36. virtual void AddStringToCache(const char* table, const char* key, const char* value) override;
  37. virtual void AddBoolToCache(const char* table, const char* key, bool value) override;
  38. virtual void AddVec3ToCache(const char* table, const char* key, const Vec3 & value) override;
  39. virtual void AddDoubleToCache(const char* table, const char* key, double value) override;
  40. virtual void AddUnsigned64ToCache(const char* table, const char* key, AZ::u64 value) override;
  41. virtual void AddSigned64ToCache(const char* table, const char* key, AZ::s64 value) override;
  42. virtual void AddArrayToCache(const char* table, const char* key, const char* arrayName) override;
  43. virtual void AddObjectToCache(const char* table, const char* key, const char* objectName) override;
  44. virtual void AddStringToArray(const char* table, const char* arrayName, const char* value) override;
  45. virtual void AddBoolToArray(const char* table, const char* arrayName, bool value) override;
  46. virtual void AddVec3ToArray(const char* table, const char* arrayName, const Vec3 & value) override;
  47. virtual void AddDoubleToArray(const char* table, const char* arrayName, double value) override;
  48. virtual void AddUnsigned64ToArray(const char* table, const char* arrayName, AZ::u64 value) override;
  49. virtual void AddSigned64ToArray(const char* table, const char* arrayName, AZ::s64 value) override;
  50. virtual void AddArrayToObject(const char* table, const char* destObjectName, const char *key, const char *srcArrayName) override;
  51. virtual void AddObjectToObject(const char* table, const char* destObjectName, const char *key, const char* sourceObjectName) override;
  52. virtual void AddObjectToArray(const char* table, const char* destArrayName, const char* sourceObjectName) override;
  53. virtual void AddStringToObject(const char* table, const char* objectName, const char* key, const char* value) override;
  54. virtual void AddBoolToObject(const char* table, const char* objectName, const char* key, bool value) override;
  55. virtual void AddVec3ToObject(const char* table, const char* objectName, const char* key, const Vec3 & value) override;
  56. virtual void AddDoubleToObject(const char* table, const char* objectName, const char* key, double value) override;
  57. virtual void AddUnsigned64ToObject(const char* table, const char* objectName, const char* key, AZ::u64 value) override;
  58. virtual void AddSigned64ToObject(const char* table, const char* objectName, const char* key, AZ::s64 value) override;
  59. virtual bool StartHTTPServer() override;
  60. virtual void StopHTTPServer() override;
  61. protected:
  62. // Unit test methods to get at m_cache and status
  63. bool IsServerEnabled() const;
  64. std::string GetDatabasesJSON() const;
  65. std::string GetTableKeysJSON(const std::string& tableName) const;
  66. bool ClearCache();
  67. private:
  68. // Console commands
  69. static void StartHTTPServerCmd(IConsoleCmdArgs* args);
  70. static void StopHTTPServerCmd(IConsoleCmdArgs* args);
  71. // CVars
  72. int m_serverEnabled;
  73. ICVar* m_serverOptionsCVar;
  74. std::unique_ptr<BaseHttpServer> m_server;
  75. std::unique_ptr<DataCache> m_cache;
  76. };
  77. } // namespace Metastream