/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates, or * a third party where indicated. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #pragma once #include #include #include #include #include #include #include "CloudGemMetric/MetricsEventParameter.h" namespace CloudGemMetric { class CloudGemMetricSystemComponent : public AZ::Component , public CloudGemFramework::CloudCanvasPlayerIdentityNotificationBus::Handler , public AZ::TickBus::Handler , protected CrySystemEventBus::Handler , protected CloudGemMetricRequestBus::Handler { public: CloudGemMetricSystemComponent(); AZ_COMPONENT(CloudGemMetricSystemComponent, "{3DC9DFEE-2F15-4B8E-804B-97499182D939}"); static void Reflect(AZ::ReflectContext* context); void OnIdentityReceived(); static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided); static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible); static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required); static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent); protected: //////////////////////////////////////////////////////////////////////// // CloudGemMetricRequestBus interface implementation // submit metrics, metrics will be buffered before sending in batch. return false if the metrics is filtered bool SubmitMetrics(const char* eventName, const AZStd::vector& metricsAttributes, const AZStd::vector& metricsParameters); bool SubmitMetricsWithSourceOverride(const char* eventName, const AZStd::vector& metricsAttributes, const AZStd::string& metricSourceOverride, const AZStd::vector& metricsParameters); // send metrics directly to server, return 0 if the metrics is filtered or player id is not available yet, return a positive id if the request is fired int SendMetrics(const char* eventName, const AZStd::vector& metricsAttributes, const AZStd::vector& metricsParameters); int SendMetricsWithSourceOverride(const char* metricsName, const AZStd::vector& metricsAttributes, const AZStd::string& metricSourceOverride, const AZStd::vector& metricsParameters); bool FilterAndSend(const AZStd::string& metricsName, const AZStd::vector& metricsAttributes, const AZStd::string& metricSourceOverride, const AZStd::vector& metricsParameters) override; bool FilterAndSendCallbacks(const AZStd::string& metricsName, const AZStd::vector& metricsAttributes, const AZStd::string& metricSourceOverride, int requestId, OnSendMetricsSuccessCallback successCallback, OnSendMetricsFailureCallback failCallback, const AZStd::vector& metricsParameters) override; // flush all metrics buffered in memory and on file void SendBufferedMetrics(); //////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // TickBus::Handler void OnTick(float deltaTime, AZ::ScriptTimePoint time) override; ////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// // AZ::Component interface implementation void Init() override; void Activate() override; void Deactivate() override; //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// // CrySystemEventBus interface implementation void OnCrySystemInitialized(ISystem& system, const SSystemInitParams& params) override; void OnCrySystemShutdown(ISystem& system) override; //////////////////////////////////////////////////////////////////////// using Attributes = AZStd::vector; using Parameters = AZStd::vector; struct AttributeSubmissionList { AZ_TYPE_INFO(AttributeSubmissionList, "{58217228-f288-11e7-8c3f-9a214cf093ae}") Attributes attributes; static void Reflect(AZ::ReflectContext* reflection) { AZ::SerializeContext* serializeContext = azrtti_cast(reflection); if (serializeContext) { serializeContext->Class() ->Version(1); } AZ::BehaviorContext* behaviorContext = azrtti_cast(reflection); if (behaviorContext) { behaviorContext->Class("CloudGemMetric_AttributesSubmissionList") ->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::Value) ->Property("attributes", BehaviorValueProperty(&AttributeSubmissionList::attributes)) ; } } }; struct EventParameterList { AZ_TYPE_INFO(EventParameterList, "{347FC436-CB4C-475F-8E53-59B9129C16FE}") Parameters parameters; static void Reflect(AZ::ReflectContext* reflection) { AZ::SerializeContext* serializeContext = azrtti_cast(reflection); if (serializeContext) { serializeContext->Class() ->Version(1); } AZ::BehaviorContext* behaviorContext = azrtti_cast(reflection); if (behaviorContext) { behaviorContext->Class("CloudGemMetric_EventParameterList") ->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::Value) ->Property("parameters", BehaviorValueProperty(&EventParameterList::parameters)) ; } } }; static void ReflectMetricsAttribute(AZ::ReflectContext* reflection); static void ReflectMetricsEventParameter(AZ::ReflectContext* reflection); private: MetricManager m_metricManager; }; }