X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fsignalproxy.cpp;h=8499e1ada965b2e94895d41f21bd780b1b7cff35;hp=d9102fd33c84103f051c9a56be7282346f1ee900;hb=2c4e055125a3e3ab7a2bd0d9c0ea33415f6ce7cc;hpb=1cb02004ee5973b89368bd84f234d4652794690d diff --git a/src/common/signalproxy.cpp b/src/common/signalproxy.cpp index d9102fd3..8499e1ad 100644 --- a/src/common/signalproxy.cpp +++ b/src/common/signalproxy.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2015 by the Quassel Project * + * Copyright (C) 2005-2016 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -119,7 +119,7 @@ void SignalProxy::SignalRelay::detachSignal(QObject *sender, int signalId) break; } else { - slotIter++; + ++slotIter; } } } @@ -146,9 +146,9 @@ int SignalProxy::SignalRelay::qt_metacall(QMetaObject::Call _c, int _id, void ** for (int i = 0; i < argTypes.size(); i++) { if (argTypes[i] == 0) { #if QT_VERSION >= 0x050000 - qWarning() << "SignalRelay::qt_metacall(): received invalid data for argument number" << i << "of signal" << QString("%1::%2").arg(caller->metaObject()->className()).arg(caller->metaObject()->method(_id).methodSignature().constData()); + qWarning() << "SignalRelay::qt_metacall(): received invalid data for argument number" << i << "of signal" << QString("%1::%2").arg(caller->metaObject()->className()).arg(caller->metaObject()->method(signal.signalId).methodSignature().constData()); #else - qWarning() << "SignalRelay::qt_metacall(): received invalid data for argument number" << i << "of signal" << QString("%1::%2").arg(caller->metaObject()->className()).arg(caller->metaObject()->method(_id).signature()); + qWarning() << "SignalRelay::qt_metacall(): received invalid data for argument number" << i << "of signal" << QString("%1::%2").arg(caller->metaObject()->className()).arg(caller->metaObject()->method(signal.signalId).signature()); #endif qWarning() << " - make sure all your data types are known by the Qt MetaSystem"; return _id; @@ -156,9 +156,11 @@ int SignalProxy::SignalRelay::qt_metacall(QMetaObject::Call _c, int _id, void ** params << QVariant(argTypes[i], _a[i+1]); } - if (argTypes.size() >= 1 && argTypes[0] == qMetaTypeId() && proxy()->proxyMode() == SignalProxy::Server) { - Peer *peer = params[0].value(); - proxy()->dispatch(peer, RpcCall(signal.signature, params)); + if (proxy()->_restrictMessageTarget) { + for (auto peer : proxy()->_restrictedTargets) { + if (peer != nullptr) + proxy()->dispatch(peer, RpcCall(signal.signature, params)); + } } else proxy()->dispatch(RpcCall(signal.signature, params)); } @@ -197,7 +199,7 @@ SignalProxy::~SignalProxy() objIter = classIter->erase(objIter); obj->stopSynchronize(this); } - classIter++; + ++classIter; } _syncSlave.clear(); @@ -288,7 +290,13 @@ bool SignalProxy::addPeer(Peer *peer) if (!peer->parent()) peer->setParent(this); + if (peer->_id < 0) { + peer->_id = nextPeerId(); + peer->_connectedSince = QDateTime::currentDateTimeUtc(); + } + _peers.insert(peer); + _peerMap[peer->_id] = peer; peer->setSignalProxy(this); @@ -331,6 +339,7 @@ void SignalProxy::removePeer(Peer *peer) disconnect(peer, 0, this, 0); peer->setSignalProxy(0); + _peerMap.remove(peer->_id); _peers.remove(peer); emit peerRemoved(peer); @@ -482,7 +491,7 @@ void SignalProxy::detachSlots(QObject *receiver) slotIter = _attachedSlots.erase(slotIter); } else - slotIter++; + ++slotIter; } } @@ -497,7 +506,7 @@ void SignalProxy::stopSynchronize(SyncableObject *obj) classIter->remove(obj->objectName()); break; } - classIter++; + ++classIter; } obj->stopSynchronize(this); } @@ -661,12 +670,8 @@ bool SignalProxy::invokeSlot(QObject *receiver, int methodId, const QVariantList qWarning() << "SignalProxy::invokeSlot(): incompatible param types to invoke" << eMeta->methodName(methodId); return false; } - // if first arg is a PeerPtr, replace it by the address of the peer originally receiving the RpcCall - if (peer && i == 0 && args[0] == qMetaTypeId()) { - QVariant v = QVariant::fromValue(peer); - _a[1] = const_cast(v.constData()); - } else - _a[i+1] = const_cast(params[i].constData()); + + _a[i+1] = const_cast(params[i].constData()); } if (returnValue.type() != QVariant::Invalid) @@ -677,9 +682,11 @@ bool SignalProxy::invokeSlot(QObject *receiver, int methodId, const QVariantList : Qt::QueuedConnection; if (type == Qt::DirectConnection) { - return receiver->qt_metacall(QMetaObject::InvokeMetaMethod, methodId, _a) < 0; - } - else { + _sourcePeer = peer; + auto result = receiver->qt_metacall(QMetaObject::InvokeMetaMethod, methodId, _a) < 0; + _sourcePeer = nullptr; + return result; + } else { qWarning() << "Queued Connections are not implemented yet"; // note to self: qmetaobject.cpp:990 ff return false; @@ -758,9 +765,11 @@ void SignalProxy::sync_call__(const SyncableObject *obj, SignalProxy::ProxyMode params << QVariant(argTypes[i], va_arg(ap, void *)); } - if (argTypes.size() >= 1 && argTypes[0] == qMetaTypeId() && proxyMode() == SignalProxy::Server) { - Peer *peer = params[0].value(); - dispatch(peer, SyncMessage(eMeta->metaObject()->className(), obj->objectName(), QByteArray(funcname), params)); + if (_restrictMessageTarget) { + for (auto peer : _restrictedTargets) { + if (peer != nullptr) + dispatch(peer, SyncMessage(eMeta->metaObject()->className(), obj->objectName(), QByteArray(funcname), params)); + } } else dispatch(SyncMessage(eMeta->metaObject()->className(), obj->objectName(), QByteArray(funcname), params)); } @@ -810,6 +819,37 @@ void SignalProxy::updateSecureState() emit secureStateChanged(_secure); } +QVariantList SignalProxy::peerData() { + QVariantList result; + for (auto peer : _peers) { + QVariantMap data; + data["id"] = peer->_id; + data["clientVersion"] = peer->_clientVersion; + data["clientVersionDate"] = peer->_buildDate; + data["remoteAddress"] = peer->address(); + data["connectedSince"] = peer->_connectedSince; + data["secure"] = peer->isSecure(); + result << data; + } + return result; +} + +Peer *SignalProxy::peerById(int peerId) { + return _peerMap[peerId]; +} + +void SignalProxy::restrictTargetPeers(QSet peers, std::function closure) +{ + auto previousRestrictMessageTarget = _restrictMessageTarget; + auto previousRestrictedTargets = _restrictedTargets; + _restrictMessageTarget = true; + _restrictedTargets = peers; + + closure(); + + _restrictMessageTarget = previousRestrictMessageTarget; + _restrictedTargets = previousRestrictedTargets; +} // ================================================== // ExtendedMetaObject