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 FetchItem,
00054 ChangeReplay,
00055 DeleteResourceCollection,
00056 SyncAllDone,
00057 Custom
00058 };
00059
00060 class Task {
00061 static qint64 latestSerial;
00062
00063 public:
00064 Task() : serial( ++latestSerial ), type( Invalid ), receiver( 0 ) {}
00065 qint64 serial;
00066 TaskType type;
00067 Collection collection;
00068 Item item;
00069 QSet<QByteArray> itemParts;
00070 QList<QDBusMessage> dbusMsgs;
00071 QObject *receiver;
00072 QByteArray methodName;
00073 QVariant argument;
00074
00075 void sendDBusReplies( bool success );
00076
00077 bool operator==( const Task &other ) const
00078 {
00079 return type == other.type
00080 && (collection == other.collection || (!collection.isValid() && !other.collection.isValid()))
00081 && (item == other.item || (!item.isValid() && !other.item.isValid()))
00082 && itemParts == other.itemParts
00083 && receiver == other.receiver
00084 && methodName == other.methodName
00085 && argument == other.argument;
00086 }
00087 };
00088
00089 ResourceScheduler( QObject *parent = 0 );
00090
00094 void scheduleFullSync();
00095
00099 void scheduleCollectionTreeSync();
00100
00105 void scheduleSync( const Collection &col );
00106
00113 void scheduleItemFetch( const Item &item, const QSet<QByteArray> &parts, const QDBusMessage &msg );
00114
00119 void scheduleResourceCollectionDeletion();
00120
00124 void scheduleFullSyncCompletion();
00125
00130 void scheduleCustomTask( QObject *receiver, const char *methodName, const QVariant &argument, ResourceBase::SchedulePriority priority = ResourceBase::Append );
00131
00135 bool isEmpty();
00136
00140 Task currentTask() const;
00141
00145 void setOnline( bool state );
00146
00150 void dump();
00151
00157 void clear();
00158
00159 public Q_SLOTS:
00163 void scheduleChangeReplay();
00164
00168 void taskDone();
00169
00173 void deferTask();
00174
00178 void collectionRemoved( const Akonadi::Collection &collection );
00179
00180 Q_SIGNALS:
00181 void executeFullSync();
00182 void executeCollectionSync( const Akonadi::Collection &col );
00183 void executeCollectionTreeSync();
00184 void executeItemFetch( const Akonadi::Item &item, const QSet<QByteArray> &parts );
00185 void executeResourceCollectionDeletion();
00186 void executeChangeReplay();
00187 void fullSyncComplete();
00188 void status( int status, const QString &message = QString() );
00189
00190 private slots:
00191 void scheduleNext();
00192 void executeNext();
00193
00194 private:
00195 void signalTaskToTracker( const Task &task, const QByteArray &taskType );
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206 enum QueueType {
00207 PrependTaskQueue,
00208 ChangeReplayQueue,
00209 AfterChangeReplayQueue,
00210 ItemFetchQueue,
00211 GenericTaskQueue,
00212 NQueueCount
00213 };
00214 typedef QList<Task> TaskList;
00215
00216 static QueueType queueTypeForTaskType( TaskType type );
00217 TaskList& queueForTaskType( TaskType type );
00218
00219 TaskList mTaskList[ NQueueCount ];
00220
00221 Task mCurrentTask;
00222 int mCurrentTasksQueue;
00223 bool mOnline;
00224 };
00225
00226 QDebug operator<<( QDebug, const ResourceScheduler::Task& task );
00227
00228
00229
00230 }
00231
00232 #endif