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