Make NetworkPacket Metatype-capable

Summary: I am open to discussion for whether this is desireable. The use-case is for moving NetworkPacket receive handling to a thread other than the one handling the rest of the device. In order to do this, we need to use a QtConnectionType::QueuedConnection. In order for that to work (with NetworkPackets), NetworkPacket has to be registered in the Metatype system.

Test Plan: Nothing should be functionally different from before

Reviewers: #kde_connect, albertvaka

Reviewed By: #kde_connect, albertvaka

Subscribers: albertvaka, apol, nicolasfella, kdeconnect

Tags: #kde_connect

Differential Revision: https://phabricator.kde.org/D16469
This commit is contained in:
Simon Redman 2018-10-29 10:41:13 -06:00
parent 08b31ce258
commit 0f5c9cd96c
2 changed files with 12 additions and 1 deletions

View file

@ -55,6 +55,15 @@ NetworkPacket::NetworkPacket(const QString& type, const QVariantMap& body)
{
}
NetworkPacket::NetworkPacket(const NetworkPacket& other)
: m_id(other.m_id)
, m_type(other.m_type)
, m_body(QVariantMap(other.m_body))
, m_payload(other.m_payload)
, m_payloadSize(other.m_payloadSize)
{
}
void NetworkPacket::createIdentityPacket(NetworkPacket* np)
{
KdeConnectConfig* config = KdeConnectConfig::instance();

View file

@ -49,7 +49,8 @@ public:
//const static QCA::EncryptionAlgorithm EncryptionAlgorithm;
const static int s_protocolVersion;
explicit NetworkPacket(const QString& type, const QVariantMap& body = {});
explicit NetworkPacket(const QString& type = QStringLiteral("empty"), const QVariantMap& body = {});
NetworkPacket(const NetworkPacket& other); // Copy constructor, required for QMetaType and queued signals
static void createIdentityPacket(NetworkPacket*);
@ -97,5 +98,6 @@ private:
};
KDECONNECTCORE_EXPORT QDebug operator<<(QDebug s, const NetworkPacket& pkg);
Q_DECLARE_METATYPE(NetworkPacket)
#endif // NETWORKPACKET_H