Services now have to call registerService() themselves in the constructor.
This fixes a race condition where the empty implementation of messageReceived()
was called instead of the one in the subclass because the object wasn't fully
constructed yet.
Change-Id: I590ec8b76e906bdb6b5cdcb18680938edde283ee
Reviewed-by: Aurindam Jana <aurindam.jana@nokia.com>
d->server = QDeclarativeDebugServer::instance();
d->status = QDeclarativeDebugService::NotConnected;
- if (!d->server)
- return;
-
- if (d->server->serviceNames().contains(name)) {
- qWarning() << "QDeclarativeDebugService: Conflicting plugin name" << name;
+ if (d->server->serviceNames().contains(d->name)) {
+ qWarning() << "QDeclarativeDebugService: Conflicting plugin name" << d->name;
d->server = 0;
- } else {
- d->server->addService(this);
}
}
d->name = name;
d->server = QDeclarativeDebugServer::instance();
d->status = QDeclarativeDebugService::NotConnected;
+}
+/**
+ Registers the service. This should be called in the constructor of the inherited class. From
+ then on the service might get asynchronous calls to messageReceived().
+ */
+QDeclarativeDebugService::Status QDeclarativeDebugService::registerService()
+{
+ Q_D(QDeclarativeDebugService);
if (!d->server)
- return;
+ return NotConnected;
- if (d->server->serviceNames().contains(name)) {
- qWarning() << "QDeclarativeDebugService: Conflicting plugin name" << name;
- d->server = 0;
- } else {
- d->server->addService(this);
- }
+ d->server->addService(this);
+ return status();
}
QDeclarativeDebugService::~QDeclarativeDebugService()
protected:
QDeclarativeDebugService(QDeclarativeDebugServicePrivate &dd, const QString &, QObject *parent = 0);
+
+ Status registerService();
+
virtual void statusChanged(Status);
virtual void messageReceived(const QByteArray &);
m_enabled(false), m_messageReceived(false)
{
m_timer.start();
- if (status() == Enabled) {
+
+ if (registerService() == Enabled) {
// wait for first message indicating whether to trace or not
while (!m_messageReceived)
waitForMessage();
{
QObject::connect(m_watch, SIGNAL(propertyChanged(int,int,QMetaProperty,QVariant)),
this, SLOT(propertyChanged(int,int,QMetaProperty,QVariant)));
+
+ registerService();
}
QDataStream &operator<<(QDataStream &ds,
: QDeclarativeDebugService(QLatin1String("QDeclarativeObserverMode"))
, m_currentInspectorPlugin(0)
{
+ registerService();
}
QDeclarativeInspectorService *QDeclarativeInspectorService::instance()
// profiler in Qt Creator.
v8::Debug::GetDebugContext();
- if (status() == Enabled) {
+ if (registerService() == Enabled) {
// ,block mode, client attached
while (!d->initialized) {
waitForMessage();
: QDeclarativeDebugService(*(new QV8ProfilerServicePrivate()), QLatin1String("V8Profiler"), parent)
{
Q_D(QV8ProfilerService);
- if (status() == Enabled) {
+
+ if (registerService() == Enabled) {
// ,block mode, client attached
while (!d->initialized)
waitForMessage();
QTRY_COMPARE(service.status(), QDeclarativeDebugService::Unavailable);
QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugService: Conflicting plugin name \"tst_QDeclarativeDebugService::status()\" ");
-
- QDeclarativeDebugService duplicate("tst_QDeclarativeDebugService::status()");
+ QDeclarativeDebugTestService duplicate("tst_QDeclarativeDebugService::status()");
QCOMPARE(duplicate.status(), QDeclarativeDebugService::NotConnected);
}
QCOMPARE(resp, msg);
QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugService: Conflicting plugin name \"tst_QDeclarativeDebugService::sendMessage()\" ");
- QDeclarativeDebugService duplicate("tst_QDeclarativeDebugService::sendMessage()");
+ QDeclarativeDebugTestService duplicate("tst_QDeclarativeDebugService::sendMessage()");
duplicate.sendMessage("msg");
}
QDeclarativeDebugTestService::QDeclarativeDebugTestService(const QString &s, QObject *parent)
: QDeclarativeDebugService(s, parent)
{
+ registerService();
}
void QDeclarativeDebugTestService::messageReceived(const QByteArray &ba)