| 92 | } |
| 93 | |
| 94 | void PropertySyncer::handleMessage(const GammaRay::Message &msg) |
| 95 | { |
| 96 | Q_ASSERT(msg.address() == m_address); |
| 97 | switch (msg.type()) { |
| 98 | case Protocol::PropertySyncRequest: { |
| 99 | Protocol::ObjectAddress addr; |
| 100 | msg >> addr; |
| 101 | Q_ASSERT(addr != Protocol::InvalidObjectAddress); |
| 102 | |
| 103 | const auto it = std::find_if(m_objects.constBegin(), m_objects.constEnd(), |
| 104 | [addr](const ObjectInfo &info) { |
| 105 | return info.addr == addr; |
| 106 | }); |
| 107 | if (it == m_objects.constEnd()) |
| 108 | break; |
| 109 | |
| 110 | QVector<QPair<QByteArray, QVariant>> values; |
| 111 | const auto propCount = (*it).obj->metaObject()->propertyCount(); |
| 112 | values.reserve(propCount); |
| 113 | for (int i = qobjectPropertyOffset(); i < propCount; ++i) { |
| 114 | const auto prop = (*it).obj->metaObject()->property(i); |
| 115 | values.push_back(qMakePair(QByteArray(prop.name()), prop.read((*it).obj))); |
| 116 | } |
| 117 | Q_ASSERT(!values.isEmpty()); |
| 118 | |
| 119 | Message msg(m_address, Protocol::PropertyValuesChanged); |
| 120 | msg << addr << ( quint32 )values.size(); |
| 121 | for (const auto &value : std::as_const(values)) |
| 122 | msg << value.first << value.second; |
| 123 | emit message(msg); |
| 124 | break; |
| 125 | } |
| 126 | case Protocol::PropertyValuesChanged: { |
| 127 | Protocol::ObjectAddress addr; |
| 128 | quint32 changeSize; |
| 129 | msg >> addr >> changeSize; |
| 130 | Q_ASSERT(addr != Protocol::InvalidObjectAddress); |
| 131 | Q_ASSERT(changeSize > 0); |
| 132 | |
| 133 | auto it = std::find_if(m_objects.begin(), m_objects.end(), [addr](const ObjectInfo &info) { |
| 134 | return info.addr == addr; |
| 135 | }); |
| 136 | if (it == m_objects.end()) |
| 137 | break; |
| 138 | |
| 139 | for (quint32 i = 0; i < changeSize; ++i) { |
| 140 | QByteArray propName; |
| 141 | QVariant propValue; |
| 142 | msg >> propName >> propValue; |
| 143 | (*it).recursionLock = true; |
| 144 | (*it).obj->setProperty(propName, propValue); |
| 145 | |
| 146 | // it can be invalid if as a result of the above call new objects have been registered for example |
| 147 | it = std::find_if(m_objects.begin(), m_objects.end(), [addr](const ObjectInfo &info) { |
| 148 | return info.addr == addr; |
| 149 | }); |
| 150 | Q_ASSERT(it != m_objects.end()); |
| 151 | (*it).recursionLock = false; |