* Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#include "DiskDeviceJobQueue.h"
#include <stdio.h>
#include <string.h>
#include <typeinfo>
#include "DiskDeviceJob.h"
#undef TRACE
#define TRACE(x...) printf(x)
DiskDeviceJobQueue::DiskDeviceJobQueue()
: fJobs(20)
{
}
DiskDeviceJobQueue::~DiskDeviceJobQueue()
{
}
status_t
DiskDeviceJobQueue::AddJob(DiskDeviceJob* job)
{
if (!job)
return B_BAD_VALUE;
return fJobs.AddItem(job) ? B_OK : B_NO_MEMORY;
}
status_t
DiskDeviceJobQueue::Execute()
{
int32 count = fJobs.CountItems();
for (int32 i = 0; i < count; i++) {
DiskDeviceJob* job = fJobs.ItemAt(i);
TRACE("DiskDeviceJobQueue::Execute(): executing job: %s\n",
typeid(*job).name());
status_t error = job->Do();
if (error != B_OK) {
TRACE("DiskDeviceJobQueue::Execute(): executing job failed: %s\n",
strerror(error));
return error;
}
}
return B_OK;
}