/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * 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. * */ ///////////////////////////////////////////////////////// ///////////////////////////////////////////////////////// // THIS CODE IS AUTOGENERATED, DO NOT MODIFY ///////////////////////////////////////////////////////// ///////////////////////////////////////////////////////// #pragma once #include #include #include #include #include #include #include #include #include #include #include #if defined (PLATFORM_SUPPORTS_AWS_NATIVE_SDK) // The AWS Native SDK AWSAllocator triggers a warning due to accessing members of std::allocator directly. // AWSAllocator.h(70): warning C4996: 'std::allocator::pointer': warning STL4010: Various members of std::allocator are deprecated in C++17. // Use std::allocator_traits instead of accessing these members directly. // You can define _SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING or _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS to acknowledge that you have received this warning. AZ_PUSH_DISABLE_WARNING(4251 4996, "-Wunknown-warning-option") #include #include AZ_POP_DISABLE_WARNING #endif // (PLATFORM_SUPPORTS_AWS_NATIVE_SDK) #include {% if json_object.HasStdAfx %} #include "StdAfx.h" {% elif json_object.DisabledPCH == False %} #include "{{ json_object.namespace }}_precompiled.h" {% endif %} namespace {{ json_object.namespace }} { namespace ServiceAPI { {% for key, value in json_object.UUIDs.items() %} extern const char* LmbrAWS_CodeGen_{{ key }}_UUID; {% endfor %} // redefs {% for item in json_object.redefinitions %} using {{ item.name }} = {{ item.primitiveType }}; {% endfor %} bool WriteJson(CloudGemFramework::JsonWriter& writer, const int& item); bool WriteJson(CloudGemFramework::JsonWriter& writer, const AZStd::string& item); bool WriteJson(CloudGemFramework::JsonWriter& writer, const double& item); {% for item in json_object.otherClasses %} {% if item.isArray %} using {{ item.name }} = AZStd::vector<{{ item.elements }}>; bool WriteJson(CloudGemFramework::JsonWriter& writer, const {{ item.name }}& list); {% else %} struct {{ item.name }} { AZ_TYPE_INFO({{ item.name }}, LmbrAWS_CodeGen_{{ item.name }}_UUID) AZ_CLASS_ALLOCATOR({{ item.name }}, AZ::SystemAllocator, 0) {% for prop in item.props %} {{ prop.type }} {{prop.name}}{{prop.init}}; {% endfor %} bool OnJsonKey(const char* key, CloudGemFramework::JsonReader& reader); static void Reflect(AZ::ReflectContext* reflection); }; bool WriteJson(CloudGemFramework::JsonWriter& writer, const {{ item.name }}& item); {% endif %} {% endfor %} // Service RequestJobs CLOUD_GEM_SERVICE({{ json_object.namespace }}); {% for path in json_object.functions %} class {{ path.functionName}}Request : public CloudGemFramework::ServiceRequest { public: SERVICE_REQUEST({{ json_object.namespace }}, HttpMethod::HTTP_{{ path.http_method }}, "{{ path.path }}"); struct Parameters { {% for param in path.params %} {{ param }}; {% endfor %} bool BuildRequest(CloudGemFramework::RequestBuilder& request); bool WriteJson(CloudGemFramework::JsonWriter& writer) const; }; {% if path.responseType %} {{ path.responseType }} result; {% endif %} Parameters parameters; }; using {{ path.functionName }}RequestJob = CloudGemFramework::ServiceRequestJob<{{ path.functionName }}Request>; {% endfor %} // Notification bus for this component class {{ json_object.namespace }}Notifications : public AZ::ComponentBus { public: {% for function in json_object.functions %} /** * Sent when the request is a success * * Params: * jsonOutput: The output receieved from the lambda call * request: The AWS Lambda request object */ {% if function.responseType %} virtual void On{{ function.functionName }}RequestSuccess(const {{ function.responseType }} response); {% else %} virtual void On{{ function.functionName }}RequestSuccess(); {% endif %} /** * Sent when the request fails * * Params: * error: The output receieved from the lambda call, * could be function error or an issue with the request * request: The AWS Lambda request object */ virtual void On{{ function.functionName }}RequestError(const CloudGemFramework::Error error); {% endfor %} }; using {{ json_object.namespace }}NotificationBus = AZ::EBus<{{ json_object.namespace }}Notifications>; class Behavior{{ json_object.namespace }}NotificationBusHandler : public {{ json_object.namespace }}NotificationBus::Handler, public AZ::BehaviorEBusHandler { public: AZ_EBUS_BEHAVIOR_BINDER(Behavior{{ json_object.namespace }}NotificationBusHandler, LmbrAWS_CodeGen_NotificationBus1_UUID, AZ::SystemAllocator {% for function in json_object.functions %} , On{{ function.functionName }}RequestSuccess , On{{ function.functionName }}RequestError {% endfor %} ); {% for function in json_object.functions %} {% if function.responseType %} void On{{ function.functionName }}RequestSuccess(const {{ function.responseType }} response) override; {% else %} void On{{ function.functionName }}RequestSuccess() override; {% endif %} void On{{ function.functionName }}RequestError(const CloudGemFramework::Error error) override; {% endfor %} }; class {{ json_object.namespace }}ResponseHandler; // Request bus for this component class {{ json_object.namespace }}Requests : public AZ::ComponentBus { public: virtual ~{{ json_object.namespace }}Requests() {} {% for function in json_object.functions %} {% if function.typedParams %} virtual void {{ function.functionName }}({{ function.typedParams}}, {{ json_object.namespace}}ResponseHandler* responseHandler); {% else %} virtual void {{ function.functionName }}({{ json_object.namespace}}ResponseHandler* responseHandler); {% endif %} {% endfor %} }; using {{ json_object.namespace }}RequestBus = AZ::EBus<{{ json_object.namespace }}Requests>; // This class is used as a parameter for all requests and throws the response on the {{ json_object.namespace }}NotificationBus // Inherit from this to define custom behavior. class {{ json_object.namespace }}ResponseHandler { public: AZ_TYPE_INFO({{ json_object.namespace }}ResponseHandler, LmbrAWS_CodeGen_ResponseHandler_UUID) AZ_CLASS_ALLOCATOR({{ json_object.namespace }}ResponseHandler, AZ::SystemAllocator, 0) virtual ~{{ json_object.namespace }}ResponseHandler() {} {% for function in json_object.functions %} virtual void Handle{{ function.functionName}}Success({{ function.functionName}}RequestJob* job, AZ::EntityId entityId); virtual void Handle{{ function.functionName}}Error({{ function.functionName}}RequestJob* job, AZ::EntityId entityId); {% endfor %} }; class {{ json_object.componentClass }} : public AZ::Component , public {{ json_object.namespace }}RequestBus::Handler { public: AZ_COMPONENT({{ json_object.componentClass }}, LmbrAWS_CodeGen_Component_UUID); virtual ~{{ json_object.componentClass }}() = default; AZStd::shared_ptr<{{ json_object.namespace }}ResponseHandler> m_defaultResponseHandler; void Init() override; void Activate() override; void Deactivate() override; static void Reflect(AZ::ReflectContext* reflection) { {% for item in json_object.otherClasses %} {% if not item.isArray %} {{ item.name }}::Reflect(reflection); {% endif %} {% endfor %} AZ::SerializeContext* serializeContext = azrtti_cast(reflection); if (serializeContext) { // we must include any fields we want to expose to the editor or lua in the serialize context serializeContext->Class<{{ json_object.componentClass }}, AZ::Component>() ->Version(1); AZ::EditContext* editContext = serializeContext->GetEditContext(); if (editContext) { editContext->Class<{{ json_object.componentClass }}>("{{ json_object.componentClass }}", "{{ json_object.namespace }} Component") ->ClassElement(AZ::Edit::ClassElements::EditorData, "") ->Attribute(AZ::Edit::Attributes::Category, "Cloud Canvas Gems") ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game")); } } AZ::BehaviorContext* behaviorContext = azrtti_cast(reflection); if (behaviorContext) { behaviorContext->EBus<{{ json_object.namespace }}RequestBus>("{{ json_object.namespace }}RequestBus") // one of these for each function {% for function in json_object.functions %} ->Event("{{ function.functionName }}", &{{ json_object.namespace }}RequestBus::Events::{{ function.functionName }}) {% endfor %} ; behaviorContext->EBus<{{ json_object.namespace }}NotificationBus>("{{ json_object.namespace }}NotificationBus") ->Handler() ; } } // Functions from the swagger definitions {% for function in json_object.functions %} {% if function.typedParams %} void {{ function.functionName }}({{ function.typedParams}}, {{ json_object.namespace}}ResponseHandler* responseHandler) override; {% else %} void {{ function.functionName }}({{ json_object.namespace}}ResponseHandler* responseHandler) override; {% endif %} {% endfor %} }; } // ServiceAPI } // {{ json_object.namespace }}