rccontroller.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. #ifndef RCCONTROLLER_H
  9. #define RCCONTROLLER_H
  10. #if !defined(Q_MOC_RUN)
  11. #include "RCCommon.h"
  12. #include <QObject>
  13. #include <QList>
  14. #include "native/utilities/AssetUtilEBusHelper.h"
  15. #include "rcjoblistmodel.h"
  16. #include "RCQueueSortModel.h"
  17. #include <AzFramework/Asset/AssetProcessorMessages.h>
  18. #include <AzToolsFramework/API/EditorAssetSystemAPI.h>
  19. #endif
  20. class RCcontrollerUnitTests;
  21. namespace AssetProcessor
  22. {
  23. /**
  24. * The RCController class controls the receiving of job requests, adding them to the model,
  25. * running RC and sending of responses
  26. */
  27. class RCController
  28. : public QObject
  29. , public AssetProcessorPlatformBus::Handler
  30. {
  31. friend class ::RCcontrollerUnitTests;
  32. Q_OBJECT
  33. public:
  34. enum CommandType
  35. {
  36. cmdUnknown = 0,
  37. cmdExecute,
  38. cmdTerminate
  39. };
  40. explicit RCController(QObject* parent = 0);
  41. virtual ~RCController();
  42. AssetProcessor::RCJobListModel* GetQueueModel();
  43. void StartJob(AssetProcessor::RCJob* rcJob);
  44. int NumberOfPendingCriticalJobsPerPlatform(QString platform);
  45. int NumberOfPendingJobsPerPlatform(QString platform);
  46. bool IsIdle();
  47. Q_SIGNALS:
  48. void FileCompiled(JobEntry entry, AssetBuilderSDK::ProcessJobResponse response);
  49. void FileFailed(JobEntry entry);
  50. void FileCancelled(JobEntry entry);
  51. //void AssetStatus(JobEntry jobEntry, AzFramework::AssetProcessor::AssetStatus status);
  52. void RcError(QString error);
  53. void ReadyToQuit(QObject* source); //After receiving QuitRequested, you must send this when its safe
  54. ///! JobStarted will notify with a path name relative to the watch folder it was found in (not the database sourcename column)
  55. void JobStarted(QString inputFile, QString platform);
  56. void JobStatusChanged(JobEntry entry, AzToolsFramework::AssetSystem::JobStatus status);
  57. void JobsInQueuePerPlatform(QString platform, int jobs);
  58. void ActiveJobsCountChanged(unsigned int jobs); // This is the count of jobs which are either queued or inflight
  59. void BecameIdle();
  60. //! This will be signalled upon compile group creation - or failure to do so (in which case status will be unknown)
  61. void CompileGroupCreated(AssetProcessor::NetworkRequestID groupID, AzFramework::AssetSystem::AssetStatus status);
  62. //! Once a compile group has an error or finished, this will be invoked.
  63. void CompileGroupFinished(AssetProcessor::NetworkRequestID groupID, AzFramework::AssetSystem::AssetStatus status);
  64. void EscalateJobs(AssetProcessor::JobIdEscalationList jobIdEscalationList);
  65. public Q_SLOTS:
  66. void JobSubmitted(JobDetails details);
  67. void QuitRequested();
  68. //! This will be called in order to create a compile group and start tracking it.
  69. void OnRequestCompileGroup(AssetProcessor::NetworkRequestID groupID, QString platform, QString searchTerm, AZ::Data::AssetId assetId, bool isStatusRequest = true, int searchType = 0);
  70. void OnEscalateJobsBySearchTerm(QString platform, QString searchTerm);
  71. void OnEscalateJobsBySourceUUID(QString platform, AZ::Uuid sourceUuid);
  72. void DispatchJobs();
  73. void DispatchJobsImpl();
  74. //! Pause or unpause dispatching, only necessary on startup to avoid thrashing and make sure no jobs jump the gun.
  75. void SetDispatchPaused(bool pause);
  76. //! All jobs which match this source will be cancelled or removed. Note that relSourceFile should have any applicable output prefixes!
  77. void RemoveJobsBySource(const AssetProcessor::SourceAssetReference& sourceAsset);
  78. // when the AP is truly done with a particular job and its going to be deleted and nothing more cares about it,
  79. // this function is called. this allows us to synchronize the various threads (catalog, queue, etc) to know that
  80. // its completely done.
  81. void OnJobComplete(JobEntry completeEntry, AzToolsFramework::AssetSystem::JobStatus status);
  82. void OnAddedToCatalog(JobEntry jobEntry);
  83. //! The config about # of jobs and slots may have changed, recompute it.
  84. void UpdateAndComputeJobSlots();
  85. //! When a new source file appears in the intermediate source folder, we can potentially resolve job dependencies
  86. //! That we could not resolve before.
  87. void OnIntermediateSourceAppeared(QString sourceRef);
  88. protected:
  89. AssetProcessor::RCQueueSortModel m_RCQueueSortModel;
  90. private:
  91. void FinishJob(AssetProcessor::RCJob* rcJob);
  92. unsigned int m_maxJobs = 0; //<! 0 means autocompute, read from registry key
  93. bool m_alwaysUseMaxJobs = false; //<! normally, it only uses maxJobs cpu cores when critical or escalated work is present to save CPU usage
  94. bool m_dispatchingJobs = false;
  95. bool m_shuttingDown = false;
  96. bool m_dispatchingPaused = true;// dispatching starts out paused.
  97. bool m_dispatchJobsQueued = false;
  98. QMap<QString, int> m_jobsCountPerPlatform;// This stores the count of jobs per platform in the RC Queue
  99. QMap<QString, int> m_pendingCriticalJobsPerPlatform;// This stores the count of pending critical jobs per platform in the RC Queue
  100. AssetProcessor::RCJobListModel m_RCJobListModel;
  101. //! An Asset Compile Group is a set of assets that we're tracking the compilation of
  102. //! It consists of a whole bunch of assets and is considered to be "complete" when either one of the assets in the group fails
  103. //! Or all assets in the group have finished.
  104. class AssetCompileGroup
  105. {
  106. public:
  107. AssetProcessor::NetworkRequestID m_requestID;
  108. QSet<AssetProcessor::QueueElementID> m_groupMembers;
  109. };
  110. QList<AssetCompileGroup> m_activeCompileGroups;
  111. };
  112. } // namespace AssetProcessor
  113. #endif // RCCONTROLLER_H