From ebbefc0151ffae360647cf2ee50a5b28c63bda80 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Mon, 8 Apr 2013 17:49:14 +0200 Subject: [PATCH] package daemon: Root: Use a common job for volume work Add VolumeJob which, besides the Volume, takes a Root method to be invoked. That allows to replace the specific job classes by simple methods. --- src/servers/package/Root.cpp | 81 +++++++++++++++--------------------- src/servers/package/Root.h | 10 ++--- 2 files changed, 38 insertions(+), 53 deletions(-) diff --git a/src/servers/package/Root.cpp b/src/servers/package/Root.cpp index f05dcc66cb..6c2f505531 100644 --- a/src/servers/package/Root.cpp +++ b/src/servers/package/Root.cpp @@ -16,63 +16,25 @@ #include "DebugSupport.h" -// #pragma mark - InitVolumePackagesJob +// #pragma mark - VolumeJob -struct Root::InitPackagesJob : public Job { - InitPackagesJob(Volume* volume) +struct Root::VolumeJob : public Job { + VolumeJob(Volume* volume, void (Root::*method)(Volume*)) : - fVolume(volume) + fVolume(volume), + fMethod(method) { } virtual void Do() { - fVolume->InitPackages(fVolume->GetRoot()); - } - -private: - Volume* fVolume; -}; - - -// #pragma mark - DeleteVolumeJob - - -struct Root::DeleteVolumeJob : public Job { - DeleteVolumeJob(Volume* volume) - : - fVolume(volume) - { - } - - virtual void Do() - { - delete fVolume; - } - -private: - Volume* fVolume; -}; - - -// #pragma mark - HandleNodeMonitorEventsJob - - -struct Root::HandleNodeMonitorEventsJob : public Job { - HandleNodeMonitorEventsJob(Volume* volume) - : - fVolume(volume) - { - } - - virtual void Do() - { - fVolume->ProcessPendingNodeMonitorEvents(); + (fVolume->GetRoot()->*fMethod)(fVolume); } private: Volume* fVolume; + void (Root::*fMethod)(Volume*); }; @@ -165,7 +127,8 @@ Root::RegisterVolume(Volume* volume) volume->SetRoot(this); // queue a job for reading the volume's packages - status_t error = _QueueJob(new(std::nothrow) InitPackagesJob(volume)); + status_t error = _QueueJob( + new(std::nothrow) VolumeJob(volume, &Root::_InitPackages)); if (error != B_OK) { volume->SetRoot(NULL); *volumeToSet = NULL; @@ -190,7 +153,7 @@ Root::UnregisterVolume(Volume* volume) // Use the job queue to delete the volume to make sure there aren't any // pending jobs that reference the volume. - _QueueJob(new(std::nothrow) DeleteVolumeJob(volume)); + _QueueJob(new(std::nothrow) VolumeJob(volume, &Root::_DeleteVolume)); } @@ -211,7 +174,8 @@ Root::FindVolume(dev_t deviceID) const void Root::VolumeNodeMonitorEventOccurred(Volume* volume) { - _QueueJob(new(std::nothrow) HandleNodeMonitorEventsJob(volume)); + _QueueJob( + new(std::nothrow) VolumeJob(volume, &Root::_ProcessNodeMonitorEvents)); } @@ -238,6 +202,27 @@ Root::_GetVolume(PackageFSMountType mountType) } +void +Root::_InitPackages(Volume* volume) +{ + volume->InitPackages(this); +} + + +void +Root::_DeleteVolume(Volume* volume) +{ + delete volume; +} + + +void +Root::_ProcessNodeMonitorEvents(Volume* volume) +{ + volume->ProcessPendingNodeMonitorEvents(); +} + + status_t Root::_QueueJob(Job* job) { diff --git a/src/servers/package/Root.h b/src/servers/package/Root.h index 2c7f328f08..b2afd2c6e9 100644 --- a/src/servers/package/Root.h +++ b/src/servers/package/Root.h @@ -48,15 +48,15 @@ protected: virtual void LastReferenceReleased(); private: - struct InitPackagesJob; - struct DeleteVolumeJob; - struct HandleNodeMonitorEventsJob; - - friend struct InitPackagesJob; + struct VolumeJob; private: Volume** _GetVolume(PackageFSMountType mountType); + void _InitPackages(Volume* volume); + void _DeleteVolume(Volume* volume); + void _ProcessNodeMonitorEvents(Volume* volume); + status_t _QueueJob(Job* job); static status_t _JobRunnerEntry(void* data);