Cleanup and constantify

This commit is contained in:
Shubham Jangra 2019-05-23 16:35:27 +05:30
parent a7532d4041
commit 41b3b83335
5 changed files with 36 additions and 44 deletions

View File

@ -69,22 +69,19 @@ int main( int argc, char **argv )
QCoreApplication app(argc, argv); QCoreApplication app(argc, argv);
std::unique_ptr<KPMCoreInitializer> i; std::unique_ptr<KPMCoreInitializer> i;
if (argc != 2) if (argc != 2) {
{
i = std::make_unique<KPMCoreInitializer>(); i = std::make_unique<KPMCoreInitializer>();
if (!i->isValid()) if (!i->isValid())
return 1; return 1;
} } else {
else
{
i = std::make_unique<KPMCoreInitializer>( argv[1] ); i = std::make_unique<KPMCoreInitializer>( argv[1] );
if (!i->isValid()) if (!i->isValid())
return 1; return 1;
} }
auto backend = CoreBackendManager::self()->backend(); auto backend = CoreBackendManager::self()->backend();
if (!backend)
{ if (!backend) {
qWarning() << "Could not get backend."; qWarning() << "Could not get backend.";
return 1; return 1;
} }
@ -96,8 +93,8 @@ int main( int argc, char **argv )
const auto devices = operationStack->previewDevices(); const auto devices = operationStack->previewDevices();
qDebug() << "Found" << devices.length() << "devices."; qDebug() << "Found" << devices.length() << "devices.";
for (const auto pdev : devices)
{ for (const auto &pdev : devices) {
qDebug() << "Device @" << (void *)pdev; qDebug() << "Device @" << (void *)pdev;
qDebug() << " " << pdev->prettyName(); qDebug() << " " << pdev->prettyName();

View File

@ -26,30 +26,29 @@
#include <QDebug> #include <QDebug>
#include <QThread> #include <QThread>
class runcmd : public QThread { class runcmd : public QThread
public:
void run() override
{ {
ExternalCommand blkidCmd(QStringLiteral("blkid"), {}); public:
void run() override
// ExternalCommadHelper will refuse to run this or any other command which is not whitelisted. {
// See src/util/externalcommand_whitelist.h for whitelisted commands. ExternalCommand blkidCmd(QStringLiteral("blkid"), {});
blkidCmd.run();
qDebug().noquote() << blkidCmd.output();
}
// ExternalCommadHelper will refuse to run this or any other command which is not whitelisted.
// See src/util/externalcommand_whitelist.h for whitelisted commands.
blkidCmd.run();
qDebug().noquote() << blkidCmd.output();
}
}; };
class runcmd2 : public QThread { class runcmd2 : public QThread
public:
void run() override
{ {
ExternalCommand lsblkCmd(QStringLiteral("lsblk"), { QStringLiteral("--nodeps"), QStringLiteral("--json") }); public:
lsblkCmd.run(); void run() override
qDebug().noquote() << lsblkCmd.output(); {
} ExternalCommand lsblkCmd(QStringLiteral("lsblk"), { QStringLiteral("--nodeps"), QStringLiteral("--json") });
lsblkCmd.run();
qDebug().noquote() << lsblkCmd.output();
}
}; };
@ -60,8 +59,10 @@ int main( int argc, char **argv )
runcmd a; runcmd a;
runcmd2 b; runcmd2 b;
a.start(); a.start();
a.wait(); a.wait();
b.start(); b.start();
b.wait(); b.wait();

View File

@ -28,13 +28,10 @@
int main( int argc, char** argv ) int main( int argc, char** argv )
{ {
QCoreApplication app(argc, argv); QCoreApplication app(argc, argv);
if ( argc != 2 ) if ( argc != 2 ) {
{
KPMCoreInitializer i; KPMCoreInitializer i;
return i.isValid() ? 0 : 1; return i.isValid() ? 0 : 1;
} } else {
else
{
KPMCoreInitializer i( argv[1] ); KPMCoreInitializer i( argv[1] );
return i.isValid() ? 0 : 1; return i.isValid() ? 0 : 1;
} }

View File

@ -66,30 +66,27 @@ int main( int argc, char **argv )
QCoreApplication app(argc, argv); QCoreApplication app(argc, argv);
std::unique_ptr<KPMCoreInitializer> i; std::unique_ptr<KPMCoreInitializer> i;
if (argc != 2) if (argc != 2) {
{
i = std::make_unique<KPMCoreInitializer>(); i = std::make_unique<KPMCoreInitializer>();
if (!i->isValid()) if (!i->isValid())
return 1; return 1;
} } else {
else
{
i = std::make_unique<KPMCoreInitializer>( argv[1] ); i = std::make_unique<KPMCoreInitializer>( argv[1] );
if (!i->isValid()) if (!i->isValid())
return 1; return 1;
} }
auto backend = CoreBackendManager::self()->backend(); auto backend = CoreBackendManager::self()->backend();
if (!backend)
{ if (!backend) {
qWarning() << "Could not get backend."; qWarning() << "Could not get backend.";
return 1; return 1;
} }
const auto devices = backend->scanDevices(ScanFlag::includeLoopback); const auto devices = backend->scanDevices(ScanFlag::includeLoopback);
qDebug() << "Found" << devices.length() << "devices."; qDebug() << "Found" << devices.length() << "devices.";
for (const auto pdev : devices)
{ for (const auto &pdev : devices) {
qDebug() << "Device @" << (void *)pdev; qDebug() << "Device @" << (void *)pdev;
qDebug() << " " << pdev->prettyName(); qDebug() << " " << pdev->prettyName();

View File

@ -55,7 +55,7 @@ static QString getDefaultDevicePath()
static bool testSmartStatus() static bool testSmartStatus()
{ {
QString devicePath = getDefaultDevicePath(); const QString devicePath = getDefaultDevicePath();
SmartStatus smart(devicePath); SmartStatus smart(devicePath);
@ -85,7 +85,7 @@ static bool testSmartStatus()
static bool testSmartParser() static bool testSmartParser()
{ {
QString devicePath = getDefaultDevicePath(); const QString devicePath = getDefaultDevicePath();
SmartParser parser(devicePath); SmartParser parser(devicePath);