1/***************************************************************************
2 * Copyright (C) 2006 by Till Adam <adam@kde.org> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU Library General Public License as *
6 * published by the Free Software Foundation; either version 2 of the *
7 * License, or (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Library General Public *
15 * License along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
19
20#ifndef AKONADISERVER_H
21#define AKONADISERVER_H
22
23#include <QtCore/QPointer>
24#include <QtCore/QVector>
25
26#include <QtNetwork/QLocalServer>
27
28class QProcess;
29
30namespace Akonadi {
31namespace Server {
32
33class ConnectionThread;
34class CacheCleaner;
35class SearchManagerThread;
36class ItemRetrievalThread;
37class SearchTaskManagerThread;
38class StorageJanitorThread;
39class IntervalCheck;
40
41class AkonadiServer : public QLocalServer
42{
43 Q_OBJECT
44
45public:
46 ~AkonadiServer();
47 static AkonadiServer *instance();
48
49 /**
50 * Can return a nullptr
51 */
52 CacheCleaner *cacheCleaner();
53
54 /**
55 * Can return a nullptr
56 */
57 IntervalCheck *intervalChecker();
58
59public Q_SLOTS:
60 /**
61 * Triggers a clean server shutdown.
62 */
63 virtual bool quit();
64
65 virtual bool init();
66
67private Q_SLOTS:
68 void doQuit();
69 void serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner);
70
71protected:
72 /** reimpl */
73 virtual void incomingConnection(quintptr socketDescriptor);
74
75private:
76 void startDatabaseProcess();
77 void createDatabase();
78 void stopDatabaseProcess();
79
80protected:
81 AkonadiServer(QObject *parent = 0);
82
83 CacheCleaner *mCacheCleaner;
84 IntervalCheck *mIntervalChecker;
85 StorageJanitorThread *mStorageJanitor;
86 ItemRetrievalThread *mItemRetrievalThread;
87 SearchTaskManagerThread *mAgentSearchManagerThread;
88 QProcess *mDatabaseProcess;
89 QVector< QPointer<ConnectionThread> > mConnections;
90 SearchManagerThread *mSearchManager;
91 bool mAlreadyShutdown;
92
93 static AkonadiServer *s_instance;
94};
95
96} // namespace Server
97} // namespace Akonadi
98#endif
99