Reuse the d-pointer of the base class Device for the child class DiskDevice.
This commit is contained in:
parent
210dea15de
commit
df364bdc7c
|
@ -48,6 +48,30 @@ Device::Device(const QString& name,
|
|||
d->m_Type = type;
|
||||
}
|
||||
|
||||
/** Constructs a Device with an empty PartitionTable.
|
||||
@param name the Device's name, usually some string defined by the manufacturer
|
||||
@param deviceNode the Device's node, for example "/dev/sda"
|
||||
*/
|
||||
Device::Device(std::shared_ptr<DevicePrivate> d_ptr,
|
||||
const QString& name,
|
||||
const QString& deviceNode,
|
||||
const qint64 logicalSectorSize,
|
||||
const qint64 totalLogicalSectors,
|
||||
const QString& iconName,
|
||||
Device::Type type)
|
||||
: QObject()
|
||||
, d(d_ptr)
|
||||
{
|
||||
d->m_Name = name.length() > 0 ? name : i18n("Unknown Device");
|
||||
d->m_DeviceNode = deviceNode;
|
||||
d->m_LogicalSectorSize = logicalSectorSize;
|
||||
d->m_TotalLogical = totalLogicalSectors;
|
||||
d->m_PartitionTable = nullptr;
|
||||
d->m_IconName = iconName.isEmpty() ? QStringLiteral("drive-harddisk") : iconName;
|
||||
d->m_SmartStatus = type == Device::Disk_Device ? std::make_shared<SmartStatus>(deviceNode) : nullptr;
|
||||
d->m_Type = type;
|
||||
}
|
||||
|
||||
/** Copy constructor for Device.
|
||||
* @param other the other Device.
|
||||
*/
|
||||
|
|
|
@ -29,7 +29,7 @@ class PartitionTable;
|
|||
class CreatePartitionTableOperation;
|
||||
class CoreBackend;
|
||||
class SmartStatus;
|
||||
struct DevicePrivate;
|
||||
class DevicePrivate;
|
||||
|
||||
/** A device description.
|
||||
|
||||
|
@ -60,11 +60,12 @@ public:
|
|||
protected:
|
||||
explicit Device(const QString& name, const QString& deviceNode, const qint64 logicalSectorSize, const qint64 totalLogicalSectors, const QString& iconName = QString(), Device::Type type = Device::Disk_Device);
|
||||
|
||||
explicit Device(std::shared_ptr<DevicePrivate> d_ptr, const QString& name, const QString& deviceNode, const qint64 logicalSectorSize, const qint64 totalLogicalSectors, const QString& iconName = QString(), Device::Type type = Device::Disk_Device);
|
||||
|
||||
public:
|
||||
explicit Device(const Device& other);
|
||||
virtual ~Device();
|
||||
|
||||
public:
|
||||
virtual bool operator==(const Device& other) const;
|
||||
virtual bool operator!=(const Device& other) const;
|
||||
|
||||
|
|
|
@ -24,8 +24,9 @@
|
|||
class PartitionTable;
|
||||
class SmartStatus;
|
||||
|
||||
struct DevicePrivate
|
||||
class DevicePrivate
|
||||
{
|
||||
public:
|
||||
QString m_Name;
|
||||
QString m_DeviceNode;
|
||||
qint64 m_LogicalSectorSize;
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
*************************************************************************/
|
||||
|
||||
#include "core/diskdevice.h"
|
||||
#include "core/device_p.h"
|
||||
|
||||
#include "core/partitiontable.h"
|
||||
#include "core/smartstatus.h"
|
||||
|
@ -39,7 +40,11 @@
|
|||
#define BLKPBSZGET _IO(0x12,123)/* get block physical sector size */
|
||||
#endif
|
||||
|
||||
struct DiskDevicePrivate {
|
||||
#define d_ptr std::static_pointer_cast<DiskDevicePrivate>(d)
|
||||
|
||||
class DiskDevicePrivate : public DevicePrivate
|
||||
{
|
||||
public:
|
||||
qint32 m_Heads;
|
||||
qint32 m_SectorsPerTrack;
|
||||
qint32 m_Cylinders;
|
||||
|
@ -94,47 +99,46 @@ DiskDevice::DiskDevice(const QString& name,
|
|||
qint32 cylinders,
|
||||
qint64 sectorSize,
|
||||
const QString& iconName)
|
||||
: Device(name, deviceNode, sectorSize, (static_cast<qint64>(heads) * cylinders * numSectors), iconName, Device::Disk_Device)
|
||||
, d(std::make_unique<DiskDevicePrivate>())
|
||||
: Device(std::make_shared<DiskDevicePrivate>(), name, deviceNode, sectorSize, (static_cast<qint64>(heads) * cylinders * numSectors), iconName, Device::Disk_Device)
|
||||
{
|
||||
d->m_Heads = heads;
|
||||
d->m_SectorsPerTrack = numSectors;
|
||||
d->m_Cylinders = cylinders;
|
||||
d->m_LogicalSectorSize = sectorSize;
|
||||
d->m_PhysicalSectorSize = getPhysicalSectorSize(deviceNode);
|
||||
d_ptr->m_Heads = heads;
|
||||
d_ptr->m_SectorsPerTrack = numSectors;
|
||||
d_ptr->m_Cylinders = cylinders;
|
||||
d_ptr->m_LogicalSectorSize = sectorSize;
|
||||
d_ptr->m_PhysicalSectorSize = getPhysicalSectorSize(deviceNode);
|
||||
}
|
||||
|
||||
qint32 DiskDevice::heads() const
|
||||
{
|
||||
return d->m_Heads;
|
||||
return d_ptr->m_Heads;
|
||||
}
|
||||
|
||||
qint32 DiskDevice::cylinders() const
|
||||
{
|
||||
return d->m_Cylinders;
|
||||
return d_ptr->m_Cylinders;
|
||||
}
|
||||
|
||||
qint32 DiskDevice::sectorsPerTrack() const
|
||||
{
|
||||
return d->m_SectorsPerTrack;
|
||||
return d_ptr->m_SectorsPerTrack;
|
||||
}
|
||||
|
||||
qint64 DiskDevice::physicalSectorSize() const
|
||||
{
|
||||
return d->m_PhysicalSectorSize;
|
||||
return d_ptr->m_PhysicalSectorSize;
|
||||
}
|
||||
|
||||
qint64 DiskDevice::logicalSectorSize() const
|
||||
{
|
||||
return d->m_LogicalSectorSize;
|
||||
return d_ptr->m_LogicalSectorSize;
|
||||
}
|
||||
|
||||
qint64 DiskDevice::totalSectors() const
|
||||
{
|
||||
return static_cast<qint64>(d->m_Heads) * d->m_Cylinders * d->m_SectorsPerTrack;
|
||||
return static_cast<qint64>(d_ptr->m_Heads) * d_ptr->m_Cylinders * d_ptr->m_SectorsPerTrack;
|
||||
}
|
||||
|
||||
qint64 DiskDevice::cylinderSize() const
|
||||
{
|
||||
return static_cast<qint64>(d->m_Heads) * d->m_SectorsPerTrack;
|
||||
return static_cast<qint64>(d_ptr->m_Heads) * d_ptr->m_SectorsPerTrack;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ class PartitionTable;
|
|||
class CreatePartitionTableOperation;
|
||||
class CoreBackend;
|
||||
class SmartStatus;
|
||||
struct DiskDevicePrivate;
|
||||
class DiskDevicePrivate;
|
||||
|
||||
/** A disk device.
|
||||
|
||||
|
@ -91,9 +91,6 @@ public:
|
|||
* @return the size of a cylinder on this Device in sectors
|
||||
*/
|
||||
qint64 cylinderSize() const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<DiskDevicePrivate> d;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue