ApplicationManagerBase.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #if !defined(Q_MOC_RUN)
  10. #include <AzCore/std/string/string.h>
  11. #include <AzCore/std/smart_ptr/unique_ptr.h>
  12. #include <AzCore/std/containers/vector.h>
  13. #include <AzCore/Debug/TraceMessageBus.h>
  14. #include <AzToolsFramework/API/AssetDatabaseBus.h>
  15. #include <native/FileWatcher/FileWatcherBase.h>
  16. #include <native/utilities/ApplicationManager.h>
  17. #include <native/utilities/AssetBuilderInfo.h>
  18. #include <native/utilities/BuilderManager.h>
  19. #include <native/utilities/UuidManager.h>
  20. #include <QtGui/qwindowdefs.h>
  21. #endif
  22. namespace AzToolsFramework
  23. {
  24. class ProcessWatcher;
  25. class Ticker;
  26. }
  27. namespace AssetProcessor
  28. {
  29. class AssetCatalog;
  30. class AssetProcessorManager;
  31. class AssetRequestHandler;
  32. class AssetScanner;
  33. class AssetServerHandler;
  34. class BuilderConfigurationManager;
  35. class BuilderManager;
  36. class ExternalModuleAssetBuilderInfo;
  37. class FileProcessor;
  38. class FileStateBase;
  39. class FileStateCache;
  40. class InternalAssetBuilderInfo;
  41. class PlatformConfiguration;
  42. class RCController;
  43. class SettingsRegistryBuilder;
  44. }
  45. class ApplicationServer;
  46. class ConnectionManager;
  47. class ControlRequestHandler;
  48. class ApplicationManagerBase
  49. : public ApplicationManager
  50. , public AssetBuilderSDK::AssetBuilderBus::Handler
  51. , public AssetProcessor::AssetBuilderInfoBus::Handler
  52. , public AssetProcessor::AssetBuilderRegistrationBus::Handler
  53. , public AZ::Debug::TraceMessageBus::Handler
  54. , protected AzToolsFramework::AssetDatabase::AssetDatabaseRequests::Bus::Handler
  55. , public AZ::Interface<AssetProcessor::IDiskSpaceInfo>::Registrar
  56. , protected AzToolsFramework::SourceControlNotificationBus::Handler
  57. , public AssetProcessor::MessageInfoBus::Handler
  58. {
  59. Q_OBJECT
  60. public:
  61. ApplicationManagerBase(int* argc, char*** argv, QObject* parent = nullptr);
  62. ApplicationManagerBase(int* argc, char*** argv, AZ::ComponentApplicationSettings componentAppSettings);
  63. ApplicationManagerBase(int* argc, char*** argv, QObject* parent, AZ::ComponentApplicationSettings componentAppSettings);
  64. virtual ~ApplicationManagerBase();
  65. ApplicationManager::BeforeRunStatus BeforeRun() override;
  66. void Destroy() override;
  67. bool Run() override;
  68. void HandleFileRelocation() const;
  69. bool Activate() override;
  70. bool PostActivate() override;
  71. void Reflect() override;
  72. AssetProcessor::PlatformConfiguration* GetPlatformConfiguration() const;
  73. AssetProcessor::AssetProcessorManager* GetAssetProcessorManager() const;
  74. AssetProcessor::AssetScanner* GetAssetScanner() const;
  75. AssetProcessor::RCController* GetRCController() const;
  76. ConnectionManager* GetConnectionManager() const;
  77. ApplicationServer* GetApplicationServer() const;
  78. int ProcessedAssetCount() const;
  79. int FailedAssetsCount() const;
  80. void ResetProcessedAssetCount();
  81. void ResetFailedAssetCount();
  82. //! AssetBuilderSDK::AssetBuilderBus Interface
  83. void RegisterBuilderInformation(const AssetBuilderSDK::AssetBuilderDesc& builderDesc) override;
  84. void RegisterComponentDescriptor(AZ::ComponentDescriptor* descriptor) override;
  85. void BuilderLog(const AZ::Uuid& builderId, const char* message, ...) override;
  86. void BuilderLogV(const AZ::Uuid& builderId, const char* message, va_list list) override;
  87. bool FindBuilderInformation(const AZ::Uuid& builderGuid, AssetBuilderSDK::AssetBuilderDesc& descriptionOut) override;
  88. //! AssetBuilderSDK::InternalAssetBuilderBus Interface
  89. void UnRegisterBuilderDescriptor(const AZ::Uuid& builderId) override;
  90. //! AssetProcessor::AssetBuilderInfoBus Interface
  91. void GetMatchingBuildersInfo(const AZStd::string& assetPath, AssetProcessor::BuilderInfoList& builderInfoList) override;
  92. void GetAllBuildersInfo(AssetProcessor::BuilderInfoList& builderInfoList) override;
  93. //! TraceMessageBus Interface
  94. bool OnError(const char* window, const char* message) override;
  95. //! IDiskSpaceInfo Interface
  96. bool CheckSufficientDiskSpace(qint64 requiredSpace, bool shutdownIfInsufficient) override;
  97. //! AzFramework::SourceControlNotificationBus::Handler
  98. void ConnectivityStateChanged(const AzToolsFramework::SourceControlState newState) override;
  99. //! MessageInfoBus::Handler
  100. void OnBuilderRegistrationFailure() override;
  101. void RemoveOldTempFolders();
  102. void Rescan();
  103. void FastScan();
  104. bool IsAssetProcessorManagerIdle() const override;
  105. bool CheckFullIdle();
  106. // Used to track AP command line checks, so the help can be easily printed.
  107. struct APCommandLineSwitch
  108. {
  109. APCommandLineSwitch(AZStd::vector<APCommandLineSwitch>& commandLineInfo, const char* switchTitle, const char* helpText)
  110. : m_switch(switchTitle)
  111. , m_helpText(helpText)
  112. {
  113. commandLineInfo.push_back(*this);
  114. }
  115. const char* m_switch;
  116. const char* m_helpText;
  117. };
  118. virtual WId GetWindowId() const;
  119. Q_SIGNALS:
  120. void CheckAssetProcessorManagerIdleState();
  121. void ConnectionStatusMsg(QString message);
  122. void SourceControlReady();
  123. void OnBuildersRegistered();
  124. void AssetProcesserManagerIdleStateChange(bool isIdle);
  125. void FullIdle(bool isIdle);
  126. public Q_SLOTS:
  127. void OnAssetProcessorManagerIdleState(bool isIdle);
  128. protected:
  129. virtual void InitAssetProcessorManager(AZStd::vector<APCommandLineSwitch>& commandLineInfo);//Deletion of assetProcessor Manager will be handled by the ThreadController
  130. virtual void InitAssetCatalog(); // Deletion of AssetCatalog will be handled when the ThreadController is deleted by the base ApplicationManager
  131. virtual void ConnectAssetCatalog();
  132. virtual void InitRCController();
  133. virtual void DestroyRCController();
  134. virtual void InitAssetScanner();
  135. virtual void DestroyAssetScanner();
  136. virtual bool InitPlatformConfiguration();
  137. virtual void DestroyPlatformConfiguration();
  138. virtual void InitFileMonitor(AZStd::unique_ptr<FileWatcherBase> fileWatcher);
  139. virtual void DestroyFileMonitor();
  140. virtual bool InitBuilderConfiguration();
  141. virtual void InitControlRequestHandler();
  142. virtual void DestroyControlRequestHandler();
  143. virtual bool InitApplicationServer() = 0;
  144. void DestroyApplicationServer();
  145. virtual void InitConnectionManager();
  146. void DestroyConnectionManager();
  147. void InitAssetRequestHandler(AssetProcessor::AssetRequestHandler* assetRequestHandler);
  148. virtual void InitFileStateCache();
  149. virtual void InitUuidManager();
  150. void CreateQtApplication() override;
  151. bool InitializeInternalBuilders();
  152. void InitBuilderManager();
  153. void ShutdownBuilderManager();
  154. bool InitAssetDatabase(bool ignoreFutureAssetDBVersionError);
  155. void ShutDownAssetDatabase();
  156. void InitAssetServerHandler();
  157. void DestroyAssetServerHandler();
  158. void InitFileProcessor();
  159. void ShutDownFileProcessor();
  160. virtual void InitSourceControl() = 0;
  161. void InitInputThread();
  162. void InputThread();
  163. void HandleCommandLineHelp(AZStd::vector<APCommandLineSwitch>& commandLineInfo);
  164. // Give an opportunity to derived classes to make connections before the application server starts listening
  165. virtual void MakeActivationConnections() {}
  166. virtual bool GetShouldExitOnIdle() const = 0;
  167. virtual void TryScanProductDependencies() {}
  168. virtual void TryHandleFileRelocation() {}
  169. // IMPLEMENTATION OF -------------- AzToolsFramework::AssetDatabase::AssetDatabaseRequests::Bus::Listener
  170. bool GetAssetDatabaseLocation(AZStd::string& location) override;
  171. // ------------------------------------------------------------
  172. AssetProcessor::AssetCatalog* GetAssetCatalog() const { return m_assetCatalog; }
  173. bool CheckReprocessFileList();
  174. ApplicationServer* m_applicationServer = nullptr;
  175. ConnectionManager* m_connectionManager = nullptr;
  176. // keep track of the critical loading point where we are loading other dlls so the error messages can be better.
  177. bool m_isCurrentlyLoadingGems = false;
  178. public Q_SLOTS:
  179. void OnActiveJobsCountChanged(unsigned int count);
  180. protected Q_SLOTS:
  181. void CheckForIdle();
  182. protected:
  183. int m_processedAssetCount = 0;
  184. int m_warningCount = 0;
  185. int m_errorCount = 0;
  186. int m_remainingAssetsToFinalize = 0;
  187. AZStd::set<AZStd::string> m_failedAssets;
  188. bool m_AssetProcessorManagerIdleState = false;
  189. bool m_sourceControlReady = false;
  190. bool m_fullIdle = false;
  191. AZStd::unique_ptr<FileWatcherBase> m_fileWatcher;
  192. AssetProcessor::PlatformConfiguration* m_platformConfiguration = nullptr;
  193. AssetProcessor::AssetProcessorManager* m_assetProcessorManager = nullptr;
  194. AssetProcessor::AssetCatalog* m_assetCatalog = nullptr;
  195. AssetProcessor::AssetScanner* m_assetScanner = nullptr;
  196. AssetProcessor::RCController* m_rcController = nullptr;
  197. AssetProcessor::AssetRequestHandler* m_assetRequestHandler = nullptr;
  198. AssetProcessor::BuilderManager* m_builderManager = nullptr;
  199. AssetProcessor::AssetServerHandler* m_assetServerHandler = nullptr;
  200. ControlRequestHandler* m_controlRequestHandler = nullptr;
  201. AZStd::unique_ptr<AssetProcessor::FileStateBase> m_fileStateCache;
  202. AZStd::unique_ptr<AssetProcessor::FileProcessor> m_fileProcessor;
  203. AZStd::unique_ptr<AssetProcessor::BuilderConfigurationManager> m_builderConfig;
  204. AZStd::unique_ptr<AssetProcessor::UuidManager> m_uuidManager;
  205. // The internal builders
  206. AZStd::shared_ptr<AssetProcessor::InternalRecognizerBasedBuilder> m_internalBuilder;
  207. AZStd::shared_ptr<AssetProcessor::SettingsRegistryBuilder> m_settingsRegistryBuilder;
  208. bool m_builderRegistrationComplete = false;
  209. // Builder description map based on the builder id
  210. AZStd::unordered_map<AZ::Uuid, AssetBuilderSDK::AssetBuilderDesc> m_builderDescMap;
  211. // Lookup for builder ids based on the name. The builder name must be unique
  212. AZStd::unordered_map<AZStd::string, AZ::Uuid> m_builderNameToId;
  213. // Builder pattern matchers to used to locate the builder descriptors that match a pattern
  214. AZStd::list<AssetUtilities::BuilderFilePatternMatcher> m_matcherBuilderPatterns;
  215. // Collection of all the external module builders
  216. AZStd::list<AssetProcessor::ExternalModuleAssetBuilderInfo*> m_externalAssetBuilders;
  217. AssetProcessor::ExternalModuleAssetBuilderInfo* m_currentExternalAssetBuilder = nullptr;
  218. QAtomicInt m_connectionsAwaitingAssetCatalogSave = 0;
  219. int m_remainingAPMJobs = 0;
  220. bool m_assetProcessorManagerIsReady = false;
  221. unsigned int m_highestConnId = 0;
  222. AzToolsFramework::Ticker* m_ticker = nullptr; // for ticking the tickbus.
  223. QList<QMetaObject::Connection> m_connectionsToRemoveOnShutdown;
  224. QString m_dependencyScanPattern;
  225. QString m_fileDependencyScanPattern;
  226. QString m_reprocessFileList;
  227. QStringList m_filesToReprocess;
  228. AZStd::vector<AZStd::string> m_dependencyAddtionalScanFolders;
  229. int m_dependencyScanMaxIteration = AssetProcessor::MissingDependencyScanner::DefaultMaxScanIteration; // The maximum number of times to recurse when scanning a file for missing dependencies.
  230. };