akabeivalidatorthread_p.h 1.95 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/* 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 AKABEI_AKABEIVALIDATORTHREAD_P_H
#define AKABEI_AKABEIVALIDATORTHREAD_P_H

#include "akabeioperation.h"

#include <QtCore/QThread>
#include <QtCore/QHash>

namespace Akabei {
20
class Error;
21 22 23 24 25 26 27 28 29
class OperationPrivate;

/*
    Hey, brave man looking at this code, I salute you.
    Before starting, keep this in mind: what you see here is what decides if a transaction is valid or not.
    It is the most complex part in the whole AkabeiCore, and the most delicate as well, since
    this decides if your system will be fucked up by a wrong transaction or be spared.
    Be careful.
*/
30 31 32 33 34 35 36 37 38
class ValidatorThread : public QThread
{
    Q_OBJECT
    public:
        ValidatorThread(QObject* parent = 0);
        virtual ~ValidatorThread();

        void requestCancel();

39
        QHash< QString, QString > versionedTargets(const QStringList &targets) const;
40
        QPair< QString, QString > versionedTarget(const QString &targets) const;
41 42 43

        static OperationPrivate *operationPrivateProxy(Operation *op);

44 45 46
    protected:
        virtual void run();

47 48 49 50 51 52 53
    Q_SIGNALS:
        void errorsOccurred(const QList<Error*> &errors);
        void validationFinished(bool success);

    private Q_SLOTS:
        void streamValidationProgress(int);

54 55
    private:
        void processNextPhase();
56
        QList< Operation* > joinOperations(Operation *op, bool shouldBeReady);
57
        void manageErrors(const QList<Error*> &errors);
58 59 60 61 62 63 64 65 66 67 68

    private:
        QHash<Operation::Phase, QList< Operation* > > m_operations;
        Operation::Phase m_currentPhase;

        friend class OperationRunner;
};

}

#endif // AKABEI_AKABEIVALIDATORTHREAD_P_H