Commit 6ee813b8 authored by Gleb Popov's avatar Gleb Popov

Wrap the duplicated checking code into a macro.

parent b1ff813e2d0f
......@@ -8,6 +8,11 @@
#include "camcontrolprober.h"
#include "zfsprober.h"
// We have to run this check whenever a probe is finished, because the object
// being probed may be deleted meanwhile.
#define GET_BLOCK_OR_RETURN_IF_GONE(name) Block* b = m_blockObjects.value(name, nullptr); \
if(!b) return;
DBUSManagerStruct ObjectManager::GetManagedObjects()
{
DBUSManagerStruct ret;
......@@ -391,9 +396,7 @@ void ObjectManager::startFilesystemProbe(Block* b)
QObject::connect(prober, &FilesystemProber::finished, this,
[this, devName](QString fs)
{
Block* b = m_blockObjects.value(devName);
if(!b)
return;
GET_BLOCK_OR_RETURN_IF_GONE(devName);
qDebug() << "Finished FS probe on " << b->name;
if(!fs.isEmpty())
......@@ -420,18 +423,14 @@ void ObjectManager::startGeomProbe(Block* b)
QObject::connect(prober, &GeomProber::gotLabels, this,
[this, devName](QStringList labels)
{
Block* b = m_blockObjects.value(devName);
if(!b)
return;
GET_BLOCK_OR_RETURN_IF_GONE(devName);
b->labels = labels;
});
QObject::connect(prober, &GeomProber::gotDisk, this,
[this, devName](DiskInfo di)
{
Block* b = m_blockObjects.value(devName);
if(!b)
return;
GET_BLOCK_OR_RETURN_IF_GONE(devName);
b->size = di.mediaSize();
b->description = di.descr();
......@@ -440,9 +439,7 @@ void ObjectManager::startGeomProbe(Block* b)
QObject::connect(prober, &GeomProber::gotPartTable, this,
[this, devName](PartTableInfo pi)
{
Block* b = m_blockObjects.value(devName);
if(!b)
return;
GET_BLOCK_OR_RETURN_IF_GONE(devName);
// do not create BlockPartTable when called from updateBlock()
if(!b->bPartTable)
......@@ -456,18 +453,14 @@ void ObjectManager::startGeomProbe(Block* b)
QObject::connect(prober, &GeomProber::gotPart, this,
[this, devName](QString tableBlockName, Part partInfo)
{
Block* b = m_blockObjects.value(devName);
if(!b)
return;
GET_BLOCK_OR_RETURN_IF_GONE(devName);
addPartition(b, tableBlockName, partInfo);
});
QObject::connect(prober, &GeomProber::finished, this,
[this, devName]()
{
Block* b = m_blockObjects.value(devName);
if(!b)
return;
GET_BLOCK_OR_RETURN_IF_GONE(devName);
b->probesDone.set(GEOM_PROBE);
qDebug() << "Finished GEOM probe on " << b->name;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment