Files
haiku-beta6/src/kits/storage/DiskDeviceJob.cpp
T
Ingo Weinhold ca9e5772c3 * Reintroduced third LinkAgainst parameter <mapLibs>, defaulting to true.
Library names are now mapped for all targets but "host" (not only for
  "haiku") -- added one more level of indirection to achieve that.
  (TARGET_LIBRARY_NAME_MAP -> *_LIBRARY_NAME_MAP_*).
* Renamed build/HaikuBuildCompatibility.h to BeOSBuildCompatibility.h
  (auto-included when compiling something that uses the Be API for platform
  "host" on anon-BeOS platform), and introduced build/HaikuBuildCompatibility.h,
  which can be included when compiling something that can be built for both,
  Haiku and BeOS compatible platforms.
* Introduced libhaikucompat.a, a library that adds a few functions existing
  under Haiku, but not under BeOS.
* New rule AddSubDirSupportedPlatforms.
* Renamed libopenbeos.so to libbe_haiku.so.
* Introduced new target platform "libbe_test", which is basically equivalent
  to a BeOS compatible host platform target, with the exception, that instead
  of the host platform's libbe.so a special build of Haiku's libbe.so
  (libbe_haiku.so (formerly known as libopenbeos.so)) is used. Furthermore
  Haiku's public app, interface, storage, and support kit headers are used
  when compiling. This replaces the less nice way in which the test app server
  and applications for this test environment were built.
  When building for platform "libbe_test", the library name "be" is
  autotranslated to "libbe_haiku.so". Thus most applications don't need
  special fiddling when them building them for the app server test environment;
  usually an "AddSubDirSupportedPlatforms libbe_test ;" will suffice.
* Reduced the dependencies of <syscalls.h> and fixed problems caused by this
  (e.g. source files not including the needed headers directly).



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14749 a95241bf-73f2-0310-859d-f6bbb57e9c96
2005-11-07 16:07:25 +00:00

169 lines
3.2 KiB
C++

//----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//---------------------------------------------------------------------
#include <DiskDeviceJob.h>
#include <syscalls.h>
#include <disk_device_manager/ddm_userland_interface.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;
}