aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmltooling/packetprotocol/qpacketprotocol.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@theqtcompany.com>2015-11-03 14:32:25 +0100
committerUlf Hermann <ulf.hermann@theqtcompany.com>2015-11-17 18:42:07 +0000
commit0b67dd7e132d7d618fa538e8c4a275c874543342 (patch)
tree3c6c7cdf8fbae8c6a7d0d333d96c22d130413980 /src/plugins/qmltooling/packetprotocol/qpacketprotocol.cpp
parente010b64d38cb8533d779ac0fe8d609f00a6793e7 (diff)
QmlDebug: Restructure QPacket and QPacketProtocol
We cannot use the same data stream version for the client and server versions of QPacket and QPacketProtocol should not deal with QPackets but with simple byte arrays because the underlying QDataStream is hard to copy. The new QQmlDebugPacket picks its data stream version from QQmlDebugConnector now, which adjusts it when connecting. As there can only ever be one QQmlDebugConnector, we can keep the version static. The clients need to query the connection for the correct version. We may connect to several different servers sequentially or we may have a server running while using a client, and we don't want to confuse the versions between those. With this in place, all remaining occurrences of QDataStream are replaced with QPacket or QQmlDebugPacket. Change-Id: I3f6ba73fcbfad5e8df917c5feb9308116738a614 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/plugins/qmltooling/packetprotocol/qpacketprotocol.cpp')
-rw-r--r--src/plugins/qmltooling/packetprotocol/qpacketprotocol.cpp31
1 files changed, 11 insertions, 20 deletions
diff --git a/src/plugins/qmltooling/packetprotocol/qpacketprotocol.cpp b/src/plugins/qmltooling/packetprotocol/qpacketprotocol.cpp
index 9f9dbfee90..d576e74e53 100644
--- a/src/plugins/qmltooling/packetprotocol/qpacketprotocol.cpp
+++ b/src/plugins/qmltooling/packetprotocol/qpacketprotocol.cpp
@@ -36,7 +36,6 @@
#include <QtCore/QElapsedTimer>
#include <private/qiodevice_p.h>
#include <private/qobject_p.h>
-#include <private/qpacket_p.h>
QT_BEGIN_NAMESPACE
@@ -63,9 +62,8 @@ static const int MAX_PACKET_SIZE = 0x7FFFFFFF;
QPacketProtocol does not perform any communications itself. Instead it can
operate on any QIODevice that supports the QIODevice::readyRead() signal. A
- logical "packet" is encapsulated by the companion QPacket class. The
- following example shows two ways to send data using QPacketProtocol. The
- transmitted data is equivalent in both.
+ logical "packet" is simply a QByteArray. The following example how to send
+ data using QPacketProtocol.
\code
QTcpSocket socket;
@@ -74,9 +72,9 @@ static const int MAX_PACKET_SIZE = 0x7FFFFFFF;
QPacketProtocol protocol(&socket);
// Send a packet
- QPacket packet;
+ QDataStream packet;
packet << "Hello world" << 123;
- protocol.send(packet);
+ protocol.send(packet.data());
\endcode
Likewise, the following shows how to read data from QPacketProtocol, assuming
@@ -88,16 +86,12 @@ static const int MAX_PACKET_SIZE = 0x7FFFFFFF;
int a;
QByteArray b;
- // Receive packet the quick way
- protocol.read() >> a >> b;
-
- // Receive packet the longer way
- QPacket packet = protocol.read();
+ // Receive packet
+ QDataStream packet(protocol.read());
p >> a >> b;
\endcode
\ingroup io
- \sa QPacket
*/
class QPacketProtocolPrivate : public QObjectPrivate
@@ -133,15 +127,14 @@ QPacketProtocol::QPacketProtocol(QIODevice *dev, QObject *parent)
}
/*!
- \fn void QPacketProtocol::send(const QPacket & packet)
+ \fn void QPacketProtocol::send(const QByteArray &data)
Transmit the \a packet.
*/
-void QPacketProtocol::send(const QPacket & p)
+void QPacketProtocol::send(const QByteArray &data)
{
Q_D(QPacketProtocol);
- QByteArray data = p.data();
if (data.isEmpty())
return; // We don't send empty packets
qint64 sendSize = data.size() + sizeof(qint32);
@@ -165,15 +158,13 @@ qint64 QPacketProtocol::packetsAvailable() const
}
/*!
- Return the next unread packet, or an invalid QPacket instance if no packets
+ Return the next unread packet, or an empty QByteArray if no packets
are available. This method does NOT block.
*/
-QPacket QPacketProtocol::read()
+QByteArray QPacketProtocol::read()
{
Q_D(QPacketProtocol);
-
- // Hope for in-place construction here, until we get move semantics for QBuffer
- return QPacket(d->packets.isEmpty() ? QByteArray() : d->packets.takeFirst());
+ return d->packets.isEmpty() ? QByteArray() : d->packets.takeFirst();
}
/*!