aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/debugger/qqmldebugserver.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@theqtcompany.com>2015-07-13 15:56:25 +0200
committerUlf Hermann <ulf.hermann@theqtcompany.com>2015-07-31 06:44:13 +0000
commitcc3a57861d5ef6e84cef0adfa1aaf726dd2b9d84 (patch)
treeef5c3983cda85022afd077fe05a2cb850aa0274b /src/qml/debugger/qqmldebugserver.cpp
parent4d07a6254cac5742ffc23377b97c6eaf04aa4c49 (diff)
Use signal/slot for passing messages through QQmlDebugServer
This results in much cleaner code than the previous implementation using QMetaObject::invokeMethod(). We have to use read locks now for adding and removing engines, as we should have done already before. If a condition is waiting on a write lock you cannot acquire a read lock from another thread. So, if we kept the write locks we wouldn't be able to receive messages while the engines are waiting. Change-Id: Icfe641601dec2f8d7181ae579146ed603d57a4c2 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/qml/debugger/qqmldebugserver.cpp')
-rw-r--r--src/qml/debugger/qqmldebugserver.cpp62
1 files changed, 40 insertions, 22 deletions
diff --git a/src/qml/debugger/qqmldebugserver.cpp b/src/qml/debugger/qqmldebugserver.cpp
index c48424f0fd..a2cb8fd5a1 100644
--- a/src/qml/debugger/qqmldebugserver.cpp
+++ b/src/qml/debugger/qqmldebugserver.cpp
@@ -102,7 +102,6 @@ public:
bool open(const QVariantHash &configuration);
void receiveMessage(const QByteArray &message);
- void sendMessages(QQmlDebugService *service, const QList<QByteArray> &messages);
template<class Action>
bool enable(Action action);
@@ -110,7 +109,8 @@ public:
private slots:
void wakeEngine(QQmlEngine *engine);
- void sendMessages(const QList<QByteArray> &messages);
+ void sendMessage(const QString &name, const QByteArray &message);
+ void sendMessages(const QString &name, const QList<QByteArray> &messages);
void changeServiceState(const QString &serviceName, QQmlDebugService::State state);
void removeThread();
@@ -623,15 +623,6 @@ void QQmlDebugServerImpl::changeServiceState(const QString &serviceName,
m_changeServiceStateCalls.deref();
}
-void QQmlDebugServerImpl::sendMessages(const QList<QByteArray> &messages)
-{
- // to be executed in debugger thread
- Q_ASSERT(QThread::currentThread() == thread());
-
- if (m_connection)
- m_connection->send(messages);
-}
-
void QQmlDebugServerImpl::removeThread()
{
Q_ASSERT(m_thread->isFinished());
@@ -690,6 +681,11 @@ bool QQmlDebugServerImpl::addService(QQmlDebugService *service)
// to be executed before thread starts
Q_ASSERT(!m_thread);
+ connect(service, SIGNAL(messageToClient(QString,QByteArray)),
+ this, SLOT(sendMessage(QString,QByteArray)));
+ connect(service, SIGNAL(messagesToClient(QString,QList<QByteArray>)),
+ this, SLOT(sendMessages(QString,QList<QByteArray>)));
+
connect(service, SIGNAL(attachedToEngine(QQmlEngine*)),
this, SLOT(wakeEngine(QQmlEngine*)), Qt::QueuedConnection);
connect(service, SIGNAL(detachedFromEngine(QQmlEngine*)),
@@ -720,24 +716,46 @@ bool QQmlDebugServerImpl::removeService(QQmlDebugService *service)
if (!service || !m_plugins.contains(service->name()))
return false;
+
+ disconnect(service, SIGNAL(messagesToClient(QString,QList<QByteArray>)),
+ this, SLOT(sendMessages(QString,QList<QByteArray>)));
+ disconnect(service, SIGNAL(messageToClient(QString,QByteArray)),
+ this, SLOT(sendMessage(QString,QByteArray)));
+
m_plugins.remove(service->name());
return true;
}
-void QQmlDebugServerImpl::sendMessages(QQmlDebugService *service, const QList<QByteArray> &messages)
+void QQmlDebugServerImpl::sendMessage(const QString &name, const QByteArray &message)
{
- QList<QByteArray> prefixedMessages;
- prefixedMessages.reserve(messages.count());
- foreach (const QByteArray &message, messages) {
- QByteArray prefixed;
- QQmlDebugStream out(&prefixed, QIODevice::WriteOnly);
- out << service->name() << message;
- prefixedMessages << prefixed;
- }
+ sendMessages(name, QList<QByteArray>() << message);
+}
- QMetaObject::invokeMethod(this, "sendMessages", Qt::QueuedConnection,
- Q_ARG(QList<QByteArray>, prefixedMessages));
+void QQmlDebugServerImpl::sendMessages(const QString &name, const QList<QByteArray> &messages)
+{
+ // to be executed in debugger thread
+ Q_ASSERT(QThread::currentThread() == thread());
+
+ if (!m_connection)
+ return;
+
+ if (!name.isEmpty()) {
+ if (!m_clientPlugins.contains(name))
+ return;
+ QList<QByteArray> prefixedMessages;
+ prefixedMessages.reserve(messages.count());
+ foreach (const QByteArray &message, messages) {
+ QByteArray prefixed;
+ QQmlDebugStream out(&prefixed, QIODevice::WriteOnly);
+ out << name << message;
+ prefixedMessages << prefixed;
+ }
+
+ m_connection->send(prefixedMessages);
+ } else {
+ m_connection->send(messages);
+ }
}
template<class Action>