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.
This commit is contained in:
Ingo Weinhold 2013-04-08 17:49:14 +02:00
parent 2508cd615f
commit ebbefc0151
2 changed files with 38 additions and 53 deletions

View File

@ -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)
{

View File

@ -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);