[Kde-bindings] [kdepimlibs/KDE/4.13] akonadi: add a new method setTemporaryOffline() to temporarily halt an agent

Martin Koller kollix at aon.at
Tue Mar 18 19:19:05 UTC 2014


Git commit 28599e5262671f26c969271fc886294736ef5d5a by Martin Koller.
Committed on 18/03/2014 at 19:14.
Pushed by mkoller into branch 'KDE/4.13'.

add a new method setTemporaryOffline() to temporarily halt an agent
to restart after some timeout

A resource/agent which detects that it can currently not continue
to work correctly shall be able to set itself temporarily to offline
and shall retry to continue with the pending actions after some timeout.
This patch adds a new method to allow this.

CCMAIL: kde-bindings at kde.org
REVIEW: 116826

M  +32   -1    akonadi/agentbase.cpp
M  +26   -0    akonadi/agentbase.h
M  +4    -0    akonadi/agentbase_p.h

http://commits.kde.org/kdepimlibs/28599e5262671f26c969271fc886294736ef5d5a

diff --git a/akonadi/agentbase.cpp b/akonadi/agentbase.cpp
index 4e51824..373574c 100644
--- a/akonadi/agentbase.cpp
+++ b/akonadi/agentbase.cpp
@@ -302,7 +302,8 @@ AgentBasePrivate::AgentBasePrivate( AgentBase *parent )
     mSettings( 0 ),
     mChangeRecorder( 0 ),
     mTracer( 0 ),
-    mObserver( 0 )
+    mObserver(0),
+    mTemporaryOfflineTimer(0)
 {
   Internal::setClientType( Internal::Agent );
 }
@@ -750,6 +751,12 @@ void AgentBasePrivate::slotResumedFromSuspend()
   }
 }
 
+void AgentBasePrivate::slotTemporaryOfflineTimeout()
+{
+  Q_Q(AgentBase);
+  q->setOnlineInternal(true);
+}
+
 QString AgentBasePrivate::dumpNotificationListToString() const
 {
   return mChangeRecorder->dumpNotificationListToString();
@@ -915,11 +922,35 @@ void AgentBase::setOnline( bool state )
   setOnlineInternal( state );
 }
 
+void AgentBase::setTemporaryOffline(int makeOnlineInSeconds)
+{
+  Q_D(AgentBase);
+
+  // if not currently online, avoid bringing it online after the timeout
+  if (!d->mOnline) {
+      return;
+  }
+
+  setOnlineInternal(false);
+
+  if (!d->mTemporaryOfflineTimer) {
+      d->mTemporaryOfflineTimer = new QTimer(d);
+      d->mTemporaryOfflineTimer->setSingleShot(true);
+      connect(d->mTemporaryOfflineTimer, SIGNAL(timeout()), this, SLOT(slotTemporaryOfflineTimeout()));
+  }
+  d->mTemporaryOfflineTimer->setInterval(makeOnlineInSeconds * 1000);
+  d->mTemporaryOfflineTimer->start();
+}
+
 void AgentBase::setOnlineInternal( bool state )
 {
   Q_D( AgentBase );
   d->mOnline = state;
 
+  if (d->mTemporaryOfflineTimer) {
+      d->mTemporaryOfflineTimer->stop();
+  }
+
   const QString newMessage = d->defaultReadyMessage();
   if ( d->mStatusMessage != newMessage && d->mStatusCode != AgentBase::Broken ) {
     emit status( d->mStatusCode, newMessage );
diff --git a/akonadi/agentbase.h b/akonadi/agentbase.h
index 4671c80..515e933 100644
--- a/akonadi/agentbase.h
+++ b/akonadi/agentbase.h
@@ -711,6 +711,31 @@ class AKONADI_EXPORT AgentBase : public QObject, protected QDBusContext
      */
     void setOnline( bool state );
 
+    /**
+      * Sets the agent offline but will make it online again after a given time
+      *
+      * Use this method when the agent detects some problem with its backend but it wants
+      * to retry all pending operations after some time - e.g. a server can not be reached currently
+      *
+      * Example usage:
+      * @code
+      * void ExampleResource::onItemRemovedFinished(KJob *job)
+      * {
+      *     if (job->error()) {
+      *         emit status(Broken, job->errorString());
+      *         deferTask();
+      *         setTemporaryOffline(300);
+      *         return;
+      *     }
+      *     ...
+      * }
+      * @endcode
+      *
+      * @since 4.13
+      * @param makeOnlineInSeconds timeout in seconds after which the agent changes to online
+      */
+    void setTemporaryOffline(int makeOnlineInSeconds = 300);
+
   protected:
     //@cond PRIVATE
     AgentBasePrivate *d_ptr;
@@ -748,6 +773,7 @@ class AKONADI_EXPORT AgentBase : public QObject, protected QDBusContext
     Q_PRIVATE_SLOT( d_func(), void slotError( const QString& ) )
     Q_PRIVATE_SLOT( d_func(), void slotNetworkStatusChange( Solid::Networking::Status ) )
     Q_PRIVATE_SLOT( d_func(), void slotResumedFromSuspend() )
+    Q_PRIVATE_SLOT(d_func(), void slotTemporaryOfflineTimeout())
 
     //@endcond
 };
diff --git a/akonadi/agentbase_p.h b/akonadi/agentbase_p.h
index 3ead634..64de02a 100644
--- a/akonadi/agentbase_p.h
+++ b/akonadi/agentbase_p.h
@@ -29,6 +29,7 @@
 #include <solid/networking.h>
 
 class QSettings;
+class QTimer;
 
 namespace Akonadi {
 
@@ -52,6 +53,7 @@ class AgentBasePrivate : public QObject
     void slotError( const QString& message );
     void slotNetworkStatusChange( Solid::Networking::Status );
     void slotResumedFromSuspend();
+    void slotTemporaryOfflineTimeout();
 
     virtual void changeProcessed();
 
@@ -108,6 +110,8 @@ class AgentBasePrivate : public QObject
 
     AgentBase::Observer *mObserver;
 
+    QTimer *mTemporaryOfflineTimer;
+
   public Q_SLOTS:
     // Dump the contents of the current ChangeReplay
     Q_SCRIPTABLE QString dumpNotificationListToString() const;


More information about the Kde-bindings mailing list