Commit 6b2cad3e authored by Ulf Hermann's avatar Ulf Hermann

QmlDebug: Use proper interfaces between debug connection and client

Mutual friend declarations are not the most beautiful thing ...

Change-Id: I0f3c2a3c0cb9bc018b63d73b463a9068278e705e
Reviewed-by: default avatarJoerg Bornemann <joerg.bornemann@theqtcompany.com>
parent db6a6521
......@@ -299,12 +299,51 @@ void QmlDebugConnection::close()
d->device->close(); // will trigger disconnected() at some point.
}
QmlDebugClient *QmlDebugConnection::client(const QString &name) const
{
Q_D(const QmlDebugConnection);
return d->plugins.value(name, 0);
}
bool QmlDebugConnection::addClient(const QString &name, QmlDebugClient *client)
{
Q_D(QmlDebugConnection);
if (d->plugins.contains(name))
return false;
d->plugins.insert(name, client);
d->advertisePlugins();
return true;
}
bool QmlDebugConnection::removeClient(const QString &name)
{
Q_D(QmlDebugConnection);
if (!d->plugins.contains(name))
return false;
d->plugins.remove(name);
d->advertisePlugins();
return true;
}
float QmlDebugConnection::serviceVersion(const QString &serviceName) const
{
Q_D(const QmlDebugConnection);
return d->serverPlugins.value(serviceName, -1);
}
bool QmlDebugConnection::sendMessage(const QString &name, const QByteArray &message)
{
Q_D(QmlDebugConnection);
if (!d->gotHello || !d->serverPlugins.contains(name))
return false;
QPacket pack(d->currentDataStreamVersion);
pack << name << message;
d->protocol->send(pack.data());
d->flush();
return true;
}
void QmlDebugConnectionPrivate::flush()
{
QAbstractSocket *socket = qobject_cast<QAbstractSocket*>(device);
......@@ -349,8 +388,7 @@ QmlDebugClientPrivate::QmlDebugClientPrivate()
{
}
QmlDebugClient::QmlDebugClient(const QString &name,
QmlDebugConnection *parent)
QmlDebugClient::QmlDebugClient(const QString &name, QmlDebugConnection *parent)
: QObject(parent), d_ptr(new QmlDebugClientPrivate())
{
Q_D(QmlDebugClient);
......@@ -360,22 +398,15 @@ QmlDebugClient::QmlDebugClient(const QString &name,
if (!d->connection)
return;
if (d->connection->d->plugins.contains(name)) {
qWarning() << "QML Debug Client: Conflicting plugin name" << name;
d->connection = 0;
} else {
d->connection->d->plugins.insert(name, this);
d->connection->d->advertisePlugins();
}
d->connection->addClient(name, this);
}
QmlDebugClient::~QmlDebugClient()
{
Q_D(const QmlDebugClient);
if (d->connection && d->connection->d) {
d->connection->d->plugins.remove(d->name);
d->connection->d->advertisePlugins();
}
if (d->connection)
d->connection->removeClient(d->name);
}
QString QmlDebugClient::name() const
......@@ -402,7 +433,7 @@ QmlDebugClient::State QmlDebugClient::state() const
if (!d->connection || !d->connection->isConnected())
return NotConnected;
if (d->connection->d->serverPlugins.contains(d->name))
if (d->connection->client(d->name) == this)
return Enabled;
return Unavailable;
......@@ -420,10 +451,7 @@ void QmlDebugClient::sendMessage(const QByteArray &message)
if (state() != Enabled)
return;
QPacket pack(d->connection->currentDataStreamVersion());
pack << d->name << message;
d->connection->d->protocol->send(pack.data());
d->connection->d->flush();
d->connection->sendMessage(d->name, message);
}
void QmlDebugClient::stateChanged(State)
......
......@@ -38,6 +38,7 @@
namespace QmlDebug {
class QmlDebugClient;
class QmlDebugConnectionPrivate;
class QMLDEBUG_EXPORT QmlDebugConnection : public QObject
{
......@@ -57,7 +58,13 @@ public:
bool isConnecting() const;
void close();
QmlDebugClient *client(const QString &name) const;
bool addClient(const QString &name, QmlDebugClient *client);
bool removeClient(const QString &name);
float serviceVersion(const QString &serviceName) const;
bool sendMessage(const QString &name, const QByteArray &message);
static QString socketStateToString(QAbstractSocket::SocketState state);
static QString socketErrorToString(QAbstractSocket::SocketError error);
......@@ -74,8 +81,6 @@ private slots:
private:
QScopedPointer<QmlDebugConnectionPrivate> d_ptr;
friend class QmlDebugClient;
friend class QmlDebugClientPrivate;
};
class QmlDebugClientPrivate;
......@@ -104,10 +109,7 @@ protected:
private:
friend class QmlDebugConnection;
friend class QmlDebugConnectionPrivate;
QScopedPointer<QmlDebugClientPrivate> d_ptr;
};
} // namespace QmlDebug
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment