Implemented BDiskDeviceJob. Should be complete.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4141 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -9,15 +9,24 @@
|
|||||||
#include <DiskDeviceDefs.h>
|
#include <DiskDeviceDefs.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
|
struct user_disk_device_job_info;
|
||||||
|
|
||||||
class BDiskDeviceJob {
|
class BDiskDeviceJob {
|
||||||
public:
|
public:
|
||||||
disk_job_id ID() const;
|
BDiskDeviceJob();
|
||||||
uint32 Type() const;
|
~BDiskDeviceJob();
|
||||||
partition_id PartitionID() const;
|
|
||||||
|
|
||||||
float Progress() const; // [0.0, 1.0]
|
status_t SetTo(disk_job_id id);
|
||||||
uint32 Status() const;
|
void Unset();
|
||||||
|
status_t InitCheck() const;
|
||||||
|
|
||||||
|
disk_job_id ID() const;
|
||||||
|
uint32 Type() const;
|
||||||
|
partition_id PartitionID() const;
|
||||||
const char *Description() const;
|
const char *Description() const;
|
||||||
|
|
||||||
|
uint32 Status() const;
|
||||||
|
float Progress() const; // [0.0, 1.0]
|
||||||
status_t GetProgressInfo(disk_device_job_progress_info *info) const;
|
status_t GetProgressInfo(disk_device_job_progress_info *info) const;
|
||||||
uint32 InterruptProperties() const;
|
uint32 InterruptProperties() const;
|
||||||
|
|
||||||
@@ -25,7 +34,11 @@ public:
|
|||||||
status_t Pause();
|
status_t Pause();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
disk_job_id fJobID;
|
status_t _SetTo(user_disk_device_job_info *info);
|
||||||
|
|
||||||
|
friend class BDiskDeviceRoster;
|
||||||
|
|
||||||
|
disk_job_id fID;
|
||||||
uint32 fType;
|
uint32 fType;
|
||||||
partition_id fPartitionID;
|
partition_id fPartitionID;
|
||||||
BString fDescription;
|
BString fDescription;
|
||||||
|
|||||||
@@ -3,4 +3,164 @@
|
|||||||
// by the OpenBeOS license.
|
// by the OpenBeOS license.
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <ddm_userland_interface.h>
|
||||||
#include <DiskDeviceJob.h>
|
#include <DiskDeviceJob.h>
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
BDiskDeviceJob::BDiskDeviceJob()
|
||||||
|
: fID(B_NO_INIT),
|
||||||
|
fType(B_DISK_DEVICE_JOB_BAD_TYPE),
|
||||||
|
fPartitionID(-1),
|
||||||
|
fDescription()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// destructor
|
||||||
|
BDiskDeviceJob::~BDiskDeviceJob()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// InitCheck
|
||||||
|
status_t
|
||||||
|
BDiskDeviceJob::InitCheck() const
|
||||||
|
{
|
||||||
|
return (fID >= 0 ? B_OK : fID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTo
|
||||||
|
status_t
|
||||||
|
BDiskDeviceJob::SetTo(disk_job_id id)
|
||||||
|
{
|
||||||
|
Unset();
|
||||||
|
user_disk_device_job_info info;
|
||||||
|
status_t error = _kern_get_disk_device_job_info(id, &info);
|
||||||
|
if (error != B_OK)
|
||||||
|
return error;
|
||||||
|
return _SetTo(&info);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unset
|
||||||
|
void
|
||||||
|
BDiskDeviceJob::Unset()
|
||||||
|
{
|
||||||
|
fID = B_NO_INIT;
|
||||||
|
fType = B_DISK_DEVICE_JOB_BAD_TYPE;
|
||||||
|
fPartitionID = -1;
|
||||||
|
fDescription.SetTo(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ID
|
||||||
|
disk_job_id
|
||||||
|
BDiskDeviceJob::ID() const
|
||||||
|
{
|
||||||
|
return fID;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type
|
||||||
|
uint32
|
||||||
|
BDiskDeviceJob::Type() const
|
||||||
|
{
|
||||||
|
return fType;
|
||||||
|
}
|
||||||
|
|
||||||
|
// PartitionID
|
||||||
|
partition_id
|
||||||
|
BDiskDeviceJob::PartitionID() const
|
||||||
|
{
|
||||||
|
return fPartitionID;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Description
|
||||||
|
const char *
|
||||||
|
BDiskDeviceJob::Description() const
|
||||||
|
{
|
||||||
|
return fDescription.String();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Status
|
||||||
|
uint32
|
||||||
|
BDiskDeviceJob::Status() const
|
||||||
|
{
|
||||||
|
if (InitCheck() != B_OK)
|
||||||
|
return B_DISK_DEVICE_JOB_UNINITIALIZED;
|
||||||
|
disk_device_job_progress_info info;
|
||||||
|
status_t error = _kern_get_disk_device_job_progress_info(fID, &info);
|
||||||
|
if (error != B_OK)
|
||||||
|
return B_DISK_DEVICE_JOB_UNINITIALIZED;
|
||||||
|
return info.status;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Progress
|
||||||
|
float
|
||||||
|
BDiskDeviceJob::Progress() const
|
||||||
|
{
|
||||||
|
if (InitCheck() != B_OK)
|
||||||
|
return 0;
|
||||||
|
disk_device_job_progress_info info;
|
||||||
|
status_t error = _kern_get_disk_device_job_progress_info(fID, &info);
|
||||||
|
if (error != B_OK)
|
||||||
|
return 0;
|
||||||
|
if (info.task_count < 1 || info.task_count <= info.completed_tasks)
|
||||||
|
return 1;
|
||||||
|
if (info.current_task_progress < 0)
|
||||||
|
info.current_task_progress = 0;
|
||||||
|
if (info.current_task_progress > 1)
|
||||||
|
info.current_task_progress = 1;
|
||||||
|
return (info.completed_tasks + info.current_task_progress)
|
||||||
|
/ info.task_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetProgressInfo
|
||||||
|
status_t
|
||||||
|
BDiskDeviceJob::GetProgressInfo(disk_device_job_progress_info *info) const
|
||||||
|
{
|
||||||
|
if (InitCheck() != B_OK)
|
||||||
|
return InitCheck();
|
||||||
|
return _kern_get_disk_device_job_progress_info(fID, info);
|
||||||
|
}
|
||||||
|
|
||||||
|
// InterruptProperties
|
||||||
|
uint32
|
||||||
|
BDiskDeviceJob::InterruptProperties() const
|
||||||
|
{
|
||||||
|
if (InitCheck() != B_OK)
|
||||||
|
return 0;
|
||||||
|
disk_device_job_progress_info info;
|
||||||
|
status_t error = _kern_get_disk_device_job_progress_info(fID, &info);
|
||||||
|
if (error != B_OK)
|
||||||
|
return 0;
|
||||||
|
return info.interrupt_properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel
|
||||||
|
status_t
|
||||||
|
BDiskDeviceJob::Cancel(bool reverse)
|
||||||
|
{
|
||||||
|
if (InitCheck() != B_OK)
|
||||||
|
return InitCheck();
|
||||||
|
return _kern_cancel_disk_device_job(fID, reverse);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pause
|
||||||
|
status_t
|
||||||
|
BDiskDeviceJob::Pause()
|
||||||
|
{
|
||||||
|
if (InitCheck() != B_OK)
|
||||||
|
return InitCheck();
|
||||||
|
return _kern_pause_disk_device_job(fID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// _SetTo
|
||||||
|
status_t
|
||||||
|
BDiskDeviceJob::_SetTo(user_disk_device_job_info *info)
|
||||||
|
{
|
||||||
|
Unset();
|
||||||
|
if (!info)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
fID = info->id;
|
||||||
|
fType = info->type;
|
||||||
|
fPartitionID = info->partition;
|
||||||
|
fDescription.SetTo(info->description);
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user