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 #include <string.h> 10 11 #include <typeinfo> 12 13 #include "DiskDeviceJob.h" 14 15 16 #undef TRACE 17 //#define TRACE(x...) 18 #define TRACE(x...) printf(x) 19 20 21 // constructor 22 DiskDeviceJobQueue::DiskDeviceJobQueue() 23 : fJobs(20, true) 24 { 25 } 26 27 28 // destructor 29 DiskDeviceJobQueue::~DiskDeviceJobQueue() 30 { 31 } 32 33 34 // AddJob 35 status_t 36 DiskDeviceJobQueue::AddJob(DiskDeviceJob* job) 37 { 38 if (!job) 39 return B_BAD_VALUE; 40 41 return fJobs.AddItem(job) ? B_OK : B_NO_MEMORY; 42 } 43 44 45 // Execute 46 status_t 47 DiskDeviceJobQueue::Execute() 48 { 49 int32 count = fJobs.CountItems(); 50 for (int32 i = 0; i < count; i++) { 51 DiskDeviceJob* job = fJobs.ItemAt(i); 52 53 TRACE("DiskDeviceJobQueue::Execute(): executing job: %s\n", 54 typeid(*job).name()); 55 56 status_t error = job->Do(); 57 if (error != B_OK) { 58 TRACE("DiskDeviceJobQueue::Execute(): executing job failed: %s\n", 59 strerror(error)); 60 return error; 61 } 62 } 63 64 return B_OK; 65 } 66