| 34 | |
| 35 | namespace { |
| 36 | bool prioritizeLatestConnection(QObject *sender, const char *normalizedSignalName, QObject *receiver) |
| 37 | { |
| 38 | const auto senderPrivate = QObjectPrivate::get(sender); |
| 39 | const auto sigIndex = senderPrivate->signalIndex(normalizedSignalName); |
| 40 | if (sigIndex < 0) { |
| 41 | return false; |
| 42 | } |
| 43 | |
| 44 | const auto connectionData = senderPrivate->connections.loadRelaxed(); |
| 45 | if (!connectionData) { |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | auto signalsVector = connectionData->signalVector.loadRelaxed(); |
| 50 | if (!signalsVector) { |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | QObjectPrivate::Connection *ourConn = nullptr; |
| 55 | for (int i = 0; i < signalsVector->count(); ++i) { |
| 56 | QObjectPrivate::Connection *conn = signalsVector->at(i).first; |
| 57 | while (conn) { |
| 58 | if (conn->signal_index == sigIndex && conn->receiver == receiver) { |
| 59 | ourConn = conn; |
| 60 | // We continue because we want to locate the latest connection, |
| 61 | // i.e. the connection we just made |
| 62 | } |
| 63 | |
| 64 | conn = conn->nextConnectionList; |
| 65 | } |
| 66 | |
| 67 | // TODO: The whole thing needs to be atomic |
| 68 | if (ourConn) { |
| 69 | if (ourConn == signalsVector->at(i).first) { |
| 70 | qDebug() << "We are already the first, nothing to do"; |
| 71 | return true; |
| 72 | } |
| 73 | |
| 74 | qDebug() << "Swapping" << ourConn->receiver << "with" |
| 75 | << static_cast<QObjectPrivate::Connection *>(signalsVector->at(i).first)->receiver; |
| 76 | ourConn->prevConnectionList->nextConnectionList.storeRelaxed(ourConn->nextConnectionList); |
| 77 | ourConn->nextConnectionList.storeRelaxed(signalsVector->at(i).first); |
| 78 | signalsVector->at(i).first.storeRelaxed(ourConn); |
| 79 | return true; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | NetworkReply::ContentType contentType(const QVariant &v) |
| 87 | { |
no test coverage detected