From 6f07fead0c0ea5dc4527db02d985735f76e65de0 Mon Sep 17 00:00:00 2001 From: Andrew Lindesay Date: Sun, 7 Feb 2021 13:42:52 +1300 Subject: [PATCH] HaikuDepot: Remove Custom List Further removal of the use of custom list class; this time with the package action lists. Also resolve an error created by a last minute change in the last pull request for this ticket. Relates To #15534 Change-Id: I85dd40b7ef664f93b24ca5041fa58cca17d72299 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3735 Reviewed-by: Adrien Destugues --- src/apps/haikudepot/model/PackageAction.h | 2 +- .../haikudepot/model/PackageActionHandler.h | 5 +++-- src/apps/haikudepot/ui/MainWindow.cpp | 18 +++++++----------- src/apps/haikudepot/ui/MainWindow.h | 8 ++++---- src/apps/haikudepot/ui/PackageInfoView.cpp | 7 ++----- 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/apps/haikudepot/model/PackageAction.h b/src/apps/haikudepot/model/PackageAction.h index c549fba7e6..f04077ad4e 100644 --- a/src/apps/haikudepot/model/PackageAction.h +++ b/src/apps/haikudepot/model/PackageAction.h @@ -1,6 +1,7 @@ /* * Copyright 2013, Stephan Aßmus . * Copyright 2013, Rene Gollent, + * Copyright 2021, Andrew Lindesay * * All rights reserved. Distributed under the terms of the MIT License. */ @@ -64,7 +65,6 @@ private: typedef BReference PackageActionRef; -typedef List PackageActionList; #endif // PACKAGE_ACTION_H diff --git a/src/apps/haikudepot/model/PackageActionHandler.h b/src/apps/haikudepot/model/PackageActionHandler.h index f8b996e9b8..f15e68c03a 100644 --- a/src/apps/haikudepot/model/PackageActionHandler.h +++ b/src/apps/haikudepot/model/PackageActionHandler.h @@ -1,5 +1,6 @@ /* * Copyright 2013, Rene Gollent . + * Copyright 2021, Andrew Lindesay . * All rights reserved. Distributed under the terms of the MIT License. */ @@ -19,8 +20,8 @@ class PackageActionHandler { public: virtual ~PackageActionHandler(); - virtual status_t SchedulePackageActions( - PackageActionList& list) = 0; + virtual status_t SchedulePackageAction( + PackageActionRef action) = 0; virtual Model* GetModel() = 0; }; diff --git a/src/apps/haikudepot/ui/MainWindow.cpp b/src/apps/haikudepot/ui/MainWindow.cpp index 72de375fdd..1ffa9cb608 100644 --- a/src/apps/haikudepot/ui/MainWindow.cpp +++ b/src/apps/haikudepot/ui/MainWindow.cpp @@ -429,7 +429,7 @@ MainWindow::MessageReceived(BMessage* message) BAutolock locker(fModel.Lock()); package = fModel.PackageForName(name); } - if (package.IsSet() || name != package->Name()) + if (!package.IsSet() || name != package->Name()) debugger("unable to find the named package"); else _AdoptPackage(package); @@ -605,15 +605,11 @@ MainWindow::PackageChanged(const PackageInfoEvent& event) status_t -MainWindow::SchedulePackageActions(PackageActionList& list) +MainWindow::SchedulePackageAction(PackageActionRef action) { AutoLocker lock(&fPendingActionsLock); - for (int32 i = 0; i < list.CountItems(); i++) { - if (!fPendingActions.Add(list.ItemAtFast(i))) - return B_NO_MEMORY; - } - - return release_sem_etc(fPendingActionsSem, list.CountItems(), 0); + fPendingActions.push(action); + return release_sem_etc(fPendingActionsSem, 1, 0); } @@ -989,7 +985,7 @@ MainWindow::_HandleWorkStatusChangeMessageReceived(const BMessage* message) } -status_t +/*static*/ status_t MainWindow::_PackageActionWorker(void* arg) { MainWindow* window = reinterpret_cast(arg); @@ -998,10 +994,10 @@ MainWindow::_PackageActionWorker(void* arg) PackageActionRef ref; { AutoLocker lock(&window->fPendingActionsLock); - ref = window->fPendingActions.ItemAt(0); + ref = window->fPendingActions.front(); + window->fPendingActions.pop(); if (!ref.IsSet()) break; - window->fPendingActions.Remove(0); } BMessenger messenger(window); diff --git a/src/apps/haikudepot/ui/MainWindow.h b/src/apps/haikudepot/ui/MainWindow.h index e86c825385..b50d4d6eb2 100644 --- a/src/apps/haikudepot/ui/MainWindow.h +++ b/src/apps/haikudepot/ui/MainWindow.h @@ -2,7 +2,7 @@ * Copyright 2013-2014, Stephan Aßmus . * Copyright 2013, Rene Gollent . * Copyright 2017, Julian Harnath . - * Copyright 2017-2020, Andrew Lindesay . + * Copyright 2017-2021, Andrew Lindesay . * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef MAIN_WINDOW_H @@ -66,8 +66,7 @@ private: private: // PackageActionHandler - virtual status_t SchedulePackageActions( - PackageActionList& list); + virtual status_t SchedulePackageAction(PackageActionRef action); virtual Model* GetModel(); private: @@ -168,7 +167,8 @@ private: bool fSinglePackageMode; thread_id fPendingActionsWorker; - PackageActionList fPendingActions; + std::queue + fPendingActions; BLocker fPendingActionsLock; sem_id fPendingActionsSem; diff --git a/src/apps/haikudepot/ui/PackageInfoView.cpp b/src/apps/haikudepot/ui/PackageInfoView.cpp index 0f22a54116..a7fe408625 100644 --- a/src/apps/haikudepot/ui/PackageInfoView.cpp +++ b/src/apps/haikudepot/ui/PackageInfoView.cpp @@ -1,6 +1,6 @@ /* * Copyright 2013-2014, Stephan Aßmus . - * Copyright 2018-2020, Andrew Lindesay . + * Copyright 2018-2021, Andrew Lindesay . * All rights reserved. Distributed under the terms of the MIT License. */ @@ -638,10 +638,7 @@ private: if (!action.IsSet()) return; - PackageActionList actions; - actions.Add(action); - status_t result - = fPackageActionHandler->SchedulePackageActions(actions); + status_t result = fPackageActionHandler->SchedulePackageAction(action); if (result != B_OK) { HDERROR("Failed to schedule action: %s '%s': %s",