Commit 1ac33a13 authored by Gleb Popov's avatar Gleb Popov

Remove the m_managedObjects cache and compute it on every GetManagedObjects() call.

Reported by: tijl
parent f1891d942806
......@@ -10,7 +10,48 @@
DBUSManagerStruct ObjectManager::GetManagedObjects()
{
return m_managedObjects;
DBUSManagerStruct ret;
QList<std::pair<QObject*, QDBusObjectPath>> objects;
std::transform(m_driveObjects.begin(), m_driveObjects.end(), std::back_inserter(objects),
[](Drive* d) { return std::make_pair(static_cast<QObject*>(d), d->dbusPath); }
);
std::transform(m_blockObjects.begin(), m_blockObjects.end(), std::back_inserter(objects),
[](Block* b) { return std::make_pair(static_cast<QObject*>(b), b->dbusPath); }
);
for(auto& objectPair : objects)
{
QObject* o = objectPair.first;
auto dbusPath = objectPair.second;
QVariantMapMap interfaces;
for(QObject* child : o->children())
{
QDBusAbstractAdaptor* adaptor = qobject_cast<QDBusAbstractAdaptor*>(child);
if(!adaptor)
continue;
const QString& iface = adaptor->metaObject()->classInfo(adaptor->metaObject()->indexOfClassInfo("D-Bus Interface")).value();
QVariantMap properties;
for (int i = adaptor->metaObject()->propertyOffset();
i < adaptor->metaObject()->propertyCount(); ++i) {
auto propertyName = adaptor->metaObject()->property(i).name();
properties.insert(QString::fromLatin1(propertyName), adaptor->property(propertyName));
}
interfaces[iface] = properties;
}
ret[dbusPath] = interfaces;
}
return ret;
}
......@@ -452,7 +493,7 @@ void ObjectManager::addPartition(Block* b, const QString& tableBlockName, const
void ObjectManager::addInterfaces(QDBusObjectPath path, QList<std::pair<QString, QDBusAbstractAdaptor*>> newInterfaces)
{
QVariantMapMap& interfaces = m_managedObjects[path];
QVariantMapMap interfaces;
for (auto pair : newInterfaces)
{
......@@ -475,11 +516,5 @@ void ObjectManager::addInterfaces(QDBusObjectPath path, QList<std::pair<QString,
void ObjectManager::removeInterfaces(QDBusObjectPath path, QStringList ifaces)
{
QVariantMapMap& interfaces = m_managedObjects[path];
for(auto iface : ifaces)
interfaces.remove(iface);
emit InterfacesRemoved(path, ifaces);
if(interfaces.empty())
m_managedObjects.remove(path);
}
......@@ -71,8 +71,6 @@ private:
void addInterfaces(QDBusObjectPath path, QList<std::pair<QString, QDBusAbstractAdaptor*>> newInterfaces);
void removeInterfaces(QDBusObjectPath path, QStringList ifaces);
DBUSManagerStruct m_managedObjects;
bool initialProbeDone;
QHash<QString, Block*> m_blockObjects;
QHash<QString, Drive*> m_driveObjects;
......
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