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 enum TaskType { 00049 Invalid, 00050 SyncAll, 00051 SyncCollectionTree, 00052 SyncCollection, 00053 SyncCollectionAttributes, 00054 FetchItem, 00055 ChangeReplay, 00056 DeleteResourceCollection, 00057 SyncAllDone, 00058 Custom 00059 }; 00060 00061 class Task { 00062 static qint64 latestSerial; 00063 00064 public: 00065 Task() : serial( ++latestSerial ), type( Invalid ), receiver( 0 ) {} 00066 qint64 serial; 00067 TaskType type; 00068 Collection collection; 00069 Item item; 00070 QSet<QByteArray> itemParts; 00071 QList<QDBusMessage> dbusMsgs; 00072 QObject *receiver; 00073 QByteArray methodName; 00074 QVariant argument; 00075 00076 void sendDBusReplies( bool success ); 00077 00078 bool operator==( const Task &other ) const 00079 { 00080 return type == other.type 00081 && (collection == other.collection || (!collection.isValid() && !other.collection.isValid())) 00082 && (item == other.item || (!item.isValid() && !other.item.isValid())) 00083 && itemParts == other.itemParts 00084 && receiver == other.receiver 00085 && methodName == other.methodName 00086 && argument == other.argument; 00087 } 00088 }; 00089 00090 ResourceScheduler( QObject *parent = 0 ); 00091 00095 void scheduleFullSync(); 00096 00100 void scheduleCollectionTreeSync(); 00101 00106 void scheduleSync( const Collection &col ); 00107 00112 void scheduleAttributesSync( const Collection &collection ); 00113 00120 void scheduleItemFetch( const Item &item, const QSet<QByteArray> &parts, const QDBusMessage &msg ); 00121 00126 void scheduleResourceCollectionDeletion(); 00127 00131 void scheduleFullSyncCompletion(); 00132 00137 void scheduleCustomTask( QObject *receiver, const char *methodName, const QVariant &argument, ResourceBase::SchedulePriority priority = ResourceBase::Append ); 00138 00142 bool isEmpty(); 00143 00147 Task currentTask() const; 00148 00152 void setOnline( bool state ); 00153 00157 void dump(); 00158 00164 void clear(); 00165 00171 void cancelQueues(); 00172 00173 public Q_SLOTS: 00177 void scheduleChangeReplay(); 00178 00182 void taskDone(); 00183 00187 void deferTask(); 00188 00192 void collectionRemoved( const Akonadi::Collection &collection ); 00193 00194 Q_SIGNALS: 00195 void executeFullSync(); 00196 void executeCollectionAttributesSync( const Akonadi::Collection &col ); 00197 void executeCollectionSync( const Akonadi::Collection &col ); 00198 void executeCollectionTreeSync(); 00199 void executeItemFetch( const Akonadi::Item &item, const QSet<QByteArray> &parts ); 00200 void executeResourceCollectionDeletion(); 00201 void executeChangeReplay(); 00202 void fullSyncComplete(); 00203 void status( int status, const QString &message = QString() ); 00204 00205 private slots: 00206 void scheduleNext(); 00207 void executeNext(); 00208 00209 private: 00210 void signalTaskToTracker( const Task &task, const QByteArray &taskType ); 00211 00212 // We have a number of task queues, by order of priority. 00213 // * ChangeReplay must be first: 00214 // change replays have to happen before we pull changes from the backend, otherwise 00215 // we will overwrite our still unsaved local changes if the backend can't do 00216 // incremental retrieval 00217 // 00218 // * then the stuff that is "immediately after change replay", like writeFile calls. 00219 // * then ItemFetch tasks, because they are made by blocking DBus calls 00220 // * then everything else. 00221 enum QueueType { 00222 PrependTaskQueue, 00223 ChangeReplayQueue, // one task at most 00224 AfterChangeReplayQueue, // also one task at most, currently 00225 ItemFetchQueue, 00226 GenericTaskQueue, 00227 NQueueCount 00228 }; 00229 typedef QList<Task> TaskList; 00230 00231 static QueueType queueTypeForTaskType( TaskType type ); 00232 TaskList& queueForTaskType( TaskType type ); 00233 00234 TaskList mTaskList[ NQueueCount ]; 00235 00236 Task mCurrentTask; 00237 int mCurrentTasksQueue; // queue mCurrentTask came from 00238 bool mOnline; 00239 }; 00240 00241 QDebug operator<<( QDebug, const ResourceScheduler::Task& task ); 00242 00243 //@endcond 00244 00245 } 00246 00247 #endif