[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase/runtime/nepomuk/server
From: Sebastian Trueg <sebastian () trueg ! de>
Date: 2008-04-29 8:20:01
Message-ID: 1209457201.384988.28590.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 802365 by trueg:
Allow the server to attach to already running service instances.
M +2 -13 processcontrol.cpp
M +67 -26 servicecontroller.cpp
M +7 -0 servicecontroller.h
--- trunk/KDE/kdebase/runtime/nepomuk/server/processcontrol.cpp #802364:802365
@@ -96,19 +96,8 @@
if ( exitCode != 0 ) {
qDebug( "ProcessControl: Application '%s' returned with exit code %d \
(%s)",
qPrintable( mApplication ), exitCode, qPrintable( \
mProcess.errorString() ) );
- if ( mPolicy == RestartOnCrash ) {
- if ( mCrashCount > 3 ) {
- qWarning() << mApplication << "crashed too often and will not be \
restarted!";
- mPolicy = StopOnCrash;
- return;
- }
- ++mCrashCount;
- QTimer::singleShot( 5000, this, SLOT(resetCrashCount()) );
- if ( !mFailedToStart ) // don't try to start an unstartable \
application
- start();
- else
- emit finished(false);
- }
+ mFailedToStart = true;
+ emit finished(false);
} else {
qDebug( "Application '%s' exited normally...", qPrintable( mApplication \
) ); emit finished(true);
--- trunk/KDE/kdebase/runtime/nepomuk/server/servicecontroller.cpp #802364:802365
@@ -42,6 +42,7 @@
Private()
: processControl( 0 ),
serviceControlInterface( 0 ),
+ attached(false),
initialized( false ) {
}
@@ -53,6 +54,10 @@
ProcessControl* processControl;
OrgKdeNepomukServiceControlInterface* serviceControlInterface;
+ // true if we attached to an already running instance instead of
+ // starting our own (in that case processControl will be 0)
+ bool attached;
+
bool initialized;
// list of loops waiting for the service to become initialized
@@ -148,23 +153,33 @@
return true;
}
- kDebug(300002) << "Starting" << name();
-
d->initialized = false;
- if( !d->processControl ) {
- d->processControl = new ProcessControl( this );
- connect( d->processControl, SIGNAL( finished( bool ) ),
- this, SLOT( slotProcessFinished( bool ) ) );
+ // check if the service is already running, ie. has been started by someone else \
or by a crashed instance of the server + // we cannot rely on the auto-restart \
feature of ProcessControl here. So we handle that completely in \
slotServiceOwnerChanged + if( \
QDBusConnection::sessionBus().interface()->isServiceRegistered( dbusServiceName( \
name() ) ) ) { + kDebug() << "Attaching to already running service" << name();
+ d->attached = true;
+ createServiceControlInterface();
+ return true;
}
+ else {
+ kDebug(300002) << "Starting" << name();
- connect( QDBusConnection::sessionBus().interface(),
- SIGNAL( serviceOwnerChanged( const QString&, const QString&, const \
QString& ) ),
- this,
- SLOT( slotServiceOwnerChanged( const QString&, const QString&, const \
QString& ) ) ); + if( !d->processControl ) {
+ d->processControl = new ProcessControl( this );
+ connect( d->processControl, SIGNAL( finished( bool ) ),
+ this, SLOT( slotProcessFinished( bool ) ) );
+ }
- return d->processControl->start( KGlobal::dirs()->locate( "exe", \
"nepomukservicestub" ),
- QStringList() << name() );
+ connect( QDBusConnection::sessionBus().interface(),
+ SIGNAL( serviceOwnerChanged( const QString&, const QString&, const \
QString& ) ), + this,
+ SLOT( slotServiceOwnerChanged( const QString&, const QString&, \
const QString& ) ) ); +
+ return d->processControl->start( KGlobal::dirs()->locate( "exe", \
"nepomukservicestub" ), + QStringList() << \
name() ); + }
}
@@ -172,17 +187,25 @@
{
if( isRunning() ) {
kDebug(300002) << "Stopping" << name();
- d->processControl->setCrashPolicy( ProcessControl::StopOnCrash );
+
+ d->attached = false;
+
+ if( d->processControl ) {
+ d->processControl->setCrashPolicy( ProcessControl::StopOnCrash );
+ }
d->serviceControlInterface->shutdown();
- d->processControl->stop();
- d->processControl->setCrashPolicy( ProcessControl::RestartOnCrash );
+
+ if( d->processControl ) {
+ d->processControl->stop();
+ d->processControl->setCrashPolicy( ProcessControl::RestartOnCrash );
+ }
}
}
bool Nepomuk::ServiceController::isRunning() const
{
- return d->processControl ? d->processControl->isRunning() : false;
+ return( d->attached || ( d->processControl ? d->processControl->isRunning() : \
false ) ); }
@@ -226,24 +249,42 @@
void Nepomuk::ServiceController::slotServiceOwnerChanged( const QString& \
serviceName,
- const QString&,
+ const QString& oldOwner,
const QString& newOwner )
{
if( !newOwner.isEmpty() && serviceName == dbusServiceName( name() ) ) {
- d->serviceControlInterface = new OrgKdeNepomukServiceControlInterface( \
serviceName,
- \
"/servicecontrol",
- \
QDBusConnection::sessionBus(),
- this \
);
- connect( d->serviceControlInterface, SIGNAL( serviceInitialized( bool ) ),
- this, SLOT( slotServiceInitialized( bool ) ) );
+ createServiceControlInterface();
+ }
- if ( d->serviceControlInterface->isInitialized() ) {
- slotServiceInitialized( true );
- }
+ // an attached service was not started through ProcessControl. Thus, we cannot \
rely + // on its restart-on-crash feature and have to do it manually. Afterwards \
it is back + // to normals
+ else if( d->attached &&
+ oldOwner == dbusServiceName( name() ) ) {
+ kDebug() << "Attached service" << name() << "went down. Restarting \
ourselves."; + d->attached = false;
+ start();
}
}
+void Nepomuk::ServiceController::createServiceControlInterface()
+{
+ delete d->serviceControlInterface;
+
+ d->serviceControlInterface = new OrgKdeNepomukServiceControlInterface( \
dbusServiceName( name() ), + \
"/servicecontrol", + \
QDBusConnection::sessionBus(), + \
this ); + connect( d->serviceControlInterface, SIGNAL( serviceInitialized( bool ) \
), + this, SLOT( slotServiceInitialized( bool ) ) );
+
+ if ( d->serviceControlInterface->isInitialized() ) {
+ slotServiceInitialized( true );
+ }
+}
+
+
void Nepomuk::ServiceController::slotServiceInitialized( bool success )
{
if ( !d->initialized ) {
--- trunk/KDE/kdebase/runtime/nepomuk/server/servicecontroller.h #802364:802365
@@ -50,6 +50,11 @@
void setAutostart( bool enable );
+ /**
+ * Make sure the service is running. This will attach to an already running
+ * instance or simple return \p true in case the service has been started
+ * already.
+ */
bool start();
void stop();
@@ -81,6 +86,8 @@
void slotServiceInitialized( bool success );
private:
+ void createServiceControlInterface();
+
class Private;
Private* const d;
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic