Akonadi

core/session.h
1 /*
2  SPDX-FileCopyrightText: 2007 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "akonadicore_export.h"
10 #include <QObject>
11 
12 #include <memory>
13 
14 class KJob;
15 class FakeSession;
16 class FakeNotificationConnection;
17 
18 namespace Akonadi
19 {
20 namespace Protocol
21 {
22 class Command;
23 using CommandPtr = QSharedPointer<Command>;
24 }
25 
26 class Job;
27 class SessionPrivate;
28 class ChangeNotificationDependenciesFactory;
29 
30 /**
31  * @short A communication session with the Akonadi storage.
32  *
33  * Every Job object has to be associated with a Session.
34  * The session is responsible of scheduling its jobs.
35  * For now only a simple serial execution is implemented (the IMAP-like
36  * protocol to communicate with the storage backend is capable of parallel
37  * execution on a single session though).
38  *
39  * @code
40  *
41  * using namespace Akonadi;
42  *
43  * Session *session = new Session( "mySession" );
44  *
45  * CollectionFetchJob *job = new CollectionFetchJob( Collection::root(),
46  * CollectionFetchJob::Recursive,
47  * session );
48  *
49  * connect( job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*)) );
50  *
51  * @endcode
52  *
53  * @author Volker Krause <[email protected]>
54  */
55 class AKONADICORE_EXPORT Session : public QObject
56 {
57  Q_OBJECT
58 
59  friend class Job;
60  friend class JobPrivate;
61  friend class SessionPrivate;
62 
63 public:
64  /**
65  * Creates a new session.
66  *
67  * @param sessionId The identifier for this session, will be a
68  * random value if empty.
69  * @param parent The parent object.
70  *
71  * @see defaultSession()
72  */
73  explicit Session(const QByteArray &sessionId = QByteArray(), QObject *parent = nullptr);
74 
75  /**
76  * Destroys the session.
77  */
78  ~Session() override;
79 
80  /**
81  * Returns the session identifier.
82  */
83  Q_REQUIRED_RESULT QByteArray sessionId() const;
84 
85  /**
86  * Returns the default session for this thread.
87  */
88  static Session *defaultSession();
89 
90  /**
91  * Stops all jobs queued for execution.
92  */
93  void clear();
94 
95 Q_SIGNALS:
96  /**
97  * This signal is emitted whenever the session has been reconnected
98  * to the server (e.g. after a server crash).
99  *
100  * @since 4.6
101  */
102  void reconnected();
103 
104 protected:
105  /**
106  * Creates a new session with shared private object.
107  *
108  * @param d The private object.
109  * @param sessionId The identifier for this session, will be a
110  * random value if empty.
111  * @param parent The parent object.
112  *
113  * @note This constructor is needed for unit testing only.
114  */
115  explicit Session(SessionPrivate *d, const QByteArray &sessionId = QByteArray(), QObject *parent = nullptr);
116 
117 private:
118  /// @cond PRIVATE
119  std::unique_ptr<SessionPrivate> const d;
120  friend class ::FakeSession;
121  friend class ::FakeNotificationConnection;
122  friend class ChangeNotificationDependenciesFactory;
123 
124  Q_PRIVATE_SLOT(d, bool handleCommands())
125  /// @endcond
126 };
127 
128 }
129 
A communication session with the Akonadi storage.
Definition: core/session.h:55
Base class for all actions in the Akonadi storage.
Definition: job.h:80
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jun 30 2022 03:51:46 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.