From 7e8bab3b4e07dd10f3d671b6a18c544343c38f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Mon, 9 Apr 2018 02:40:24 +0100 Subject: [PATCH] d-pointerize LvmDevice class. --- src/core/device.cpp | 23 --------- src/core/device.h | 2 - src/core/device_p.h | 5 ++ src/core/lvmdevice.cpp | 83 ++++++++++++++++++++++++++++---- src/core/lvmdevice.h | 53 ++++---------------- src/core/volumemanagerdevice.cpp | 11 +++-- src/core/volumemanagerdevice.h | 5 +- src/core/volumemanagerdevice_p.h | 27 +++++++++++ 8 files changed, 126 insertions(+), 83 deletions(-) create mode 100644 src/core/volumemanagerdevice_p.h diff --git a/src/core/device.cpp b/src/core/device.cpp index f6acae1..d6f576c 100644 --- a/src/core/device.cpp +++ b/src/core/device.cpp @@ -25,29 +25,6 @@ #include -/** 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(const QString& name, - const QString& deviceNode, - const qint64 logicalSectorSize, - const qint64 totalLogicalSectors, - const QString& iconName, - Device::Type type) - : QObject() - , d(std::make_shared()) -{ - 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(deviceNode) : nullptr; - 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" diff --git a/src/core/device.h b/src/core/device.h index 393723a..f99e642 100644 --- a/src/core/device.h +++ b/src/core/device.h @@ -58,8 +58,6 @@ 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 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: diff --git a/src/core/device_p.h b/src/core/device_p.h index 688f3c5..97d152c 100644 --- a/src/core/device_p.h +++ b/src/core/device_p.h @@ -15,6 +15,9 @@ * along with this program. If not, see .* *************************************************************************/ +#ifndef KPMCORE_DEVICE_P_H +#define KPMCORE_DEVICE_P_H + #include "core/device.h" #include @@ -36,3 +39,5 @@ public: std::shared_ptr m_SmartStatus; Device::Type m_Type; }; + +#endif diff --git a/src/core/lvmdevice.cpp b/src/core/lvmdevice.cpp index 0799c54..917410c 100644 --- a/src/core/lvmdevice.cpp +++ b/src/core/lvmdevice.cpp @@ -18,6 +18,7 @@ #include "core/lvmdevice.h" #include "core/partition.h" +#include "core/volumemanagerdevice_p.h" #include "fs/filesystem.h" #include "fs/lvm2_pv.h" #include "fs/luks.h" @@ -34,26 +35,43 @@ #include +#define d_ptr std::static_pointer_cast(d) + +class LvmDevicePrivate : public VolumeManagerDevicePrivate +{ +public: + qint64 m_peSize; + qint64 m_totalPE; + qint64 m_allocPE; + qint64 m_freePE; + QString m_UUID; + + mutable QStringList* m_LVPathList; + QVector m_PVs; + mutable QHash* m_LVSizeMap; +}; + /** Constructs a representation of LVM device with initialized LV as Partitions * * @param vgName Volume Group name * @param iconName Icon representing LVM Volume group */ LvmDevice::LvmDevice(const QString& vgName, const QString& iconName) - : VolumeManagerDevice(vgName, + : VolumeManagerDevice(std::make_shared(), + vgName, (QStringLiteral("/dev/") + vgName), getPeSize(vgName), getTotalPE(vgName), iconName, Device::LVM_Device) { - m_peSize = logicalSize(); - m_totalPE = totalLogical(); - m_freePE = getFreePE(vgName); - m_allocPE = m_totalPE - m_freePE; - m_UUID = getUUID(vgName); - m_LVPathList = new QStringList(getLVs(vgName)); - m_LVSizeMap = new QHash(); + d_ptr->m_peSize = logicalSize(); + d_ptr->m_totalPE = totalLogical(); + d_ptr->m_freePE = getFreePE(vgName); + d_ptr->m_allocPE = d_ptr->m_totalPE - d_ptr->m_freePE; + d_ptr->m_UUID = getUUID(vgName); + d_ptr->m_LVPathList = new QStringList(getLVs(vgName)); + d_ptr->m_LVSizeMap = new QHash(); initPartitions(); } @@ -66,8 +84,8 @@ QVector LvmDevice::s_DirtyPVs; LvmDevice::~LvmDevice() { - delete m_LVPathList; - delete m_LVSizeMap; + delete d_ptr->m_LVPathList; + delete d_ptr->m_LVSizeMap; } void LvmDevice::initPartitions() @@ -492,3 +510,48 @@ bool LvmDevice::activateLV(const QString& lvPath) lvPath }); return deactivate.run(-1) && deactivate.exitCode() == 0; } + +qint64 LvmDevice::peSize() const +{ + return d_ptr->m_peSize; +} + +qint64 LvmDevice::totalPE() const +{ + return d_ptr->m_totalPE; +} + +qint64 LvmDevice::allocatedPE() const +{ + return d_ptr->m_allocPE; +} + +qint64 LvmDevice::freePE() const +{ + return d_ptr->m_freePE; +} + +QString LvmDevice::UUID() const +{ + return d_ptr->m_UUID; +} + +QStringList* LvmDevice::LVPathList() const +{ + return d_ptr->m_LVPathList; +} + +QVector & LvmDevice::physicalVolumes() +{ + return d_ptr->m_PVs; +} + +const QVector & LvmDevice::physicalVolumes() const +{ + return d_ptr->m_PVs; +} + +QHash* LvmDevice::LVSizeMap() const +{ + return d_ptr->m_LVSizeMap; +} diff --git a/src/core/lvmdevice.h b/src/core/lvmdevice.h index 8a49263..08b768e 100644 --- a/src/core/lvmdevice.h +++ b/src/core/lvmdevice.h @@ -16,8 +16,7 @@ * along with this program. If not, see .* *************************************************************************/ -#if !defined(KPMCORE_LVMDEVICE_H) - +#ifndef KPMCORE_LVMDEVICE_H #define KPMCORE_LVMDEVICE_H #include "core/device.h" @@ -57,7 +56,6 @@ public: static QVector s_DirtyPVs; -public: static void scanSystemLVM(QList& devices); static const QStringList getVGs(); @@ -89,54 +87,23 @@ public: static bool activateVG(Report& report, const LvmDevice& d); protected: - void initPartitions() override; const QList scanPartitions(PartitionTable* pTable) const; Partition* scanPartition(const QString& lvPath, PartitionTable* pTable) const; qint64 mappedSector(const QString& lvPath, qint64 sector) const override; public: - qint64 peSize() const { - return m_peSize; - } - qint64 totalPE() const { - return m_totalPE; - } - qint64 allocatedPE() const { - return m_allocPE; - } - qint64 freePE() const { - return m_freePE; - } - QString UUID() const { - return m_UUID; - } - QStringList* LVPathList() const { - return m_LVPathList; - } - QVector & physicalVolumes() { - return m_PVs; - } - const QVector & physicalVolumes() const { - return m_PVs; - } + qint64 peSize() const; + qint64 totalPE() const; + qint64 allocatedPE() const; + qint64 freePE() const; + QString UUID() const; + QStringList* LVPathList() const; + QVector & physicalVolumes(); + const QVector & physicalVolumes() const; protected: - QHash* LVSizeMap() const { - return m_LVSizeMap; - } - -private: - qint64 m_peSize; - qint64 m_totalPE; - qint64 m_allocPE; - qint64 m_freePE; - QString m_UUID; - - mutable QStringList* m_LVPathList; - QVector m_PVs; - mutable QHash* m_LVSizeMap; - + QHash* LVSizeMap() const; }; #endif diff --git a/src/core/volumemanagerdevice.cpp b/src/core/volumemanagerdevice.cpp index 8dc9659..7c339af 100644 --- a/src/core/volumemanagerdevice.cpp +++ b/src/core/volumemanagerdevice.cpp @@ -18,17 +18,22 @@ #include "core/device_p.h" #include "core/volumemanagerdevice.h" +#include "core/volumemanagerdevice_p.h" /** Constructs an abstract Volume Manager Device with an empty PartitionTable. * + * @param name the Device's name + * @param deviceNode the Device's node + * @param logicalExtentSize the logical extent size that device uses */ -VolumeManagerDevice::VolumeManagerDevice(const QString& name, +VolumeManagerDevice::VolumeManagerDevice(std::shared_ptr d, + const QString& name, const QString& deviceNode, - const qint64 logicalSize, + const qint64 logicalExtentSize, const qint64 totalLogical, const QString& iconName, Device::Type type) - : Device(name, deviceNode, logicalSize, totalLogical, iconName, type) + : Device(std::static_pointer_cast(d), name, deviceNode, logicalExtentSize, totalLogical, iconName, type) { } diff --git a/src/core/volumemanagerdevice.h b/src/core/volumemanagerdevice.h index be59eb5..60dd4d3 100644 --- a/src/core/volumemanagerdevice.h +++ b/src/core/volumemanagerdevice.h @@ -26,6 +26,8 @@ #include #include +class VolumeManagerDevicePrivate; + /** A Volume Manager of physical devices represented as an abstract device. * * VolumeManagerDevice is an abstract device class for volume manager. e.g: LVM, SoftRAID. @@ -40,8 +42,7 @@ class LIBKPMCORE_EXPORT VolumeManagerDevice : public Device Q_DISABLE_COPY(VolumeManagerDevice) public: - - VolumeManagerDevice(const QString& name, const QString& deviceNode, const qint64 logicalSize, const qint64 totalLogical, const QString& iconName = QString(), Device::Type type = Device::Unknown_Device); + VolumeManagerDevice(std::shared_ptr d, const QString& name, const QString& deviceNode, const qint64 logicalSectorSize, const qint64 totalLogical, const QString& iconName = QString(), Device::Type type = Device::Unknown_Device); /** * @return list of physical device's path that makes up volumeManagerDevice.(e.g: /dev/sda, /dev/sdb1) diff --git a/src/core/volumemanagerdevice_p.h b/src/core/volumemanagerdevice_p.h new file mode 100644 index 0000000..6061c26 --- /dev/null +++ b/src/core/volumemanagerdevice_p.h @@ -0,0 +1,27 @@ +/************************************************************************* + * Copyright (C) 2018 by Andrius Štikonas * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 3 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see .* + *************************************************************************/ + +#ifndef KPMCORE_VOLUMEMANAGERDEVICE_P_H +#define KPMCORE_VOLUMEMANAGERDEVICE_P_H + +#include "core/device_p.h" + +class VolumeManagerDevicePrivate : public DevicePrivate +{ +}; + +#endif