akabeibackend_p.h 3.05 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/* This file is part of the Chakra project

   Copyright (C) 2010 Dario Freddi <drf@chakra-project.org>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.
*/

#ifndef AKABEIBACKEND_P_H
#define AKABEIBACKEND_P_H

14 15
#include <akabeibackend.h>
#include <akabeioperationrunner.h>
16
#include <akabeidatabase.h>
17
#include <akabeidebug.h>
18

19 20 21
#include <QFileSystemWatcher>
#include <QFutureWatcher>
#include <QUuid>
Lukas Appelhans's avatar
Lukas Appelhans committed
22
#include <QFile>
23
#include <QReadWriteLock>
24
#include <QCoreApplication>
25
#include <QDBusInterface>
26

27 28
namespace Akabei
{
29

30 31 32 33 34 35
class GroupPool
{
    public:
        virtual ~GroupPool();

        Group *group(const QString &name);
36
        bool contains(const QString &name) const;
Lisa's avatar
Lisa committed
37 38
        
        QList< Group* > allGroups() const;
39 40 41 42 43 44

    private:
        GroupPool();

        QHash<QString, Group*> m_pool;

45 46
        QMutex * m_mutex;

47 48 49 50
        friend class BackendPrivate;
};

class BackendPrivate : public QObject
51
{
52
    Q_OBJECT
53
    Q_DECLARE_PUBLIC(Backend)
54
    Backend * const q_ptr;
55 56 57

    public:
        BackendPrivate(Backend *p)
58 59
            : QObject(p)
            , q_ptr(p)
60
            , status(Backend::StatusBare)
61
            , mutex(new QReadWriteLock(QReadWriteLock::Recursive))
62 63
            , localDatabase(nullptr)
            , lockFileHandle(nullptr)
64
            , fsWatcher(new QFileSystemWatcher(p))
65
            , groupPool(new GroupPool)
66
            , runner(new OperationRunner(p))
67
            , iface(nullptr) {}
68
        ~BackendPrivate() {
69
            delete lockFileHandle;
Lukas Appelhans's avatar
Lukas Appelhans committed
70
            qDeleteAll(databases);
Lukas Appelhans's avatar
Lukas Appelhans committed
71 72
            delete localDatabase;
            delete groupPool;
73
            delete mutex;
74
            delete iface;
75
        }
76 77

        Backend::Status status;
78
        QReadWriteLock *mutex;
79

80
        Database *localDatabase;
81
        QFile * lockFileHandle;
82
        QFutureWatcher<void> lockWatcher;
83 84 85
        QList<Database*> databases;

        QFileSystemWatcher *fsWatcher;
86
        GroupPool *groupPool;
87 88

        QFutureWatcher< QHash< QString, Database* > > *initializationWatcher;
89 90
        QHash< QUuid, QFutureWatcher< QList < Package* > >* > queryPackageFuturePool;
        QHash< QUuid, QFutureWatcher< QList < Group* > >* > queryGroupFuturePool;
91
        QHash< QUuid, QFutureWatcher< QList < Package* > >* > orphanPackageFuturePool;
92

93
        OperationRunner *runner;
94

95 96 97
        QObject * callbackObject;
        const char * callbackSlot;

98
        void __k__initializationFinished();
99
        void __k__lockGranted(qlonglong pid);
100 101 102
        void __k__lockGranted() {
            __k__lockGranted(QCoreApplication::applicationPid());
        }
103
        void getLock();
104 105

        QHash<QString, Database*> performInitialization();
106
        void addDatabase(const QString &name);
107

108
        Package* parseInfoFile();
109 110
        
        QDBusInterface * iface;
111

112
    public Q_SLOTS:
113 114
        void packageQueryFinished();
        void groupQueryFinished();
115
        void orphanQueryFinished();
116 117 118 119 120
};

}

#endif