1 /* 2 * Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #include "DiskDeviceJobQueue.h" 7 8 #include <stdio.h> 9 10 #include <typeinfo> 11 12 #include "DiskDeviceJob.h" 13 14 15 #undef TRACE 16 //#define TRACE(x...) 17 #define TRACE(x...) printf(x) 18 19 20 // constructor 21 DiskDeviceJobQueue::DiskDeviceJobQueue() 22 : fJobs(20, true) 23 { 24 } 25 26 27 // destructor 28 DiskDeviceJobQueue::~DiskDeviceJobQueue() 29 { 30 } 31 32 33 // AddJob 34 status_t 35 DiskDeviceJobQueue::AddJob(DiskDeviceJob* job) 36 { 37 if (!job) 38 return B_BAD_VALUE; 39 40 return fJobs.AddItem(job) ? B_OK : B_NO_MEMORY; 41 } 42 43 44 // Execute 45 status_t 46 DiskDeviceJobQueue::Execute() 47 { 48 int32 count = fJobs.CountItems(); 49 for (int32 i = 0; i < count; i++) { 50 DiskDeviceJob* job = fJobs.ItemAt(i); 51 52 TRACE("DiskDeviceJobQueue::Execute(): executing job: %s\n", 53 typeid(*job).name()); 54 55 status_t error = job->Do(); 56 if (error != B_OK) { 57 TRACE("DiskDeviceJobQueue::Execute(): executing job failed\n"); 58 return error; 59 } 60 } 61 62 return B_OK; 63 } 64