rccontroller.h 5.8 KB

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