summaryrefslogtreecommitdiff
path: root/mpris2/interfacetest.h
blob: cfc174ce95c66a088b0e6470dc972d4a2c71cb11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) 2011  Alex Merry <dev@randomguy3.me.uk>

    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.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/


#ifndef INTERFACETEST_H
#define INTERFACETEST_H

class QDBusInterface;
class QDBusMessage;
class QTimer;
#include <QObject>
#include <QStringList>
#include <QVariantMap>

namespace Mpris2
{
    class InterfaceTest : public QObject
    {
        Q_OBJECT

    public:
        enum LocationType {
            Property,
            Method,
            Signal,
            Other
        };

        QVariantMap properties() const;

    public slots:
        /**
            * Performs a basic initial test.
            *
            * Checks for property existence and types, mainly.
            */
        void initialTest();

        /**
            * Performs an incremental test.
            *
            * Checks that if properties have changed, we have
            * been notified (actually waits a couple of seconds for
            * slightly delayed notifications before complaining).
            */
        void incrementalTest();

    protected:
        InterfaceTest(const QString& interface, const QString& service, QObject* parent);
        virtual ~InterfaceTest();

    signals:
        /**
          * Reports that there was a problem with the interface.
          *
          * Indicates that a violation of MPRIS has been found.
          *
          * @param desc  a user-readable description of the error
          */
        void interfaceError(Mpris2::InterfaceTest::LocationType locType, const QString& location, const QString& desc);

        /**
          * Reports that there might be a problem with the interface.
          *
          * This is something that isn't necessarily a problem, but
          * probably is, like not including the "file" protocol
          * in SupportedUriSchemes.
          *
          * @param desc  a user-readable description of the warning
          */
        void interfaceWarning(Mpris2::InterfaceTest::LocationType locType, const QString& location, const QString& desc);

        /**
          * Reports salient information about the testing.
          *
          * Provides useful information for developers about their
          * implementation, allowing them to ensure that it is
          * reporting what they expect.
          *
          * This will generally be either things that could be a
          * problem, but probably aren't, or indicate that the user
          * needs to check something worked as expected (because it
          * can't be checked directly in the interface).
          */
        void interfaceInfo(Mpris2::InterfaceTest::LocationType locType, const QString& location, const QString& desc);

        /**
         * Reports that some properties have changed.
         *
         * This is tied to the interface's propertiesChanged signal,
         * and so will only be emitted for property changes reported
         * using that mechanism.
         */
        void propertiesChanged(const QStringList& properties);

    private slots:
        void _m_propertiesChanged(const QString& interface,
                                  const QVariantMap& changedProperties,
                                  const QStringList& invalidatedProperties,
                                  const QDBusMessage& signalMessage);
        void delayedIncrementalCheck();

    protected:
        bool getAllProps();
        bool getProp(const QString& propName);

        bool checkPropValid(const QString& propName, QVariant::Type expType, const QVariantMap& oldProps = QVariantMap());
        bool checkNonEmptyStringPropValid(const QString& propName, const QVariantMap& oldProps = QVariantMap());

        virtual void checkProps(const QVariantMap& oldProps = QVariantMap()) = 0;
        virtual void checkUpdatedProperty(const QString& propName) = 0;
        virtual void checkConsistency(const QVariantMap& oldProps = QVariantMap()) = 0;
        virtual void connectSignals();

        QDBusInterface* iface;
        QVariantMap     props;
        QVariantMap     outOfDateProperties; // prop name -> new value
        QStringList     propsNotUpdated;

    private:
        QDBusInterface*    propsIface;
        QTimer*            delayedCheckTimer;
        QMap<QString,uint> propertyUpdateWarningCount;
    };
}

#endif // INTERFACETEST_H