akonadi
resourcescheduler_p.h
00001 /* 00002 Copyright (c) 2007 Volker Krause <vkrause@kde.org> 00003 00004 This library is free software; you can redistribute it and/or modify it 00005 under the terms of the GNU Library General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or (at your 00007 option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, but WITHOUT 00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00011 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00012 License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to the 00016 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00017 02110-1301, USA. 00018 */ 00019 00020 #ifndef AKONADI_RESOURCESCHEDULER_P_H 00021 #define AKONADI_RESOURCESCHEDULER_P_H 00022 00023 #include <akonadi/agentbase.h> 00024 #include <akonadi/collection.h> 00025 #include <akonadi/item.h> 00026 #include <akonadi/resourcebase.h> 00027 00028 #include <QtCore/QObject> 00029 #include <QtCore/QStringList> 00030 #include <QtDBus/QDBusMessage> 00031 00032 namespace Akonadi { 00033 00034 //@cond PRIVATE 00035 00043 class ResourceScheduler : public QObject 00044 { 00045 Q_OBJECT 00046 00047 public: 00048 // If you change this enum, keep s_taskTypes in sync in resourcescheduler.cpp 00049 enum TaskType { 00050 Invalid, 00051 SyncAll, 00052 SyncCollectionTree, 00053 SyncCollection, 00054 SyncCollectionAttributes, 00055 FetchItem, 00056 ChangeReplay, 00057 DeleteResourceCollection, 00058 SyncAllDone, 00059 Custom 00060 }; 00061 00062 class Task { 00063 static qint64 latestSerial; 00064 00065 public: 00066 Task() : serial( ++latestSerial ), type( Invalid ), receiver( 0 ) {} 00067 qint64 serial; 00068 TaskType type; 00069 Collection collection; 00070 Item item; 00071 QSet<QByteArray> itemParts; 00072 QList<QDBusMessage> dbusMsgs; 00073 QObject *receiver; 00074 QByteArray methodName; 00075 QVariant argument; 00076 00077 void sendDBusReplies( bool success ); 00078 00079 bool operator==( const Task &other ) const 00080 { 00081 return type == other.type 00082 && (collection == other.collection || (!collection.isValid() && !other.collection.isValid())) 00083 && (item == other.item || (!item.isValid() && !other.item.isValid())) 00084 && itemParts == other.itemParts 00085 && receiver == other.receiver 00086 && methodName == other.methodName 00087 && argument == other.argument; 00088 } 00089 }; 00090 00091 ResourceScheduler( QObject *parent = 0 ); 00092 00096 void scheduleFullSync(); 00097 00101 void scheduleCollectionTreeSync(); 00102 00107 void scheduleSync( const Collection &col ); 00108 00113 void scheduleAttributesSync( const Collection &collection ); 00114 00121 void scheduleItemFetch( const Item &item, const QSet<QByteArray> &parts, const QDBusMessage &msg ); 00122 00127 void scheduleResourceCollectionDeletion(); 00128 00132 void scheduleFullSyncCompletion(); 00133 00138 void scheduleCustomTask( QObject *receiver, const char *methodName, const QVariant &argument, ResourceBase::SchedulePriority priority = ResourceBase::Append ); 00139 00143 bool isEmpty(); 00144 00148 Task currentTask() const; 00149 00153 void setOnline( bool state ); 00154 00158 void dump(); 00159 00165 void clear(); 00166 00172 void cancelQueues(); 00173 00174 public Q_SLOTS: 00178 void scheduleChangeReplay(); 00179 00183 void taskDone(); 00184 00188 void deferTask(); 00189 00193 void collectionRemoved( const Akonadi::Collection &collection ); 00194 00195 Q_SIGNALS: 00196 void executeFullSync(); 00197 void executeCollectionAttributesSync( const Akonadi::Collection &col ); 00198 void executeCollectionSync( const Akonadi::Collection &col ); 00199 void executeCollectionTreeSync(); 00200 void executeItemFetch( const Akonadi::Item &item, const QSet<QByteArray> &parts ); 00201 void executeResourceCollectionDeletion(); 00202 void executeChangeReplay(); 00203 void fullSyncComplete(); 00204 void status( int status, const QString &message = QString() ); 00205 00206 private slots: 00207 void scheduleNext(); 00208 void executeNext(); 00209 00210 private: 00211 void signalTaskToTracker( const Task &task, const QByteArray &taskType ); 00212 00213 // We have a number of task queues, by order of priority. 00214 // * ChangeReplay must be first: 00215 // change replays have to happen before we pull changes from the backend, otherwise 00216 // we will overwrite our still unsaved local changes if the backend can't do 00217 // incremental retrieval 00218 // 00219 // * then the stuff that is "immediately after change replay", like writeFile calls. 00220 // * then ItemFetch tasks, because they are made by blocking DBus calls 00221 // * then everything else. 00222 enum QueueType { 00223 PrependTaskQueue, 00224 ChangeReplayQueue, // one task at most 00225 AfterChangeReplayQueue, // also one task at most, currently 00226 ItemFetchQueue, 00227 GenericTaskQueue, 00228 NQueueCount 00229 }; 00230 typedef QList<Task> TaskList; 00231 00232 static QueueType queueTypeForTaskType( TaskType type ); 00233 TaskList& queueForTaskType( TaskType type ); 00234 00235 TaskList mTaskList[ NQueueCount ]; 00236 00237 Task mCurrentTask; 00238 int mCurrentTasksQueue; // queue mCurrentTask came from 00239 bool mOnline; 00240 }; 00241 00242 QDebug operator<<( QDebug, const ResourceScheduler::Task& task ); 00243 00244 //@endcond 00245 00246 } 00247 00248 #endif