aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@theqtcompany.com>2015-07-16 16:17:17 +0200
committerUlf Hermann <ulf.hermann@theqtcompany.com>2015-08-04 13:35:18 +0000
commit275ddd68af1881c5712848a4be9892f84b62b321 (patch)
treedf846963158857e8b84a66f2d6e64f2528f0363e
parent20d06b5e822cc301e31f77a87915eed62195eb92 (diff)
Clean up QQmlDebugConnector's addService() and removeService()
As we look up services by name we should also add and remove them by name. As the thread doesn't run during adding and removing of services we don't have to check the client plugins for the initial state. It's also a good idea to eventually disconnect any signals that we connect on addService(). Change-Id: I9acd17d2caafe15831f32b7b959dc2dea9cab08c Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
-rw-r--r--src/plugins/qmltooling/qmldbg_server/qqmldebugserver.cpp36
-rw-r--r--src/qml/debugger/qqmldebugconnector_p.h4
-rw-r--r--src/qml/debugger/qqmldebugservice.cpp4
3 files changed, 22 insertions, 22 deletions
diff --git a/src/plugins/qmltooling/qmldbg_server/qqmldebugserver.cpp b/src/plugins/qmltooling/qmldbg_server/qqmldebugserver.cpp
index 91982b415c..1459ab8759 100644
--- a/src/plugins/qmltooling/qmldbg_server/qqmldebugserver.cpp
+++ b/src/plugins/qmltooling/qmldbg_server/qqmldebugserver.cpp
@@ -94,8 +94,8 @@ public:
void addEngine(QQmlEngine *engine);
void removeEngine(QQmlEngine *engine);
- bool addService(QQmlDebugService *service);
- bool removeService(QQmlDebugService *service);
+ bool addService(const QString &name, QQmlDebugService *service);
+ bool removeService(const QString &name);
bool open(const QVariantHash &configuration);
void setDevice(QIODevice *socket);
@@ -601,11 +601,14 @@ void QQmlDebugServerImpl::removeEngine(QQmlEngine *engine)
service->engineRemoved(engine);
}
-bool QQmlDebugServerImpl::addService(QQmlDebugService *service)
+bool QQmlDebugServerImpl::addService(const QString &name, QQmlDebugService *service)
{
// to be executed before thread starts
Q_ASSERT(!m_thread);
+ if (!service || m_plugins.contains(name))
+ return false;
+
connect(service, SIGNAL(messageToClient(QString,QByteArray)),
this, SLOT(sendMessage(QString,QByteArray)));
connect(service, SIGNAL(messagesToClient(QString,QList<QByteArray>)),
@@ -616,31 +619,28 @@ bool QQmlDebugServerImpl::addService(QQmlDebugService *service)
connect(service, SIGNAL(detachedFromEngine(QQmlEngine*)),
this, SLOT(wakeEngine(QQmlEngine*)), Qt::QueuedConnection);
+ service->setState(QQmlDebugService::Unavailable);
+ m_plugins.insert(name, service);
- if (!service || m_plugins.contains(service->name()))
- return false;
- m_plugins.insert(service->name(), service);
- QQmlDebugService::State newState = QQmlDebugService::Unavailable;
- if (m_clientPlugins.contains(service->name()))
- newState = QQmlDebugService::Enabled;
- service->setState(newState);
return true;
}
-bool QQmlDebugServerImpl::removeService(QQmlDebugService *service)
+bool QQmlDebugServerImpl::removeService(const QString &name)
{
// to be executed after thread ends
Q_ASSERT(!m_thread);
- QQmlDebugService::State newState = QQmlDebugService::NotConnected;
+ QQmlDebugService *service = m_plugins.value(name);
+ if (!service)
+ return false;
- m_changeServiceStateCalls.ref();
- QMetaObject::invokeMethod(this, "changeServiceState", Qt::QueuedConnection,
- Q_ARG(QString, service->name()),
- Q_ARG(QQmlDebugService::State, newState));
+ m_plugins.remove(name);
+ service->setState(QQmlDebugService::NotConnected);
- if (!service || !m_plugins.contains(service->name()))
- return false;
+ disconnect(service, SIGNAL(detachedFromEngine(QQmlEngine*)),
+ this, SLOT(wakeEngine(QQmlEngine*)));
+ disconnect(service, SIGNAL(attachedToEngine(QQmlEngine*)),
+ this, SLOT(wakeEngine(QQmlEngine*)));
disconnect(service, SIGNAL(messagesToClient(QString,QList<QByteArray>)),
this, SLOT(sendMessages(QString,QList<QByteArray>)));
diff --git a/src/qml/debugger/qqmldebugconnector_p.h b/src/qml/debugger/qqmldebugconnector_p.h
index a4531bf1a9..02e94811a6 100644
--- a/src/qml/debugger/qqmldebugconnector_p.h
+++ b/src/qml/debugger/qqmldebugconnector_p.h
@@ -67,8 +67,8 @@ public:
virtual void addEngine(QQmlEngine *engine) = 0;
virtual void removeEngine(QQmlEngine *engine) = 0;
- virtual bool addService(QQmlDebugService *service) = 0;
- virtual bool removeService(QQmlDebugService *service) = 0;
+ virtual bool addService(const QString &name, QQmlDebugService *service) = 0;
+ virtual bool removeService(const QString &name) = 0;
virtual bool open(const QVariantHash &configuration = QVariantHash()) = 0;
diff --git a/src/qml/debugger/qqmldebugservice.cpp b/src/qml/debugger/qqmldebugservice.cpp
index 3a69799da8..0b07f320ec 100644
--- a/src/qml/debugger/qqmldebugservice.cpp
+++ b/src/qml/debugger/qqmldebugservice.cpp
@@ -72,7 +72,7 @@ QQmlDebugService::QQmlDebugService(const QString &name, float version, QObject *
if (server->service(d->name)) {
qWarning() << "QQmlDebugService: Conflicting plugin name" << d->name;
} else {
- server->addService(this);
+ server->addService(d->name, this);
}
}
@@ -87,7 +87,7 @@ QQmlDebugService::~QQmlDebugService()
if (server->service(d->name) != this)
qWarning() << "QQmlDebugService: Plugin" << d->name << "is not registered.";
else
- server->removeService(this);
+ server->removeService(d->name);
}
const QString &QQmlDebugService::name() const