123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #pragma once
- #include <AzCore/EBus/EBus.h>
- #include <AzCore/std/parallel/mutex.h>
- #include <AzCore/std/string/string.h>
- #include <AzCore/std/containers/vector.h>
- #include <AzFramework/Asset/AssetProcessorMessages.h>
- #include <AssetBuilderSDK/AssetBuilderBusses.h>
- #include <native/assetprocessor.h>
- #include <QByteArray>
- namespace AssetProcessor
- {
- struct BuilderParams;
- }
- namespace AssetUtilities
- {
- class QuitListener;
- class JobLogTraceListener;
- }
- //This EBUS broadcasts the platform of the connection the AssetProcessor connected or disconnected with
- class AssetProcessorPlaformBusTraits
- : public AZ::EBusTraits
- {
- public:
- static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple; // multi listener
- static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; //single bus
- virtual ~AssetProcessorPlaformBusTraits() {}
- //Informs that the AP got a connection for this platform.
- virtual void AssetProcessorPlatformConnected(const AZStd::string platform) {}
- //Informs that a connection got disconnected for this platform.
- virtual void AssetProcessorPlatformDisconnected(const AZStd::string platform) {}
- };
- using AssetProcessorPlatformBus = AZ::EBus<AssetProcessorPlaformBusTraits>;
- class ApplicationServerBusTraits
- : public AZ::EBusTraits
- {
- public:
- static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
- static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
- typedef AZStd::recursive_mutex MutexType;
- virtual ~ApplicationServerBusTraits() {};
- //! Returns the port the server is set to listen on
- virtual int GetServerListeningPort() const = 0;
- };
- using ApplicationServerBus = AZ::EBus<ApplicationServerBusTraits>;
- namespace AzFramework
- {
- namespace AssetSystem
- {
- class BaseAssetProcessorMessage;
- }
- }
- namespace AssetProcessor
- {
- // This bus sends messages to connected clients/proxies identified by their connection ID. The bus
- // is addressed by the connection ID as assigned by the ConnectionManager.
- class ConnectionBusTraits
- : public AZ::EBusTraits
- {
- public:
- static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
- static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
- typedef unsigned int BusIdType;
- typedef AZStd::recursive_mutex MutexType;
- virtual ~ConnectionBusTraits() {}
- // Sends an unsolicited message to the connection
- virtual size_t Send(unsigned int serial, const AzFramework::AssetSystem::BaseAssetProcessorMessage& message) = 0;
- // Sends a raw buffer to the connection
- virtual size_t SendRaw(unsigned int type, unsigned int serial, const QByteArray& data) = 0;
- // Sends a message to the connection if the platform match
- virtual size_t SendPerPlatform(unsigned int serial, const AzFramework::AssetSystem::BaseAssetProcessorMessage& message, const QString& platform) = 0;
- // Sends a raw buffer to the connection if the platform match
- virtual size_t SendRawPerPlatform(unsigned int type, unsigned int serial, const QByteArray& data, const QString& platform) = 0;
- using ResponseCallback = AZStd::function<void(AZ::u32, QByteArray)>;
- // Sends a message to the connection which expects a response.
- virtual unsigned int SendRequest(const AzFramework::AssetSystem::BaseAssetProcessorMessage& message, const ResponseCallback& callback) = 0;
- // Sends a response to the connection
- virtual size_t SendResponse(unsigned int serial, const AzFramework::AssetSystem::BaseAssetProcessorMessage& message) = 0;
- // Removes a response handler that is no longer needed
- virtual void RemoveResponseHandler(unsigned int serial) = 0;
- };
- using ConnectionBus = AZ::EBus<ConnectionBusTraits>;
- class MessageInfoBusTraits
- : public AZ::EBusTraits
- {
- public:
- static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple; // multi listener
- static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; //single bus
- typedef AZStd::recursive_mutex MutexType;
- virtual ~MessageInfoBusTraits() {}
- //Show a message window to the user
- virtual void NegotiationFailed() {}
- // Notifies listeners of a given Asset failing to process
- virtual void OnAssetFailed(const AZStd::string& /*sourceFileName*/) {}
- // Notifies listener about a general error
- virtual void OnErrorMessage([[maybe_unused]] const char* error) {}
- // Notifies listener about a builder registration failure
- virtual void OnBuilderRegistrationFailure() {};
- };
- using MessageInfoBus = AZ::EBus<MessageInfoBusTraits>;
- typedef AZStd::vector <AssetBuilderSDK::AssetBuilderDesc> BuilderInfoList;
- // This EBUS is used to retrieve asset builder Information
- class AssetBuilderInfoBusTraits
- : public AZ::EBusTraits
- {
- public:
- static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; // single listener
- static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; //single bus
- using MutexType = AZStd::recursive_mutex;
- virtual ~AssetBuilderInfoBusTraits() {}
- // For a given asset returns a list of all asset builder that are interested in it.
- virtual void GetMatchingBuildersInfo(const AZStd::string& assetPath, AssetProcessor::BuilderInfoList& /*builderInfoList*/) = 0;
- virtual void GetAllBuildersInfo(AssetProcessor::BuilderInfoList& /*builderInfoList*/) = 0;
- };
- using AssetBuilderInfoBus = AZ::EBus<AssetBuilderInfoBusTraits>;
- // This EBUS is used to broadcast information about the currently processing job
- class ProcessingJobInfoBusTraits
- : public AZ::EBusTraits
- {
- public:
- static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; // single listener
- static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; //single bus
- typedef AZStd::recursive_mutex MutexType;
- virtual ~ProcessingJobInfoBusTraits() {}
- // Will notify other systems a product is about to be updated in the cache. This can mean that
- // it will be created, overwritten with new data or deleted. BeginCacheFileUpdate is pared with
- // EndCacheFileUpdate.
- virtual void BeginCacheFileUpdate(const char* /*productPath*/) {};
- // Will notify other systems that a file in the cache has been updated along with status of whether it
- // succeeded or failed. EndCacheFileUpdate is paired with BeginCacheFileUpdate.
- virtual void EndCacheFileUpdate(const char* /*productPath*/, bool /*queueAgainForDeletion*/) {};
- virtual AZ::u32 GetJobFingerprint(const AssetProcessor::JobIndentifier& /*jobIndentifier*/) { return 0; };
- };
- using ProcessingJobInfoBus = AZ::EBus<ProcessingJobInfoBusTraits>;
- // This EBUS is used to issue requests to the AssetCatalog
- class AssetRegistryRequests
- : public AZ::EBusTraits
- {
- public:
- static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; // single listener
- static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; //single bus
- typedef AZStd::recursive_mutex MutexType;
- // This function will either return the registry version of the next registry save or of the current one, if it is in progress
- // It will not put another save registry event in the event pump if we are currently in the process of saving the registry
- virtual int SaveRegistry() = 0;
- // This method checks for cyclic preload dependency for all the currently processed assets.
- virtual void ValidatePreLoadDependency() = 0;
- };
- typedef AZ::EBus<AssetRegistryRequests> AssetRegistryRequestBus;
- // This EBUS issues notifications when the catalog begins and finishes saving the asset registry
- class AssetRegistryNotifications
- : public AZ::EBusTraits
- {
- public:
- static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple; // single listener
- static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; //single bus
- typedef AZStd::recursive_mutex MutexType;
- // The asset catalog has finished saving the registry
- virtual void OnRegistrySaveComplete(int /*assetCatalogVersion*/, bool /*allCatalogsSaved*/) {}
- };
- using AssetRegistryNotificationBus = AZ::EBus<AssetRegistryNotifications>;
- // This EBUS is used to check if there is sufficient disk space
- class IDiskSpaceInfo
- {
- public:
- AZ_RTTI(IDiskSpaceInfo, "{0A324878-9871-49DA-8F34-AE3B1D43B7C0}");
- // Returns true if there is at least `requiredSpace` bytes plus 256kb free disk space in the project cache folder
- // If shutdownIfInsufficient is true, an error will be displayed and the application will be shutdown
- virtual bool CheckSufficientDiskSpace(qint64 /*requiredSpace*/, bool /*shutdownIfInsufficient*/) { return true; }
- };
- //! Defines the modes the Asset Cache Server mode setting for the Asset Processor (AP).
- enum class AssetServerMode
- {
- Inactive, //! This mode means the AP is offline; only processing the assets locally
- Server, //! This mode means the AP is writing out the asset products to a remote location
- Client //! This mode means the AP is attempting to retrieve asset products from a remote location
- };
- // This EBUS is used to perform Asset Server related tasks.
- class AssetServerBusTraits
- : public AZ::EBusTraits
- {
- public:
- static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
- static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
- typedef AZStd::recursive_mutex MutexType;
- static const bool LocklessDispatch = true;
- //! This will return true if we were able to verify the server address as being valid, otherwise return false.
- virtual bool IsServerAddressValid() = 0;
- //! StoreJobResult should store all the files in the temp folder provided by the builderParams to the server
- //! As well as any outputProducts which are outside the temp folder intended to be copied directly to the
- //! Cache without going through the temp folder
- //! It should associate those files with the server key provided by the builderParams because
- //! it will be send the same server key to retrieve these files by the client.
- //! This will return true if it was able to save all the relevant job data to the server, otherwise return false.
- virtual bool StoreJobResult(const AssetProcessor::BuilderParams& builderParams, AZStd::vector<AZStd::string>& sourceFileList) = 0;
- //! RetrieveJobResult should retrieve all the files associated with the server key provided in the builderParams
- //! and put them in the temporary directory provided by the builderParam.
- //! This will return true if it was able to retrieve all the relevant job data from the server, otherwise return false.
- virtual bool RetrieveJobResult(const AssetProcessor::BuilderParams& builderParams) = 0;
- //! Retrieve the current mode for shared caching
- virtual AssetServerMode GetRemoteCachingMode() const = 0;
- //! Store the shared caching mode
- virtual void SetRemoteCachingMode(AssetServerMode mode) = 0;
- //! Retrieve the remote folder location for the shared cache
- virtual const AZStd::string& GetServerAddress() const = 0;
- //! Store the remote folder location for the shared cache
- virtual bool SetServerAddress(const AZStd::string& address) = 0;
- };
- using AssetServerBus = AZ::EBus<AssetServerBusTraits>;
- // This EBUS has notify listeners when Asset Server state(s) changes.
- class AssetServerNotifications
- : public AZ::EBusTraits
- {
- public:
- static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple; // multi listener
- static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; //single bus
- typedef AZStd::recursive_mutex MutexType;
- //! This emits when the mode of the Asset Server Cache mode has changed.
- virtual void OnRemoteCachingModeChanged([[maybe_unused]] AssetServerMode mode) {}
- };
- using AssetServerNotificationBus = AZ::EBus<AssetServerNotifications>;
- // This EBUS is used to retrieve asset server information
- class AssetServerInfoBusTraits
- : public AZ::EBusTraits
- {
- public:
- static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; // single listener
- static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; // single bus
- using MutexType = AZStd::recursive_mutex;
- virtual ~AssetServerInfoBusTraits() = default;
- virtual const AZStd::string& ComputeArchiveFilePath(const AssetProcessor::BuilderParams& builderParams) = 0;
- };
- using AssetServerInfoBus = AZ::EBus<AssetServerInfoBusTraits>;
- } // namespace AssetProcessor
|