summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
47a6910)
For file transfers and possibly other use cases, it is important to know
which peer has received a specific signal, and to allow sending remote
signals only through a particular peer rather than multicasting to all connected
clients.
For this reason, we now treat attached signals/slots specially if their first
argument is a PeerPtr (a typedef for Peer *):
* An attached slot will have a pointer to the peer which received the signal in
its first argument
* An attached signal on the core side will be relayed only through the peer that
is given as the first argument (and the receiving slot will have a pointer to
the client-side peer in this argument)
* The peer argument for an attached signal on the client side will be ignored,
as clients only have one peer anyway
#include "protocol.h"
#include "syncableobject.h"
#include "util.h"
#include "protocol.h"
#include "syncableobject.h"
#include "util.h"
using namespace Protocol;
using namespace Protocol;
params << QVariant(argTypes[i], _a[i+1]);
}
params << QVariant(argTypes[i], _a[i+1]);
}
- proxy()->dispatch(RpcCall(signal.signature, params));
+ if (argTypes.size() >= 1 && argTypes[0] == qMetaTypeId<PeerPtr>() && proxy()->proxyMode() == SignalProxy::Server) {
+ Peer *peer = params[0].value<PeerPtr>();
+ proxy()->dispatch(peer, RpcCall(signal.signature, params));
+ } else
+ proxy()->dispatch(RpcCall(signal.signature, params));
}
_id -= _slots.count();
}
}
_id -= _slots.count();
}
+void SignalProxy::dispatch(Peer *peer, const RpcCall &rpcCall)
+{
+ if (peer && peer->isOpen())
+ peer->dispatch(rpcCall);
+ else
+ QCoreApplication::postEvent(this, new ::RemovePeerEvent(peer));
+}
+
+
void SignalProxy::handle(Peer *peer, const SyncMessage &syncMessage)
{
if (!_syncSlave.contains(syncMessage.className) || !_syncSlave[syncMessage.className].contains(syncMessage.objectName)) {
void SignalProxy::handle(Peer *peer, const SyncMessage &syncMessage)
{
if (!_syncSlave.contains(syncMessage.className) || !_syncSlave[syncMessage.className].contains(syncMessage.objectName)) {
void SignalProxy::handle(Peer *peer, const RpcCall &rpcCall)
{
void SignalProxy::handle(Peer *peer, const RpcCall &rpcCall)
{
QObject *receiver;
int methodId;
SlotHash::const_iterator slot = _attachedSlots.constFind(rpcCall.slotName);
while (slot != _attachedSlots.constEnd() && slot.key() == rpcCall.slotName) {
receiver = (*slot).first;
methodId = (*slot).second;
QObject *receiver;
int methodId;
SlotHash::const_iterator slot = _attachedSlots.constFind(rpcCall.slotName);
while (slot != _attachedSlots.constEnd() && slot.key() == rpcCall.slotName) {
receiver = (*slot).first;
methodId = (*slot).second;
- if (!invokeSlot(receiver, methodId, rpcCall.params)) {
+ if (!invokeSlot(receiver, methodId, rpcCall.params, peer)) {
ExtendedMetaObject *eMeta = extendedMetaObject(receiver);
qWarning("SignalProxy::handleSignal(): invokeMethod for \"%s\" failed ", eMeta->methodName(methodId).constData());
}
ExtendedMetaObject *eMeta = extendedMetaObject(receiver);
qWarning("SignalProxy::handleSignal(): invokeMethod for \"%s\" failed ", eMeta->methodName(methodId).constData());
}
-bool SignalProxy::invokeSlot(QObject *receiver, int methodId, const QVariantList ¶ms, QVariant &returnValue)
+bool SignalProxy::invokeSlot(QObject *receiver, int methodId, const QVariantList ¶ms, QVariant &returnValue, Peer *peer)
{
ExtendedMetaObject *eMeta = extendedMetaObject(receiver);
const QList<int> args = eMeta->argTypes(methodId);
{
ExtendedMetaObject *eMeta = extendedMetaObject(receiver);
const QList<int> args = eMeta->argTypes(methodId);
qWarning() << "SignalProxy::invokeSlot(): incompatible param types to invoke" << eMeta->methodName(methodId);
return false;
}
qWarning() << "SignalProxy::invokeSlot(): incompatible param types to invoke" << eMeta->methodName(methodId);
return false;
}
- _a[i+1] = const_cast<void *>(params[i].constData());
+ // 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<PeerPtr>()) {
+ QVariant v = QVariant::fromValue<PeerPtr>(peer);
+ _a[1] = const_cast<void*>(v.constData());
+ } else
+ _a[i+1] = const_cast<void *>(params[i].constData());
}
if (returnValue.type() != QVariant::Invalid)
}
if (returnValue.type() != QVariant::Invalid)
-bool SignalProxy::invokeSlot(QObject *receiver, int methodId, const QVariantList ¶ms)
+bool SignalProxy::invokeSlot(QObject *receiver, int methodId, const QVariantList ¶ms, Peer *peer)
- return invokeSlot(receiver, methodId, params, ret);
+ return invokeSlot(receiver, methodId, params, ret, peer);
template<class T>
void dispatch(const T &protoMessage);
template<class T>
void dispatch(const T &protoMessage);
+ void dispatch(Peer *peer, const Protocol::RpcCall &rpcCall);
void handle(Peer *peer, const Protocol::SyncMessage &syncMessage);
void handle(Peer *peer, const Protocol::RpcCall &rpcCall);
void handle(Peer *peer, const Protocol::SyncMessage &syncMessage);
void handle(Peer *peer, const Protocol::RpcCall &rpcCall);
template<class T>
void handle(Peer *, T) { Q_ASSERT(0); }
template<class T>
void handle(Peer *, T) { Q_ASSERT(0); }
- bool invokeSlot(QObject *receiver, int methodId, const QVariantList ¶ms, QVariant &returnValue);
- bool invokeSlot(QObject *receiver, int methodId, const QVariantList ¶ms = QVariantList());
+ bool invokeSlot(QObject *receiver, int methodId, const QVariantList ¶ms, QVariant &returnValue, Peer *peer = 0);
+ bool invokeSlot(QObject *receiver, int methodId, const QVariantList ¶ms = QVariantList(), Peer *peer = 0);
void requestInit(SyncableObject *obj);
QVariantMap initData(SyncableObject *obj) const;
void requestInit(SyncableObject *obj);
QVariantMap initData(SyncableObject *obj) const;
#include <QHostAddress>
#include <QDataStream>
#include <QHostAddress>
#include <QDataStream>
+// We need to special-case Peer* in attached signals/slots, so typedef it for the meta type system
+class Peer;
+typedef Peer * PeerPtr;
+Q_DECLARE_METATYPE(PeerPtr)
+
class SignedId
{
protected:
class SignedId
{
protected: