Make PeerPtr work for RPC calls
authorManuel Nickschas <sputnick@quassel-irc.org>
Wed, 11 Mar 2015 18:43:21 +0000 (19:43 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 11 Mar 2015 18:43:21 +0000 (19:43 +0100)
While most of the functionality was already in place, it turns out
that we need to enable loading/saving PeerPtr from/to a QVariant in
order for SignalProxy to work properly.

I'm honestly not sure why it seemed to work without this when implementing
the TransferManager, but it's obvious it's required.

src/common/peer.cpp
src/common/peer.h
src/common/quassel.cpp

index 1404159..3785326 100644 (file)
@@ -32,3 +32,22 @@ AuthHandler *Peer::authHandler() const
 {
     return _authHandler;
 }
+
+
+// Note that we need to use a fixed-size integer instead of uintptr_t, in order
+// to avoid issues with different architectures for client and core.
+// In practice, we'll never really have to restore the real value of a PeerPtr from
+// a QVariant.
+QDataStream &operator<<(QDataStream &out, PeerPtr ptr)
+{
+    out << reinterpret_cast<quint64>(ptr);
+    return out;
+}
+
+QDataStream &operator>>(QDataStream &in, PeerPtr &ptr)
+{
+    quint64 value;
+    in >> value;
+    ptr = reinterpret_cast<PeerPtr>(value);
+    return in;
+}
index a21e9c1..b9dfed1 100644 (file)
@@ -86,6 +86,9 @@ private:
 typedef Peer * PeerPtr;
 Q_DECLARE_METATYPE(PeerPtr)
 
+QDataStream &operator<<(QDataStream &out, PeerPtr ptr);
+QDataStream &operator>>(QDataStream &in, PeerPtr &ptr);
+
 
 // Template method needed in the header
 template<typename T> inline
index f43423c..c166ee6 100644 (file)
@@ -42,6 +42,7 @@
 #include "logger.h"
 #include "message.h"
 #include "network.h"
+#include "peer.h"
 #include "protocol.h"
 #include "syncableobject.h"
 #include "types.h"
@@ -203,6 +204,8 @@ void Quassel::registerMetaTypes()
     qRegisterMetaTypeStreamOperators<MsgId>("MsgId");
 
     qRegisterMetaType<Protocol::SessionState>("Protocol::SessionState");
+    qRegisterMetaType<PeerPtr>("PeerPtr");
+    qRegisterMetaTypeStreamOperators<PeerPtr>("PeerPtr");
 
     // Versions of Qt prior to 4.7 didn't define QVariant as a meta type
     if (!QMetaType::type("QVariant")) {