/* * 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. * */ #include #include #include #include #include namespace PythonAssetBuilder { void PythonBuilderWorker::Reflect(AZ::ReflectContext* context) { if (auto&& serialize = azrtti_cast(context)) { serialize->Class()->Version(0); } if (auto&& behaviorContext = azrtti_cast(context)) { behaviorContext->Class("PythonBuilderWorker") ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation) ->Attribute(AZ::Script::Attributes::Module, "asset.builder") ->Constructor() ; } } bool PythonBuilderWorker::ConfigureBuilderInformation(const AssetBuilderSDK::AssetBuilderDesc& assetBuilderDesc) { using namespace AssetBuilderSDK; if (m_assetBuilderDesc) { AZ_Error(PythonBuilder, false, "Asset Builder (%s) already configured!", assetBuilderDesc.m_name.c_str()); return false; } // register the new PythonBuilderWorker instance with the Asset Builder m_assetBuilderDesc = AZStd::make_shared(assetBuilderDesc); // prepare delegate handler for CreateJobs function to be resolved in a Python script m_assetBuilderDesc->m_createJobFunction = [this](auto&& request, auto&& response) { this->CreateJobs(request, response); }; // prepare delegate handler for ProcessJob function to be resolved in a Python script m_assetBuilderDesc->m_processJobFunction = [this](auto&& request, auto&& response) { this->ProcessJob(request, response); }; // connect to the shutdown signal handler AssetBuilderCommandBus::Handler::BusConnect(m_assetBuilderDesc->m_busId); // register with the Asset Builder AssetBuilderBus::Broadcast(&AssetBuilderBus::Events::RegisterBuilderInformation, *m_assetBuilderDesc); return true; } void PythonBuilderWorker::ShutDown() { // Note - Shutdown will be called on a different thread than your process job thread if (!m_isShuttingDown) { m_isShuttingDown = true; PythonBuilderNotificationBus::Event(m_busId, &PythonBuilderNotificationBus::Events::OnShutdown); AssetBuilderSDK::AssetBuilderCommandBus::Handler::BusDisconnect(); } } void PythonBuilderWorker::CreateJobs(const AssetBuilderSDK::CreateJobsRequest& request, AssetBuilderSDK::CreateJobsResponse& response) { if (m_isShuttingDown) { response.m_result = AssetBuilderSDK::CreateJobsResultCode::ShuttingDown; return; } // assume failure response.m_result = AssetBuilderSDK::CreateJobsResultCode::Failed; PythonBuilderNotificationBus::EventResult( response, request.m_builderid, &PythonBuilderNotificationBus::Events::OnCreateJobsRequest, request); } void PythonBuilderWorker::ProcessJob(const AssetBuilderSDK::ProcessJobRequest& request, AssetBuilderSDK::ProcessJobResponse& response) { AssetBuilderSDK::JobCommandBus::Handler::BusConnect(request.m_jobId); // assume failure response.m_resultCode = AssetBuilderSDK::ProcessJobResult_Failed; PythonBuilderNotificationBus::EventResult( response, request.m_builderGuid, &PythonBuilderNotificationBus::Events::OnProcessJobRequest, request); AssetBuilderSDK::JobCommandBus::Handler::BusDisconnect(request.m_jobId); } void PythonBuilderWorker::Cancel() { PythonBuilderNotificationBus::Event(m_busId, &PythonBuilderNotificationBus::Events::OnCancel); } }