[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:       2010-04-14 13:27:56
Message-ID: 20100414132756.D7E0CAC898 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1114769 by trueg:

Ported to QDBusServiceWatcher and while at it fixed a bug where a service that had \
only been attached to was not restarted after it went down. Thanks to Vishesh Handa \
for the initial patch.

CCMAIL: handa.vish@gmail.com


 M  +28 -12    servicecontroller.cpp  
 M  +2 -3      servicecontroller.h  
 M  +2 -33     servicemanager.cpp  


--- trunk/KDE/kdebase/runtime/nepomuk/server/servicecontroller.cpp #1114768:1114769
@@ -24,13 +24,15 @@
 #include <QtCore/QEventLoop>
 #include <QtCore/QTimer>
 
+#include <QtDBus/QDBusServiceWatcher>
+
 #include <KStandardDirs>
 #include <KConfigGroup>
 #include <KDebug>
 
 
 namespace {
-    QString dbusServiceName( const QString& serviceName ) {
+    inline QString dbusServiceName( const QString& serviceName ) {
         return QString("org.kde.nepomuk.services.%1").arg(serviceName);
     }
 }
@@ -42,6 +44,7 @@
     Private()
         : processControl( 0 ),
           serviceControlInterface( 0 ),
+          dbusServiceWatcher( 0 ),
           attached( false ),
           initialized( false ),
           failedToInitialize( false ) {
@@ -54,6 +57,7 @@
 
     ProcessControl* processControl;
     OrgKdeNepomukServiceControlInterface* serviceControlInterface;
+    QDBusServiceWatcher* dbusServiceWatcher;
 
     // true if we attached to an already running instance instead of
     // starting our own (in that case processControl will be 0)
@@ -158,12 +162,25 @@
     d->initialized = false;
     d->failedToInitialize = false;
 
+    if ( !d->dbusServiceWatcher ) {
+        d->dbusServiceWatcher = new QDBusServiceWatcher( dbusServiceName(name()),
+                                                         \
QDBusConnection::sessionBus(), +                                                      \
QDBusServiceWatcher::WatchForRegistration | \
QDBusServiceWatcher::WatchForUnregistration, +                                        \
this ); +    }
+    d->dbusServiceWatcher->disconnect( this );
+
     // 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();
+
+        // we do not have ProcessControl to take care of restarting. Thus, we \
monitor the service via DBus +        connect( d->dbusServiceWatcher, SIGNAL( \
serviceUnregistered( QString ) ), +                 this, SLOT( \
slotServiceUnregistered( QString ) ) ); +
         return true;
     }
     else {
@@ -175,10 +192,9 @@
                      this, SLOT( slotProcessFinished( bool ) ) );
         }
 
-        connect( QDBusConnection::sessionBus().interface(),
-                 SIGNAL( serviceOwnerChanged( const QString&, const QString&, const \
                QString& ) ),
-                 this,
-                 SLOT( slotServiceOwnerChanged( const QString&, const QString&, \
const QString& ) ) ); +        // wait for the service to be registered with DBus \
before creating the service interface +        connect( d->dbusServiceWatcher, \
SIGNAL( serviceRegistered( QString ) ), +                 this, SLOT( \
slotServiceRegistered( QString ) ) );  
         d->processControl->setCrashPolicy( ProcessControl::RestartOnCrash );
         return d->processControl->start( KGlobal::dirs()->locate( "exe", \
"nepomukservicestub" ), @@ -265,19 +281,19 @@
 }
 
 
-void Nepomuk::ServiceController::slotServiceOwnerChanged( const QString& \
                serviceName,
-                                                          const QString& oldOwner,
-                                                          const QString& newOwner )
+void Nepomuk::ServiceController::slotServiceRegistered( const QString& serviceName )
 {
-    if( !newOwner.isEmpty() && serviceName == dbusServiceName( name() ) ) {
+    if( serviceName == dbusServiceName( name() ) ) {
         createServiceControlInterface();
     }
+}
 
+void Nepomuk::ServiceController::slotServiceUnregistered( const QString& serviceName \
) +{
     // 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() ) ) {
+    // to normal
+    if( d->attached && serviceName == dbusServiceName( name() ) ) {
         kDebug() << "Attached service" << name() << "went down. Restarting \
ourselves.";  d->attached = false;
         start();
--- trunk/KDE/kdebase/runtime/nepomuk/server/servicecontroller.h #1114768:1114769
@@ -80,9 +80,8 @@
         
     private Q_SLOTS:
         void slotProcessFinished( bool );
-        void slotServiceOwnerChanged( const QString& serviceName,
-                                      const QString&,
-                                      const QString& newOwner );
+        void slotServiceRegistered( const QString& serviceName );
+        void slotServiceUnregistered( const QString& serviceName );
         void slotServiceInitialized( bool success );
         
     private:
--- trunk/KDE/kdebase/runtime/nepomuk/server/servicemanager.cpp #1114768:1114769
@@ -327,39 +327,8 @@
 bool Nepomuk::ServiceManager::startService( const QString& name )
 {
     if( ServiceController* sc = d->findService( name ) ) {
-        if( !sc->isRunning() ) {
-            // start dependencies if possible
-            foreach( const QString &dependency, d->dependencyTree[name] ) {
-                if ( ServiceController* depSc = d->findService( dependency ) ) {
-                    if( depSc->autostart() || depSc->startOnDemand() ) {
-                        if ( !startService( dependency ) ) {
-                            kDebug() << "Cannot start dependency" << dependency;
-                            return false;
-                        }
-                    }
-                    else {
-                        kDebug() << "Dependency" << dependency << "can not be \
                started automatically. It is not an autostart or start on demand \
                service";
-                        return false;
-                    }
-                }
-                else {
-                    kDebug() << "Invalid dependency:" << dependency;
-                    return false;
-                }
-            }
-
-            if ( sc->start() ) {
-                return sc->waitForInitialized();
-            }
-            else {
-                // failed to start service
-                return false;
-            }
-        }
-        else {
-            // service already running
-            return true;
-        }
+        d->startService( sc );
+        return sc->waitForInitialized();
     }
     else {
         // could not find service


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic