00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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
00213
00214
00215
00216
00217
00218
00219
00220
00221 enum QueueType {
00222 PrependTaskQueue,
00223 ChangeReplayQueue,
00224 AfterChangeReplayQueue,
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;
00238 bool mOnline;
00239 };
00240
00241 QDebug operator<<( QDebug, const ResourceScheduler::Task& task );
00242
00243
00244
00245 }
00246
00247 #endif