- Timestamp:
- Apr 25, 2019 5:11:49 PM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/medium
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumEnumerator.cpp
r78298 r78299 32 32 33 33 34 /** Template function to convert a list of 35 * abstract objects to a human readable string list. 36 * @note T should have .toString() member implemented. */ 34 37 template<class T> static QStringList toStringList(const QList<T> &list) 35 38 { … … 41 44 42 45 43 /** UITask extension used for medium enumeration purposes. */ 46 /** UITask extension used for medium-enumeration purposes. 47 * @note Indeed property/setProperty API isn't thread-safe stuff. 48 * This isn't dangerous for us since setter/getter API calls 49 * are splitted in time by enumerator's logic, but latest Qt 50 * versions prohibits property/setProperty API usage from 51 * other than the GUI thread anyway so we will have to rework 52 * that stuff to be thread-safe one day at least for Qt >= 5.11. */ 44 53 class UITaskMediumEnumeration : public UITask 45 54 { … … 48 57 public: 49 58 50 /** Constructs @a medium 59 /** Constructs @a medium-enumeration task. */ 51 60 UITaskMediumEnumeration(const UIMedium &medium) 52 61 : UITask(UITask::Type_MediumEnumeration) 53 62 { 54 63 /* Store medium as property: */ 64 /// @todo rework to thread-safe stuff one day 55 65 setProperty("medium", QVariant::fromValue(medium)); 56 66 } … … 58 68 private: 59 69 60 /** Contains medium 70 /** Contains medium-enumeration task body. */ 61 71 virtual void run() /* override */ 62 72 { 63 73 /* Get medium: */ 74 /// @todo rework to thread-safe stuff one day 64 75 UIMedium guiMedium = property("medium").value<UIMedium>(); 65 76 /* Enumerate it: */ … … 70 81 }; 71 82 83 84 /********************************************************************************************************************************* 85 * Class UIMediumEnumerator implementation. * 86 *********************************************************************************************************************************/ 72 87 73 88 UIMediumEnumerator::UIMediumEnumerator() … … 91 106 this, &UIMediumEnumerator::sltHandleMachineRegistration); 92 107 93 /* Listen for global thread-pool: */108 /* Prepare global thread-pool listener: */ 94 109 connect(vboxGlobal().threadPool(), &UIThreadPool::sigTaskComplete, 95 110 this, &UIMediumEnumerator::sltHandleMediumEnumerationTaskComplete); … … 98 113 QList<QUuid> UIMediumEnumerator::mediumIDs() const 99 114 { 100 /* Return keys of current medi um-map: */115 /* Return keys of current media map: */ 101 116 return m_media.keys(); 102 117 } … … 104 119 UIMedium UIMediumEnumerator::medium(const QUuid &uMediumID) const 105 120 { 106 /* Search through current medium-map for the medium with passed ID: */ 121 /* Search through current media map 122 * for the UIMedium with passed ID: */ 107 123 if (m_media.contains(uMediumID)) 108 124 return m_media.value(uMediumID); 109 /* Return NULL medium otherwise: */125 /* Return NULL UIMedium otherwise: */ 110 126 return UIMedium(); 111 127 } … … 113 129 void UIMediumEnumerator::createMedium(const UIMedium &guiMedium) 114 130 { 115 /* Get medium ID: */131 /* Get UIMedium ID: */ 116 132 const QUuid uMediumID = guiMedium.id(); 117 133 118 134 /* Do not create UIMedium(s) with incorrect ID: */ 119 135 AssertReturnVoid(!uMediumID.isNull()); 120 /* Make sure medium doesn't existsalready: */136 /* Make sure UIMedium doesn't exist already: */ 121 137 AssertReturnVoid(!m_media.contains(uMediumID)); 122 138 123 /* Insert medium: */139 /* Insert UIMedium: */ 124 140 m_media[uMediumID] = guiMedium; 125 141 LogRel(("GUI: UIMediumEnumerator: Medium with key={%s} created\n", uMediumID.toString().toUtf8().constData())); … … 133 149 /* Do not delete UIMedium(s) with incorrect ID: */ 134 150 AssertReturnVoid(!uMediumID.isNull()); 135 /* Make sure medium still exists: */151 /* Make sure UIMedium still exists: */ 136 152 AssertReturnVoid(m_media.contains(uMediumID)); 137 153 138 /* Remove medium: */154 /* Remove UIMedium: */ 139 155 m_media.remove(uMediumID); 140 156 LogRel(("GUI: UIMediumEnumerator: Medium with key={%s} deleted\n", uMediumID.toString().toUtf8().constData())); … … 149 165 AssertReturnVoid(!m_fMediumEnumerationInProgress); 150 166 151 /* Compose new map of all currently knownmedia & their children.152 * While composing we are using data from already existingmedia. */167 /* Compose new map of currently cached media & their children. 168 * While composing we are using data from already cached media. */ 153 169 UIMediumMap media; 154 170 addNullMediumToMap(media); 155 /* If @p mediaList is empty we start the media enumeration with all known media: */ 171 /* If @p inputMedia is empty we start the media enumeration with all 172 * known hard disk media. Otherwise only passed inputMedia will be 173 * enumerated. But be aware we will enumerate all the optical/floppy 174 * media in any case to make them listed within the first run wizard 175 * for now. But I think later we can add proper enumeration call to 176 * the wizard instead and enumerate only inputMedia in 'else' case. */ 156 177 if (inputMedia.isEmpty()) 157 178 { … … 168 189 addMediaToMap(inputMedia, media); 169 190 } 191 192 /* VBoxGlobal is cleaning up, abort immediately: */ 170 193 if (VBoxGlobal::isCleaningUp()) 171 return; /* VBoxGlobal is cleaning up, abort immediately. */ 194 return; 195 196 /* Remember new media map: */ 172 197 m_media = media; 173 198 … … 177 202 emit sigMediumEnumerationStarted(); 178 203 179 /* Make sure we really have more than one medium (which is Null): */204 /* Make sure we really have more than one UIMedium (which is NULL): */ 180 205 if (m_media.size() == 1) 181 206 { … … 186 211 } 187 212 188 /* Start enumeration for UIMedium(s) with correctID: */213 /* Start enumeration for media with non-NULL ID: */ 189 214 foreach (const QUuid &uMediumID, m_media.keys()) 190 215 if (!uMediumID.isNull()) … … 197 222 AssertReturnVoid(!m_fMediumEnumerationInProgress); 198 223 199 /* Refresh all knownmedia we have: */224 /* Refresh all cached media we have: */ 200 225 foreach (const QUuid &uMediumID, m_media.keys()) 201 226 m_media[uMediumID].refresh(); … … 337 362 if (uMediumID == UIMedium::nullID()) 338 363 { 339 /* Delete this medium: */364 /* Delete this UIMedium: */ 340 365 m_media.remove(uMediumKey); 341 366 LogRel2(("GUI: UIMediumEnumerator: Medium with key={%s} closed and deleted (after enumeration)\n", … … 348 373 else if (uMediumID != uMediumKey) 349 374 { 350 /* We have to reinject enumerated medium: */375 /* We have to reinject enumerated UIMedium: */ 351 376 m_media.remove(uMediumKey); 352 377 m_media[uMediumID] = guiMedium; … … 363 388 else 364 389 { 365 /* Just update enumerated medium: */390 /* Just update enumerated UIMedium: */ 366 391 m_media[uMediumID] = guiMedium; 367 392 LogRel2(("GUI: UIMediumEnumerator: Medium with key={%s} updated\n", … … 394 419 void UIMediumEnumerator::addNullMediumToMap(UIMediumMap &media) 395 420 { 396 /* Insert NULL uimedium to the passed uimediummap.421 /* Insert NULL UIMedium to the passed media map. 397 422 * Get existing one from the previous map if any. */ 398 423 const UIMedium guiMedium = m_media.contains(UIMedium::nullID()) … … 404 429 void UIMediumEnumerator::addMediaToMap(const CMediumVector &inputMedia, UIMediumMap &outputMedia) 405 430 { 406 /* Insert hard-disks to the passed uimedium map. 407 * Get existing one from the previous map if any. */ 431 /* Iterate through passed inputMedia vector: */ 408 432 foreach (const CMedium &comMedium, inputMedia) 409 433 { … … 412 436 break; 413 437 414 /* Prepare uimedium on the basis of current medium: */ 438 /* Insert UIMedium to the passed media map. 439 * Get existing one from the previous map if any. 440 * Create on the basis of comMedium otherwise. */ 415 441 const QUuid uMediumID = comMedium.GetId(); 416 442 const UIMedium guiMedium = m_media.contains(uMediumID) 417 443 ? m_media.value(uMediumID) 418 444 : UIMedium(comMedium, UIMediumDefs::mediumTypeToLocal(comMedium.GetDeviceType())); 419 /* Insert uimedium into map: */420 445 outputMedia.insert(guiMedium.id(), guiMedium); 421 446 422 /* Insert medium children into map too: */447 /* Insert comMedium children into map as well: */ 423 448 addMediaToMap(comMedium.GetChildren(), outputMedia); 424 449 } 425 450 } 426 451 427 /**428 * Calculates last known UIMedium <i>usage</i> based on cached data.429 * @param uMachineID describes the machine we are calculating <i>usage</i> for.430 * @param previousUIMediumIDs receives UIMedium IDs used in cached data.431 * @param fTakeIntoAccountCurrentStateOnly defines whether we should take into accound current VM state only.432 */433 452 void UIMediumEnumerator::calculateCachedUsage(const QUuid &uMachineID, 434 453 QList<QUuid> &previousUIMediumIDs, 435 454 const bool fTakeIntoAccountCurrentStateOnly) const 436 455 { 437 /* For each the UIMedium ID cache have: */456 /* For each the cached UIMedium we have: */ 438 457 foreach (const QUuid &uUIMediumID, mediumIDs()) 439 458 { … … 451 470 } 452 471 453 /**454 * Calculates new CMedium <i>usage</i> based on actual data.455 * @param uMachineID describes the machine we are calculating <i>usage</i> for.456 * @param currentCMediums receives CMedium used in actual data.457 * @param currentCMediumIDs receives CMedium IDs used in actual data.458 * @param fTakeIntoAccountCurrentStateOnly defines whether we should take into accound current VM state only.459 */460 472 void UIMediumEnumerator::calculateActualUsage(const QUuid &uMachineID, 461 473 CMediumMap ¤tCMediums, … … 479 491 } 480 492 481 /**482 * Calculates new CMedium <i>usage</i> based on actual data.483 * @param snapshot is reference we are calculating <i>usage</i> for.484 * @param currentCMediums receives CMedium used in actual data.485 * @param currentCMediumIDs receives CMedium IDs used in actual data.486 */487 493 void UIMediumEnumerator::calculateActualUsage(const CSnapshot &comSnapshot, 488 494 CMediumMap ¤tCMediums, … … 501 507 } 502 508 503 /**504 * Calculates new CMedium <i>usage</i> based on actual data.505 * @param machine is reference we are calculating <i>usage</i> for.506 * @param currentCMediums receives CMedium used in actual data.507 * @param currentCMediumIDs receives CMedium IDs used in actual data.508 */509 509 void UIMediumEnumerator::calculateActualUsage(const CMachine &comMachine, 510 510 CMediumMap ¤tCMediums, … … 533 533 } 534 534 535 /**536 * Updates cache using known changes in cached data.537 * @param previousUIMediumIDs reflects UIMedium IDs used in cached data.538 */539 535 void UIMediumEnumerator::recacheFromCachedUsage(const QList<QUuid> &previousUIMediumIDs) 540 536 { … … 572 568 } 573 569 574 /**575 * Updates cache using known changes in actual data.576 * @param currentCMediums reflects CMedium used in actual data.577 * @param currentCMediumIDs reflects CMedium IDs used in actual data.578 */579 570 void UIMediumEnumerator::recacheFromActualUsage(const CMediumMap ¤tCMediums, 580 571 const QList<QUuid> ¤tCMediumIDs) -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumEnumerator.h
r78298 r78299 35 35 class UIThreadPool; 36 36 37 /* Typedefs:*/37 /** A map of CMedium objects ordered by their IDs. */ 38 38 typedef QMap<QUuid, CMedium> CMediumMap; 39 39 40 /* Medium-enumerator prototype. 41 * Manages access to medium information using thread-pool interface. */ 40 /** QObject extension operating as medium-enumeration object. 41 * Manages access to cached UIMedium information via public API. 42 * Updates cache on corresponding Main events using thread-pool interface. */ 42 43 class SHARED_LIBRARY_STUFF UIMediumEnumerator : public QIWithRetranslateUI3<QObject> 43 44 { … … 46 47 signals: 47 48 48 /* Notifiers: Medium-operations stuff:*/49 /** Notifies listeners about UIMedium with @a uMediumID created. */ 49 50 void sigMediumCreated(const QUuid &uMediumID); 51 /** Notifies listeners about UIMedium with @a uMediumID deleted. */ 50 52 void sigMediumDeleted(const QUuid &uMediumID); 51 53 52 /* Notifiers: Medium-enumeration stuff:*/54 /** Notifies listeners about consolidated medium-enumeration process has started. */ 53 55 void sigMediumEnumerationStarted(); 56 /** Notifies listeners about UIMedium with @a uMediumID updated. */ 54 57 void sigMediumEnumerated(const QUuid &uMediumID); 58 /** Notifies listeners about consolidated medium-enumeration process has finished. */ 55 59 void sigMediumEnumerationFinished(); 56 60 … … 60 64 UIMediumEnumerator(); 61 65 62 /* API: Medium-access stuff:*/66 /** Returns cached UIMedium ID list. */ 63 67 QList<QUuid> mediumIDs() const; 68 /** Returns a wrapper of cached UIMedium with specified @a uMediumID. */ 64 69 UIMedium medium(const QUuid &uMediumID) const; 70 71 /** Creates UIMedium thus caching it internally on the basis of passed @a guiMedium information. */ 65 72 void createMedium(const UIMedium &guiMedium); 73 /** Deletes UIMedium with specified @a uMediumID thus removing it from internal cache. */ 66 74 void deleteMedium(const QUuid &uMediumID); 67 75 68 /* API: Medium-enumeration stuff:*/76 /** Returns whether consolidated medium-enumeration process is in progress. */ 69 77 bool isMediumEnumerationInProgress() const { return m_fMediumEnumerationInProgress; } 78 /** Makes a request to enumerate specified @a inputMedia. 79 * @note Empty list means that full/overall medium-enumeration is requested. */ 70 80 void enumerateMedia(const CMediumVector &inputMedia = CMediumVector()); 81 /** Refresh all the lightweight UIMedium information for all the cached UIMedium(s). 82 * @note Please note that this is a lightweight version, which doesn't perform 83 * heavy state/accessibility checks thus doesn't require to be performed 84 * by a worker COM-aware thread. */ 71 85 void refreshMedia(); 72 86 … … 78 92 private slots: 79 93 80 /** Handles machine-data-change and snapshot-change events . */94 /** Handles machine-data-change and snapshot-change events for a machine with specified @a uMachineID. */ 81 95 void sltHandleMachineUpdate(const QUuid &uMachineID); 82 /** Handles machine-[un]registration events. */ 96 /** Handles machine-[un]registration events for a machine with specified @a uMachineID. 97 * @param fRegistered Specifies whether the machine was registered or unregistered otherwise. */ 83 98 void sltHandleMachineRegistration(const QUuid &uMachineID, const bool fRegistered); 84 /** Handles snapshot-deleted events . */99 /** Handles snapshot-deleted events for a machine with specified @a uMachineID and a snapshot with specified @a uSnapshotID. */ 85 100 void sltHandleSnapshotDeleted(const QUuid &uMachineID, const QUuid &uSnapshotID); 86 101 87 /* Handler: Medium-enumeration stuff:*/102 /** Handles medium-enumeration @a pTask complete signal. */ 88 103 void sltHandleMediumEnumerationTaskComplete(UITask *pTask); 89 104 90 105 private: 91 106 92 /* Helpers: Medium-enumeration stuff:*/107 /** Creates medium-enumeration task for certain @a guiMedium. */ 93 108 void createMediumEnumerationTask(const UIMedium &guiMedium); 109 /** Adds NULL UIMedium to specified @a outputMedia map. */ 94 110 void addNullMediumToMap(UIMediumMap &outputMedia); 111 /** Adds @a inputMedia to specified @a outputMedia map. */ 95 112 void addMediaToMap(const CMediumVector &inputMedia, UIMediumMap &outputMedia); 96 113 97 /* Helpers: Medium re-caching stuff: */ 114 /** Updates usage for machine with specified @a uMachineID on the basis of cached data. 115 * @param previousUIMediumIDs Brings UIMedium IDs used in cached data. 116 * @param fTakeIntoAccountCurrentStateOnly Brings whether we should take into accound current VM state only. */ 98 117 void calculateCachedUsage(const QUuid &uMachineID, 99 118 QList<QUuid> &previousUIMediumIDs, 100 119 const bool fTakeIntoAccountCurrentStateOnly) const; 120 /** Updates usage for machine with specified @a uMachineID on the basis of actual data. 121 * @param currentCMediums Brings CMedium used in actual data. 122 * @param currentCMediumIDs Brings CMedium IDs used in actual data. 123 * @param fTakeIntoAccountCurrentStateOnly Brings whether we should take into accound current VM state only. */ 101 124 void calculateActualUsage(const QUuid &uMachineID, 102 125 CMediumMap ¤tCMediums, 103 126 QList<QUuid> ¤tCMediumIDs, 104 127 const bool fTakeIntoAccountCurrentStateOnly) const; 128 /** Updates usage for machine specified by its @a comSnapshot reference on the basis of actual data. 129 * @param currentCMediums Brings CMedium used in actual data. 130 * @param currentCMediumIDs Brings CMedium IDs used in actual data. */ 105 131 void calculateActualUsage(const CSnapshot &comSnapshot, 106 132 CMediumMap ¤tCMediums, 107 133 QList<QUuid> ¤tCMediumIDs) const; 134 /** Updates usage for machine specified by own @a comMachine reference on the basis of actual data. 135 * @param currentCMediums Brings CMedium used in actual data. 136 * @param currentCMediumIDs Brings CMedium IDs used in actual data. */ 108 137 void calculateActualUsage(const CMachine &comMachine, 109 138 CMediumMap ¤tCMediums, 110 139 QList<QUuid> ¤tCMediumIDs) const; 140 141 /** Updates cache using known changes in cached data. 142 * @param previousUIMediumIDs Brings UIMedium IDs used in cached data. */ 111 143 void recacheFromCachedUsage(const QList<QUuid> &previousUIMediumIDs); 144 /** Updates cache using known changes in actual data. 145 * @param currentCMediums Brings CMedium used in actual data. 146 * @param currentCMediumIDs Brings CMedium IDs used in actual data. */ 112 147 void recacheFromActualUsage(const CMediumMap ¤tCMediums, 113 148 const QList<QUuid> ¤tCMediumIDs); 114 149 115 /* Variables:*/150 /** Holds whether consolidated medium-enumeration process is in progress. */ 116 151 bool m_fMediumEnumerationInProgress; 152 153 /** Holds a set of current medium-enumeration tasks. */ 117 154 QSet<UITask*> m_tasks; 155 156 /** Holds a map of current cached (enumerated) media. */ 118 157 UIMediumMap m_media; 119 158 };
Note:
See TracChangeset
for help on using the changeset viewer.