MCPcopy Create free account
hub / github.com/KDAB/GammaRay / handleMessage

Method handleMessage

common/propertysyncer.cpp:94–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92}
93
94void 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;

Callers 2

server2clientMethod · 0.80
client2serverMethod · 0.80

Calls 15

qobjectPropertyOffsetFunction · 0.85
propertyCountMethod · 0.80
reserveMethod · 0.80
endMethod · 0.80
addressMethod · 0.45
typeMethod · 0.45
constBeginMethod · 0.45
constEndMethod · 0.45
metaObjectMethod · 0.45
propertyMethod · 0.45
nameMethod · 0.45
isEmptyMethod · 0.45

Tested by 2

server2clientMethod · 0.64
client2serverMethod · 0.64