From 92b4c1abcfc64855cd73733f136a86435e562beb Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Mon, 21 Nov 2011 16:03:53 +0100 Subject: Debugger: Make registration of services explicit 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 --- .../debugger/qdeclarativedebugservice.cpp | 27 +++++++++++----------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src/declarative/debugger/qdeclarativedebugservice.cpp') diff --git a/src/declarative/debugger/qdeclarativedebugservice.cpp b/src/declarative/debugger/qdeclarativedebugservice.cpp index be60ea4609..0a997aa2fe 100644 --- a/src/declarative/debugger/qdeclarativedebugservice.cpp +++ b/src/declarative/debugger/qdeclarativedebugservice.cpp @@ -61,14 +61,9 @@ QDeclarativeDebugService::QDeclarativeDebugService(const QString &name, QObject 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); } } @@ -80,16 +75,20 @@ QDeclarativeDebugService::QDeclarativeDebugService(QDeclarativeDebugServicePriva 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() -- cgit v1.2.3