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 InvalideCacheForCollection, 00059 SyncAllDone, 00060 SyncCollectionTreeDone, 00061 Custom 00062 }; 00063 00064 class Task { 00065 static qint64 latestSerial; 00066 00067 public: 00068 Task() : serial( ++latestSerial ), type( Invalid ), receiver( 0 ) {} 00069 qint64 serial; 00070 TaskType type; 00071 Collection collection; 00072 Item item; 00073 QSet<QByteArray> itemParts; 00074 QList<QDBusMessage> dbusMsgs; 00075 QObject *receiver; 00076 QByteArray methodName; 00077 QVariant argument; 00078 00079 void sendDBusReplies( bool success ); 00080 00081 bool operator==( const Task &other ) const 00082 { 00083 return type == other.type 00084 && (collection == other.collection || (!collection.isValid() && !other.collection.isValid())) 00085 && (item == other.item || (!item.isValid() && !other.item.isValid())) 00086 && itemParts == other.itemParts 00087 && receiver == other.receiver 00088 && methodName == other.methodName 00089 && argument == other.argument; 00090 } 00091 }; 00092 00093 ResourceScheduler( QObject *parent = 0 ); 00094 00098 void scheduleFullSync(); 00099 00103 void scheduleCollectionTreeSync(); 00104 00109 void scheduleSync( const Collection &col ); 00110 00115 void scheduleAttributesSync( const Collection &collection ); 00116 00123 void scheduleItemFetch( const Item &item, const QSet<QByteArray> &parts, const QDBusMessage &msg ); 00124 00129 void scheduleResourceCollectionDeletion(); 00130 00135 void scheduleCacheInvalidation( const Collection &collection ); 00136 00140 void scheduleFullSyncCompletion(); 00141 00145 void scheduleCollectionTreeSyncCompletion(); 00146 00151 void scheduleCustomTask( QObject *receiver, const char *methodName, const QVariant &argument, ResourceBase::SchedulePriority priority = ResourceBase::Append ); 00152 00156 bool isEmpty(); 00157 00161 Task currentTask() const; 00162 00166 void setOnline( bool state ); 00167 00171 void dump(); 00175 QString dumpToString() const; 00176 00182 void clear(); 00183 00189 void cancelQueues(); 00190 00191 public Q_SLOTS: 00195 void scheduleChangeReplay(); 00196 00200 void taskDone(); 00201 00205 void deferTask(); 00206 00210 void collectionRemoved( const Akonadi::Collection &collection ); 00211 00212 Q_SIGNALS: 00213 void executeFullSync(); 00214 void executeCollectionAttributesSync( const Akonadi::Collection &col ); 00215 void executeCollectionSync( const Akonadi::Collection &col ); 00216 void executeCollectionTreeSync(); 00217 void executeItemFetch( const Akonadi::Item &item, const QSet<QByteArray> &parts ); 00218 void executeResourceCollectionDeletion(); 00219 void executeCacheInvalidation( const Akonadi::Collection &collection ); 00220 void executeChangeReplay(); 00221 void collectionTreeSyncComplete(); 00222 void fullSyncComplete(); 00223 void status( int status, const QString &message = QString() ); 00224 00225 private slots: 00226 void scheduleNext(); 00227 void executeNext(); 00228 00229 private: 00230 void signalTaskToTracker( const Task &task, const QByteArray &taskType ); 00231 00232 // We have a number of task queues, by order of priority. 00233 // * ChangeReplay must be first: 00234 // change replays have to happen before we pull changes from the backend, otherwise 00235 // we will overwrite our still unsaved local changes if the backend can't do 00236 // incremental retrieval 00237 // 00238 // * then the stuff that is "immediately after change replay", like writeFile calls. 00239 // * then ItemFetch tasks, because they are made by blocking DBus calls 00240 // * then everything else. 00241 enum QueueType { 00242 PrependTaskQueue, 00243 ChangeReplayQueue, // one task at most 00244 AfterChangeReplayQueue, // also one task at most, currently 00245 ItemFetchQueue, 00246 GenericTaskQueue, 00247 NQueueCount 00248 }; 00249 typedef QList<Task> TaskList; 00250 00251 static QueueType queueTypeForTaskType( TaskType type ); 00252 TaskList& queueForTaskType( TaskType type ); 00253 00254 TaskList mTaskList[ NQueueCount ]; 00255 00256 Task mCurrentTask; 00257 int mCurrentTasksQueue; // queue mCurrentTask came from 00258 bool mOnline; 00259 }; 00260 00261 QDebug operator<<( QDebug, const ResourceScheduler::Task& task ); 00262 QTextStream& operator<<( QTextStream&, const ResourceScheduler::Task& task ); 00263 00264 //@endcond 00265 00266 } 00267 00268 #endif