rcjoblistmodel.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 RCQUEUEMODEL_H
  9. #define RCQUEUEMODEL_H
  10. #if !defined(Q_MOC_RUN)
  11. #include "RCCommon.h"
  12. #include <QAbstractItemModel>
  13. #include <QObject>
  14. #include <QQueue>
  15. #include <QMultiMap>
  16. #include "rcjob.h"
  17. #endif
  18. namespace AssetProcessor
  19. {
  20. class QueueElementID;
  21. }
  22. class RCcontrollerUnitTests;
  23. namespace AssetProcessor
  24. {
  25. /**
  26. * The RCJobListModel class contains lists of RC jobs
  27. */
  28. class RCJobListModel
  29. : public QAbstractItemModel
  30. {
  31. friend class ::RCcontrollerUnitTests;
  32. Q_OBJECT
  33. public:
  34. enum DataRoles
  35. {
  36. jobIndexRole = Qt::UserRole + 1,
  37. stateRole,
  38. displayNameRole,
  39. timeCreatedRole,
  40. timeLaunchedRole,
  41. timeCompletedRole,
  42. jobDataRole,
  43. };
  44. enum Column
  45. {
  46. ColumnState,
  47. ColumnJobId,
  48. ColumnCommand,
  49. ColumnCompleted,
  50. ColumnPlatform,
  51. Max
  52. };
  53. explicit RCJobListModel(QObject* parent = 0);
  54. QModelIndex parent(const QModelIndex&) const override;
  55. QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
  56. int columnCount(const QModelIndex& parent = QModelIndex()) const override;
  57. int rowCount(const QModelIndex& parent = QModelIndex()) const override;
  58. QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
  59. QVariant data(const QModelIndex& index, int role) const override;
  60. void markAsProcessing(RCJob* rcJob);
  61. void markAsStarted(RCJob* rcJob);
  62. void markAsCompleted(RCJob* rcJob);
  63. void markAsCataloged(const AssetProcessor::QueueElementID& check);
  64. unsigned int jobsInFlight() const;
  65. // Returns how many jobs in the queue have the missing dependency flag set.
  66. unsigned int jobsInQueueWithoutMissingDependencies() const;
  67. // Returns how many finished jobs that haven't been updated in the catalog.
  68. unsigned int jobsPendingCatalog() const;
  69. void UpdateJobEscalation(const QueueElementID& toEscalate, int valueToEscalateTo);
  70. void UpdateJobEscalation(AssetProcessor::RCJob* rcJob, int valueToEscalateTo);
  71. void UpdateRow(int jobIndex);
  72. bool isEmpty();
  73. void addNewJob(RCJob* rcJob);
  74. bool isInFlight(const QueueElementID& check) const;
  75. bool isInQueue(const QueueElementID& check) const;
  76. bool isWaitingOnCatalog(const QueueElementID& check) const;
  77. void PerformHeuristicSearch(QString searchTerm, QString platform, QSet<QueueElementID>& found, AssetProcessor::JobIdEscalationList& escalationList, bool isStatusRequest, int searchRules = 0);
  78. void PerformUUIDSearch(AZ::Uuid searchUuid, QString platform, QSet<QueueElementID>& found, AssetProcessor::JobIdEscalationList& escalationList, bool isStatusRequest);
  79. int itemCount() const;
  80. RCJob* getItem(int index) const;
  81. int GetIndexOfJobByState(const QueueElementID& elementId, RCJob::JobState jobState);
  82. ///! EraseJobs expects the database name of the source file.
  83. void EraseJobs(const SourceAssetReference& sourceAssetReference, AZStd::vector<RCJob*>& pendingJobs);
  84. private:
  85. AZStd::vector<RCJob*> m_jobs;
  86. QSet<RCJob*> m_jobsInFlight;
  87. // Keeps track of jobs waiting on the APM thread to finish writing out to the catalog
  88. // This prevents job dependencies from starting before the dependent job is actually done
  89. // Since the jobs aren't uniquely identified, and the APM thread can fall behind, we keep track of how many have finished
  90. QHash<QueueElementID, int> m_finishedJobsNotInCatalog;
  91. // profiler showed much of our time was spent in IsInQueue.
  92. QMultiMap<QueueElementID, RCJob*> m_jobsInQueueLookup;
  93. };
  94. } // namespace AssetProcessor
  95. #endif // RCQUEUEMODEL_H