Akonadi

preprocessorinstance.h
1/******************************************************************************
2 *
3 * File : preprocessorinstance.h
4 * Creation date : Sat 18 Jul 2009 02:50:39
5 *
6 * SPDX-FileCopyrightText: 2009 Szymon Stefanek <s.stefanek at gmail dot com>
7 *
8 * SPDX-License-Identifier: LGPL-2.0-or-later
9 *
10 *****************************************************************************/
11
12#pragma once
13
14#include <QDateTime>
15#include <QObject>
16
17#include <deque>
18
19class OrgFreedesktopAkonadiPreprocessorInterface;
20
21namespace Akonadi
22{
23namespace Server
24{
25class PreprocessorManager;
26class AgentInstance;
27class Tracer;
28
29/**
30 * A single preprocessor (agent) instance.
31 *
32 * Most of the interface of this class is protected and is exposed only
33 * to PreprocessorManager (singleton).
34 *
35 * This class is NOT thread safe. The caller is responsible of protecting
36 * against concurrent access.
37 */
39{
40 friend class PreprocessorManager;
41
43
44protected:
45 /**
46 * Create an instance of a PreprocessorInstance descriptor.
47 */
48 PreprocessorInstance(const QString &id, PreprocessorManager &manager, Tracer &tracer);
49
50public: // This is public only for qDeleteAll() called from PreprocessorManager
51 // ...for some reason couldn't convince gcc to have it as friend...
52
53 /**
54 * Destroy this instance of the PreprocessorInstance descriptor.
55 */
57
58private:
59 PreprocessorManager &mManager;
60 Tracer &mTracer;
61
62 /**
63 * The internal queue if item identifiers.
64 * The head item in the queue is the one currently being processed.
65 * The other ones are waiting.
66 */
67 std::deque<qint64> mItemQueue;
68
69 /**
70 * Is this processor busy ?
71 * This, in fact, *should* be equivalent to "mItemQueue.count() > 0"
72 * as the head item in the queue is the one being processed now.
73 */
74 bool mBusy = false;
75
76 /**
77 * The date-time at that we have started processing the current
78 * item in the queue. This is used to compute the processing time
79 * and eventually spot a "dead" preprocessor (which takes longer
80 * than N minutes to process an item).
81 */
82 QDateTime mItemProcessingStartDateTime;
83
84 /**
85 * The id of this preprocessor instance. This is actually
86 * the AgentInstance identifier.
87 */
88 QString mId;
89
90 /**
91 * The preprocessor D-Bus interface. Owned.
92 */
93 OrgFreedesktopAkonadiPreprocessorInterface *mInterface = nullptr;
94
95protected:
96 /**
97 * This is called by PreprocessorManager just after the construction
98 * in order to connect to the preprocessor instance via D-Bus.
99 * In case of failure this object should be destroyed as it can't
100 * operate properly. The error message is printed via Tracer.
101 */
102 bool init();
103
104 /**
105 * Returns true if this preprocessor instance is currently processing an item.
106 * That is: if we have called "processItem()" on it and it hasn't emitted
107 * itemProcessed() yet.
108 */
109 bool isBusy() const
110 {
111 return mBusy;
112 }
113
114 /**
115 * Returns the time in seconds elapsed since the current item was submitted
116 * to the slave preprocessor instance. If no item is currently being
117 * processed then this function returns -1;
118 */
119 qint64 currentProcessingTime();
120
121 /**
122 * Returns the id of this preprocessor. This is actually
123 * the AgentInstance identifier but it's not a requirement.
124 */
125 const QString &id() const
126 {
127 return mId;
128 }
129
130 /**
131 * Returns a pointer to the internal preprocessor instance
132 * item queue. Don't mess with it unless you *really* know
133 * what you're doing. Use enqueueItem() to add an item
134 * to the queue. This method is provided to the PreprocessorManager
135 * to take over the item queue of a dying preprocessor.
136 *
137 * The returned pointer is granted to be non null.
138 */
139 std::deque<qint64> *itemQueue()
140 {
141 return &mItemQueue;
142 }
143
144 /**
145 * This is called by PreprocessorManager to enqueue a PimItem
146 * for processing by this preprocessor instance.
147 */
148 void enqueueItem(qint64 itemId);
149
150 /**
151 * Attempts to abort the processing of the current item.
152 * May be called only if isBusy() returns true and an assertion
153 * will remind you of that.
154 * Returns true if the abort request was successfully sent
155 * (but not necessarily handled by the slave) and false
156 * if the request couldn't be sent for some reason.
157 */
158 bool abortProcessing();
159
160 /**
161 * Attempts to invoke the preprocessor slave restart via
162 * AgentManager. This is the "last resort" action before
163 * starting to ignore the preprocessor (after it misbehaved).
164 */
165 bool invokeRestart();
166
167private:
168 /**
169 * This function starts processing of the first item in mItemQueue.
170 * It's only used internally.
171 */
172 void processHeadItem();
173
174private Q_SLOTS:
175
176 /**
177 * This is invoked to signal that the processing of the current (head)
178 * item has terminated and the next item should be processed.
179 */
180 void itemProcessed(qlonglong id);
181
182}; // class PreprocessorInstance
183
184} // namespace Server
185} // namespace Akonadi
Represents one agent instance and takes care of communication with it.
A single preprocessor (agent) instance.
std::deque< qint64 > * itemQueue()
Returns a pointer to the internal preprocessor instance item queue.
PreprocessorInstance(const QString &id, PreprocessorManager &manager, Tracer &tracer)
Create an instance of a PreprocessorInstance descriptor.
qint64 currentProcessingTime()
Returns the time in seconds elapsed since the current item was submitted to the slave preprocessor in...
const QString & id() const
Returns the id of this preprocessor.
bool isBusy() const
Returns true if this preprocessor instance is currently processing an item.
bool abortProcessing()
Attempts to abort the processing of the current item.
void enqueueItem(qint64 itemId)
This is called by PreprocessorManager to enqueue a PimItem for processing by this preprocessor instan...
~PreprocessorInstance() override
Destroy this instance of the PreprocessorInstance descriptor.
bool init()
This is called by PreprocessorManager just after the construction in order to connect to the preproce...
bool invokeRestart()
Attempts to invoke the preprocessor slave restart via AgentManager.
The manager for preprocessor agents.
The global tracer instance where all akonadi components can send their tracing information to.
Definition tracer.h:38
Helper integration between Akonadi and Qt.
Q_OBJECTQ_OBJECT
Q_SLOTSQ_SLOTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:03:34 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.