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:
@@ -16,63 +16,25 @@
|
|||||||
#include "DebugSupport.h"
|
#include "DebugSupport.h"
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - InitVolumePackagesJob
|
// #pragma mark - VolumeJob
|
||||||
|
|
||||||
|
|
||||||
struct Root::InitPackagesJob : public Job {
|
struct Root::VolumeJob : public Job {
|
||||||
InitPackagesJob(Volume* volume)
|
VolumeJob(Volume* volume, void (Root::*method)(Volume*))
|
||||||
:
|
:
|
||||||
fVolume(volume)
|
fVolume(volume),
|
||||||
|
fMethod(method)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Do()
|
virtual void Do()
|
||||||
{
|
{
|
||||||
fVolume->InitPackages(fVolume->GetRoot());
|
(fVolume->GetRoot()->*fMethod)(fVolume);
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Volume* fVolume;
|
Volume* fVolume;
|
||||||
|
void (Root::*fMethod)(Volume*);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -165,7 +127,8 @@ Root::RegisterVolume(Volume* volume)
|
|||||||
volume->SetRoot(this);
|
volume->SetRoot(this);
|
||||||
|
|
||||||
// queue a job for reading the volume's packages
|
// 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) {
|
if (error != B_OK) {
|
||||||
volume->SetRoot(NULL);
|
volume->SetRoot(NULL);
|
||||||
*volumeToSet = 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
|
// Use the job queue to delete the volume to make sure there aren't any
|
||||||
// pending jobs that reference the volume.
|
// 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
|
void
|
||||||
Root::VolumeNodeMonitorEventOccurred(Volume* volume)
|
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
|
status_t
|
||||||
Root::_QueueJob(Job* job)
|
Root::_QueueJob(Job* job)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -48,15 +48,15 @@ protected:
|
|||||||
virtual void LastReferenceReleased();
|
virtual void LastReferenceReleased();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct InitPackagesJob;
|
struct VolumeJob;
|
||||||
struct DeleteVolumeJob;
|
|
||||||
struct HandleNodeMonitorEventsJob;
|
|
||||||
|
|
||||||
friend struct InitPackagesJob;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Volume** _GetVolume(PackageFSMountType mountType);
|
Volume** _GetVolume(PackageFSMountType mountType);
|
||||||
|
|
||||||
|
void _InitPackages(Volume* volume);
|
||||||
|
void _DeleteVolume(Volume* volume);
|
||||||
|
void _ProcessNodeMonitorEvents(Volume* volume);
|
||||||
|
|
||||||
status_t _QueueJob(Job* job);
|
status_t _QueueJob(Job* job);
|
||||||
|
|
||||||
static status_t _JobRunnerEntry(void* data);
|
static status_t _JobRunnerEntry(void* data);
|
||||||
|
|||||||
Reference in New Issue
Block a user