/* * 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 ///////////////////////////////////////////////////////// ///////////////////////////////////////////////////////// {% if json_object.HasStdAfx %} #include "StdAfx.h" {% elif json_object.DisabledPCH == False %} #include "{{ json_object.namespace }}_precompiled.h" {% endif %} #include "AWS/ServiceAPI/{{ json_object.componentClass }}.h" namespace {{ json_object.namespace }} { namespace ServiceAPI { {% for key, value in json_object.UUIDs.items() %} const char* LmbrAWS_CodeGen_{{ key }}_UUID= "{{ value }}"; {% endfor %} void Configure() { // Insert any necessary CloudGemFramework configuration here } // redefs bool WriteJson(CloudGemFramework::JsonWriter& writer, const int& item) { return writer.Int(item); } bool WriteJson(CloudGemFramework::JsonWriter& writer, const AZStd::string& item) { return writer.String(item); } bool WriteJson(CloudGemFramework::JsonWriter& writer, const double& item) { return writer.Double(item); } {% for item in json_object.otherClasses %} {% if item.isArray %} bool WriteJson(CloudGemFramework::JsonWriter& writer, const {{ item.name }}& list) { bool ok = true; ok = ok && writer.StartArray(); for (auto item : list) { ok = ok && WriteJson(writer, item); } ok = ok && writer.EndArray(); return ok; } {% else %} bool WriteJson(CloudGemFramework::JsonWriter& writer, const {{ item.name }}& item) { bool ok = true; ok = ok && writer.StartObject(); {% for prop in item.props %} ok = ok && writer.Key("{{ prop.name }}"); ok = ok && WriteJson(writer, item.{{ prop.name }}); {% endfor %} ok = ok && writer.EndObject(); return ok; } {% endif %} {% endfor %} // Generated Function Parameters {% for path in json_object.functions %} bool {{ path.functionName }}Request::Parameters::BuildRequest(CloudGemFramework::RequestBuilder& request) { bool ok = true; {% for param in path.pathParamNames %} ok = ok && request.SetPathParameter("{""{{ param }}""}", {{ param }}); {% endfor %} {% for param in path.queryParamNames %} ok = ok && request.AddQueryParameter("{{ param }}", {{ param }}); {% endfor %} ok = ok && request.WriteJsonBodyParameter(*this); return ok; } bool {{ path.functionName }}Request::Parameters::WriteJson(CloudGemFramework::JsonWriter& writer) const { bool ok = true; {% for param in path.paramNames %} ok = ok && {{ json_object.namespace }}::ServiceAPI::WriteJson(writer, {{ param }}); {% endfor %} return ok; } {% endfor %} // {{ json_object.namespace }}NotificationBus {% for function in json_object.functions %} {% if function.responseType %} void {{ json_object.namespace }}Notifications::On{{ function.functionName }}RequestSuccess(const {{ function.responseType }} response) { } {% else %} void {{ json_object.namespace }}Notifications::On{{ function.functionName }}RequestSuccess() { } {% endif %} void {{ json_object.namespace }}Notifications::On{{ function.functionName }}RequestError(const CloudGemFramework::Error error) { } {% endfor %} // BehaviorContext {{ json_object.namespace }}NotificationBus handler implementation {% for function in json_object.functions %} {% if function.responseType %} void Behavior{{ json_object.namespace }}NotificationBusHandler::On{{ function.functionName }}RequestSuccess(const {{ function.responseType }} response) { Call(FN_On{{ function.functionName}}RequestSuccess, response); } {% else %} void Behavior{{ json_object.namespace }}NotificationBusHandler::On{{ function.functionName }}RequestSuccess() { Call(FN_On{{ function.functionName}}RequestSuccess); } {% endif %} void Behavior{{ json_object.namespace }}NotificationBusHandler::On{{ function.functionName }}RequestError(const CloudGemFramework::Error error) { Call(FN_On{{ function.functionName }}RequestError, error); } {% endfor %} // {{ json_object.namespace }}RequestBus {% for function in json_object.functions %} {% if function.typedParams %} void {{ json_object.namespace }}Requests::{{ function.functionName }}({{ function.typedParams}}, {{ json_object.namespace}}ResponseHandler* responseHandler) { } {% else %} void {{ json_object.namespace }}Requests::{{ function.functionName }}({{ json_object.namespace}}ResponseHandler* responseHandler) { } {% endif %} {% endfor %} // {{ json_object.namespace }}ResponseHandler {% for function in json_object.functions %} void {{ json_object.namespace }}ResponseHandler::Handle{{ function.functionName}}Success({{ function.functionName}}RequestJob* job, AZ::EntityId entityId) { {% if function.responseType %} EBUS_EVENT_ID(entityId, {{ json_object.namespace }}NotificationBus, On{{ function.functionName }}RequestSuccess, job->result); {% else %} EBUS_EVENT_ID(entityId, {{ json_object.namespace }}NotificationBus, On{{ function.functionName }}RequestSuccess); {% endif %} } void {{ json_object.namespace }}ResponseHandler::Handle{{ function.functionName}}Error({{ function.functionName}}RequestJob* job, AZ::EntityId entityId) { EBUS_EVENT_ID(entityId, {{ json_object.namespace }}NotificationBus, On{{ function.functionName }}RequestError, job->error); } {% endfor %} // {{ json_object.componentClass }} void {{ json_object.componentClass }}::Init() { m_defaultResponseHandler = AZStd::make_shared<{{ json_object.namespace }}ResponseHandler>(); {{ json_object.namespace }}::ServiceAPI::Configure(); } void {{ json_object.componentClass }}::Activate() { {{ json_object.namespace }}RequestBus::Handler::BusConnect(m_entity->GetId()); } void {{ json_object.componentClass }}::Deactivate() { {{ json_object.namespace }}RequestBus::Handler::BusDisconnect(); } {% for function in json_object.functions %} {% if function.typedParams %} void {{ json_object.componentClass }}::{{ function.functionName }}({{ function.typedParams}}, {{ json_object.namespace}}ResponseHandler* responseHandler) {% else %} void {{ json_object.componentClass }}::{{ function.functionName }}({{ json_object.namespace}}ResponseHandler* responseHandler) {% endif %} { // Cache our entityId in case the entity goes away AZ::EntityId entityId; if (m_entity) { entityId = m_entity->GetId(); } // Cache our default response handler in case this component goes away AZStd::shared_ptr < {{ json_object.namespace }}ResponseHandler > defaultResponseHandler = m_defaultResponseHandler; // Create job {{ function.functionName}}RequestJob* requestJob = {{ function.functionName}}RequestJob::Create( [responseHandler, defaultResponseHandler, entityId]({{ function.functionName}}RequestJob* successJob) { // handle success {{ json_object.namespace}}ResponseHandler* successHandler = responseHandler ? responseHandler : defaultResponseHandler.get(); if (successHandler) { successHandler->Handle{{ function.functionName }}Success(successJob, entityId); } }, [responseHandler, defaultResponseHandler, entityId]({{ function.functionName}}RequestJob* failedJob) { // handle error {{ json_object.namespace}}ResponseHandler* failureHandler = responseHandler ? responseHandler : defaultResponseHandler.get(); if (failureHandler) { failureHandler->Handle{{ function.functionName }}Error(failedJob, entityId); } } ); {% for param in function.paramNames %} requestJob->parameters.{{ param }} = {{ param }}; {% endfor %} {% for param in function.pathParamNames %} requestJob->parameters.{{ param }} = {{ param }}; {% endfor %} {% for param in function.queryParamNames %} requestJob->parameters.{{ param }} = {{ param }}; {% endfor %} requestJob->Start(); } {% endfor %} {% for item in json_object.otherClasses %} {% if not item.isArray %} bool {{ item.name }}::OnJsonKey(const char* key, CloudGemFramework::JsonReader& reader) { {% for prop in item.props %} if (strcmp(key, "{{prop.name}}") == 0) return reader.Accept({{ prop.name }}); {% endfor %} return reader.Ignore(); } void {{ item.name }}::Reflect(AZ::ReflectContext* reflection) { AZ::SerializeContext* serializeContext = azrtti_cast(reflection); if (serializeContext) { serializeContext->Class<{{ item.name }}>() ->Version(1); } AZ::BehaviorContext* behaviorContext = azrtti_cast(reflection); if (behaviorContext) { behaviorContext->Class<{{ item.name }}>("{{ json_object.namespace }}_{{ item.name }}") ->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::Value) {% for prop in item.props %} ->Property("{{ prop.name }}", BehaviorValueProperty(&{{ item.name }}::{{ prop.name }})) {% endfor %} ; } } {% endif %} {% endfor %} } }