~pieq/checkbox/add-30suspend-1reboot-cycles-support

« back to all changes in this revision

Viewing changes to checkbox-gui/gui-engine/gui-engine.h

  • Committer: Zygmunt Krynicki
  • Date: 2015-09-17 13:32:37 UTC
  • mto: This revision was merged to the branch mainline in revision 4014.
  • Revision ID: zygmunt.krynicki@canonical.com-20150917133237-7d4mdzlgpin1na9g
checkbox-gui: remove checkbox gui entirely

This patch removes all of checkbox-gui. This was long in the making but
it's now done. We cannot maintain this codebase effectively. Keeping it
around slows us down as we are unable to make feature-parity changes
here with the same simplicity that we can make them elsewhere, most
notably in checkbox-converged.

The code has served us well but it is the time to let go and make
checkbox-converged the only application that we use across all of Ubuntu
releases and across different environments (phone, table and desktop).

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * This file is part of Checkbox
3
 
 *
4
 
 * Copyright 2013 Canonical Ltd.
5
 
 *
6
 
 * Authors:
7
 
 * - Andrew Haigh <andrew.haigh@cellsoftware.co.uk>
8
 
 *
9
 
 * This program is free software; you can redistribute it and/or modify
10
 
 * it under the terms of the GNU General Public License as published by
11
 
 * the Free Software Foundation; version 3.
12
 
 *
13
 
 * This program is distributed in the hope that it will be useful,
14
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
 * GNU General Public License for more details.
17
 
 *
18
 
 * You should have received a copy of the GNU General Public License
19
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 
 */
21
 
 
22
 
 #ifndef PLAINBOX_GUI_H
23
 
 #define PLAINBOX_GUI_H
24
 
 
25
 
#include <QtQml/qqml.h>
26
 
#include <QtQml/QQmlExtensionPlugin>
27
 
#include <QtDBus/QtDBus>
28
 
#include <QtXml/QDomDocument>
29
 
 
30
 
#include "PBJsonUtils.h"
31
 
 
32
 
#include <QtWidgets/QFileDialog>
33
 
 
34
 
class GuiEnginePlugin : public QQmlExtensionPlugin
35
 
{
36
 
    Q_OBJECT
37
 
    Q_PLUGIN_METADATA(IID "guiengine")
38
 
 
39
 
public:
40
 
 
41
 
    // inherited from QQmlExtensionPlugin
42
 
    void registerTypes(const char *uri);
43
 
};
44
 
 
45
 
#include "PBTypes.h"
46
 
#include "PBNames.h"
47
 
 
48
 
#include "PBTreeNode.h"
49
 
 
50
 
#include "JobTreeNode.h"
51
 
 
52
 
// Currently used for the metadata Title of saved sessions in Plainbox
53
 
static const QString GUI_ENGINE_NAME_STR("GuiEngine");
54
 
 
55
 
 
56
 
/* We need to extract the signature of GetEstimatedDuration(): (dd) */
57
 
struct EstimatedDuration{
58
 
    double automated_duration;
59
 
    double manual_duration;
60
 
};
61
 
 
62
 
Q_DECLARE_METATYPE(EstimatedDuration);
63
 
 
64
 
/* This class embodies the wrapper which can call Plainbox APIs over D-Bus
65
 
 *
66
 
 * Its intended clients are Test Suite selection, test selection etc.
67
 
 *
68
 
 * There should only be one instance of this class
69
 
 */
70
 
class GuiEngine : public QObject
71
 
{
72
 
    Q_OBJECT
73
 
 
74
 
    private:
75
 
        enum EngineState {
76
 
        UNINITIALISED,
77
 
        READY
78
 
        };
79
 
 
80
 
public:
81
 
        GuiEngine( QObject*parent = 0);
82
 
 
83
 
public slots:
84
 
 
85
 
        /* Called by the QML/Qt GUI */
86
 
 
87
 
        // Manage GuiEngine lifetime
88
 
        bool Initialise(void);
89
 
        bool Shutdown(void);
90
 
 
91
 
        // Returns whitelist object path, whitelist name
92
 
        QMap<QDBusObjectPath,QString> GetWhiteListPathsAndNames(void);
93
 
 
94
 
        void SetWhiteList(const QDBusObjectPath opath, const bool check);
95
 
 
96
 
        void SetRealJobsList(const QList<QDBusObjectPath> &real_jobs) {
97
 
            m_final_run_list = real_jobs;
98
 
        }
99
 
 
100
 
        void SetRerunJobsList(const QList<QDBusObjectPath> &rerun_jobs) {
101
 
            m_rerun_list = rerun_jobs;
102
 
        }
103
 
 
104
 
        /* Run all the jobs of type "local" in order to generate the true
105
 
         * list of tests from which the user can select.
106
 
         */
107
 
        void RunLocalJobs(void);
108
 
 
109
 
        // Helper which prepares the corrected run-list from plainbox
110
 
        int PrepareJobs(void);
111
 
 
112
 
        void RunJobs(void);
113
 
 
114
 
        // Used when running the real tests
115
 
        void Pause(void);
116
 
        void Resume(void);
117
 
 
118
 
        // Session estimated duration
119
 
        QVariantMap GetEstimatedDuration();
120
 
 
121
 
        /* Signal receivers from Plainbox
122
 
         */
123
 
        void InterfacesAdded(QDBusMessage msg);
124
 
        void InterfacesRemoved(QDBusMessage msg);
125
 
 
126
 
        void CatchallShowInteractiveUISignalsHandler(QDBusMessage msg);
127
 
        void CatchallAskForOutcomeSignalsHandler(QDBusMessage msg);
128
 
        void CatchallIOLogGeneratedSignalsHandler(QDBusMessage msg);
129
 
        void CatchallLocalJobResultAvailableSignalsHandler(QDBusMessage msg);
130
 
        void CatchallJobResultAvailableSignalsHandler(QDBusMessage msg);
131
 
        /* Helper functions for logging and testing
132
 
         */
133
 
 
134
 
        // Used by the test program test-gui-engine
135
 
        void AcknowledgeJobsDone(void);
136
 
        void AcknowledgeLocalJobsDone(void);
137
 
        void ManualTest(const int outcome);
138
 
 
139
 
        // Returns a list of DBus Object Paths for valid tests
140
 
        const QList<QDBusObjectPath>& GetValidRunList(void);
141
 
 
142
 
        /* Returns a list of DBusObjectPaths representing tests
143
 
         * which are relevant for human beings (i.e. excludes resource jobs)
144
 
         */
145
 
        const QList<QDBusObjectPath>& GetVisibleRunList(void);
146
 
 
147
 
        /* Returns a list of DBusObjectPaths representing tests
148
 
         * which are relevant for human beings (i.e. excludes resource jobs)
149
 
         */
150
 
        void SetVisibleJobsList(const QList<QDBusObjectPath> &visible_jobs) {
151
 
            m_visible_run_list = visible_jobs;
152
 
        }
153
 
 
154
 
        // Useful for the progress bar in the run manager
155
 
        int ValidRunListCount(void);
156
 
 
157
 
        // Resume after dealing with Manual Interaction Dialog
158
 
        void ResumeFromManualInteractionDialog(bool run_test, \
159
 
                                               const QString outcome, \
160
 
                                               const QString comments);
161
 
 
162
 
        // Convenience functions for the GUI
163
 
        QString GuiExportSessionAsXML(void);
164
 
        QString GuiExportSessionAsHTML(void);
165
 
        QString GuiExportSessionAsXLSX(void);
166
 
        QString GuiExportSessionAsJSON(void);
167
 
 
168
 
        bool GuiExportSessionToFileAsXML(const QString& output_file,
169
 
                                         const QStringList& option_list,
170
 
                                         const QString& exporter_unit);
171
 
        bool GuiExportSessionToFileAsHTML(const QString& output_file,
172
 
                                          const QStringList& option_list,
173
 
                                          const QString& exporter_unit);
174
 
        bool GuiExportSessionToFileAsXLSX(const QString& output_file,
175
 
                                          const QStringList& option_list,
176
 
                                          const QString& exporter_unit);
177
 
        bool GuiExportSessionToFileAsJSON(const QString& output_file,
178
 
                                          const QStringList& option_list,
179
 
                                          const QString& exporter_unit);
180
 
 
181
 
        const QString SendSubmissionViaCertificationTransport( \
182
 
                                     const QString &submission_path,
183
 
                                     const QString &secure_id,
184
 
                                     const bool submitToHexr);
185
 
        
186
 
        const QString SendSubmissionViaLaunchpadTransport( \
187
 
                                     const QString &submission_path,
188
 
                                     const QString &email);
189
 
 
190
 
        // Convenience until we move to Qt 5.1 and the FileDialog component
191
 
        QString GetSaveFileName(const QString& defaultName, const QString& text);
192
 
 
193
 
        // Session management from the GUI
194
 
        void GuiSessionRemove(void);
195
 
        const QString GuiPreviousSessionFile(void);
196
 
 
197
 
        const QString GetIOLog(const QString& job);
198
 
 
199
 
        // Retrieve all the previous session data
200
 
        void GuiResumeSession(const bool re_run, const bool continue_pass = false);
201
 
        void GuiCreateSession(void);
202
 
 
203
 
public:
204
 
        // Returns a list of all the jobnodes
205
 
        QList<PBTreeNode*> GetJobNodes(void);
206
 
 
207
 
        // Returns a tree of all the jobs
208
 
        JobTreeNode* GetJobTreeNodes();
209
 
 
210
 
        // Obtain The Results
211
 
        const QString ExportSession(const QDBusObjectPath session, \
212
 
                                    const QString& output_format, \
213
 
                                    const QStringList& option_list);
214
 
 
215
 
 
216
 
        const QString ExportSessionToFile(const QDBusObjectPath session, \
217
 
                                    const QString& output_format, \
218
 
                                    const QStringList& option_list,
219
 
                                    const QString& exporter_unit, \
220
 
                                    const QString& output_file);
221
 
        
222
 
        QString SendDataViaTransport(const QDBusObjectPath session, \
223
 
                                     const QString &transport, \
224
 
                                     const QString &url, \
225
 
                                     const QString &option_list, \
226
 
                                     const QString &data);
227
 
        
228
 
        // Suspend and Resume Session
229
 
        void SessionPersistentSave(const QDBusObjectPath session);
230
 
        void SessionRemove(const QDBusObjectPath session);
231
 
        const QString PreviousSessionFile(const QDBusObjectPath session);
232
 
 
233
 
        // Ensure the RunManager view is updated with the recovered data
234
 
        void ResumeGetOutcomes(void);
235
 
 
236
 
signals:
237
 
        // Instruct the GUI to update itself
238
 
        void localJobsCompleted(void);
239
 
 
240
 
        // When starting a run of jobs
241
 
        void jobsBegin(void);
242
 
 
243
 
        void updateGuiBeginJob(const QString& job_id, \
244
 
                                const int current_job_index,
245
 
                                const QString& test_name);
246
 
 
247
 
        // When a job has completed
248
 
        void updateGuiEndJob(const QString& job_id, \
249
 
                              const int current_job_index,
250
 
                              const int outcome,
251
 
                              const QString& test_name);
252
 
 
253
 
        // When all jobs are completed
254
 
        void jobsCompleted(void);
255
 
 
256
 
        // Manual Interaction Dialog
257
 
        void raiseManualInteractionDialog(const int suggested_outcome /* from PB */, bool show_test);
258
 
 
259
 
        void updateManualInteractionDialog(const int suggested_outcome, bool show_test);
260
 
 
261
 
        void closeManualInteractionDialog(void);
262
 
 
263
 
private:
264
 
        // Helper function when generating the desired local and real jobs
265
 
        QList<QDBusObjectPath> GenerateDesiredJobList();
266
 
 
267
 
        bool RefreshPBObjects(void);
268
 
 
269
 
        const PBTreeNode* GetRootJobsNode(const PBTreeNode *node);
270
 
        const PBTreeNode* GetRootWhiteListNode(const PBTreeNode *node);
271
 
 
272
 
        QList<PBTreeNode*> GetWhiteListNodes(void);
273
 
 
274
 
        bool WhiteListDesignates(const QDBusObjectPath white_opath, \
275
 
                                 const QDBusObjectPath job_opath);
276
 
 
277
 
        QDBusObjectPath CreateSession(QList<QDBusObjectPath> job_list);
278
 
 
279
 
 
280
 
        void ConnectJobReceivers(void);
281
 
        QList<QDBusObjectPath> GetLocalJobs(const QList<QDBusObjectPath> &job_list);
282
 
 
283
 
        QList<QDBusObjectPath> GetAllJobs(void);
284
 
 
285
 
 
286
 
        // SessionState methods
287
 
        QStringList UpdateDesiredJobList(const QDBusObjectPath session, \
288
 
                                         QList<QDBusObjectPath> desired_job_list);
289
 
 
290
 
        void SessionResume(const QDBusObjectPath session);
291
 
        // SessionState Properties
292
 
        QList<QDBusObjectPath> SessionStateDesiredJobList(const QDBusObjectPath session);
293
 
        QList<QDBusObjectPath> SessionStateRunList(const QDBusObjectPath session);
294
 
        QList<QDBusObjectPath> SessionStateJobList(const QDBusObjectPath session);
295
 
        void SetSessionStateMetadata(const QDBusObjectPath session, \
296
 
                                     const QString& flags, \
297
 
                                     const QString& running_job_name, \
298
 
                                     const QString& title,
299
 
                                     const QByteArray& app_blob,
300
 
                                     const QString& app_id);
301
 
 
302
 
        const QVariantMap SessionStateMetadata(const QDBusObjectPath session);
303
 
        // Encode/decode of internal state of this class
304
 
        void EncodeGuiEngineStateAsJSON(void);
305
 
        void DecodeGuiEngineStateFromJSON(void);
306
 
 
307
 
        void UpdateJobResult(const QDBusObjectPath session, \
308
 
                                        const QDBusObjectPath &job_path, \
309
 
                                        const QDBusObjectPath &result_path);
310
 
 
311
 
        // JobRunner Methods
312
 
        void RunCommand(const QDBusObjectPath& runner);
313
 
        void SetOutcome(const QDBusObjectPath& runner, \
314
 
                        const QString& outcome, \
315
 
                        const QString& comments);
316
 
 
317
 
        /* A synthesised method. This is needed in the case of skipping tests
318
 
         * on resuming a session, since in this circumstance, there is no
319
 
         * runner object to serve as a means of setting the outcome.
320
 
         */
321
 
        QDBusObjectPath SetJobOutcome(const QDBusObjectPath& job_path, \
322
 
                                      const QString& outcome, \
323
 
                                      const QString& comments);
324
 
 
325
 
        bool JobCanStart(const QDBusObjectPath& job_path);
326
 
        const QString GetReadinessDescription(const QDBusObjectPath& job_path);
327
 
 
328
 
        // Job Properties
329
 
        QString GetCommand(const QDBusObjectPath& opath);
330
 
 
331
 
        // Service Methods
332
 
        void RunJob(const QDBusObjectPath session, const QDBusObjectPath opath);
333
 
 
334
 
        // Convenience functions
335
 
        int GetOutcomeFromJobResultPath(const QDBusObjectPath &opath);
336
 
        int GetOutcomeFromJobPath(const QDBusObjectPath &opath);
337
 
        const QString GetIOLogFromJobPath(const QDBusObjectPath &opath);
338
 
 
339
 
        const QString ConvertOutcome(const int outcome);
340
 
 
341
 
        // Find the next real job index to run based on current index through m_run_list
342
 
        int NextRunJobIndex(int index);
343
 
 
344
 
protected:  // for test purposes only
345
 
        // JobStateMap
346
 
        jsm_t GetJobStateMap(void);
347
 
 
348
 
        void GetJobStates(void);
349
 
 
350
 
        void GetJobResults(void);
351
 
 
352
 
        // Debugging tool
353
 
        const QString JobNameFromObjectPath(const QDBusObjectPath& opath);
354
 
 
355
 
        const QDBusObjectPath GetCurrentSession(void);
356
 
 
357
 
private:
358
 
        EngineState enginestate;
359
 
 
360
 
        /* Contains our Tree of Plainbox objects (Methods, results, tests etc)
361
 
         * Structure is as exposed on DBus.
362
 
         */
363
 
        PBTreeNode* pb_objects;
364
 
 
365
 
        // Have we got valid tree of PlainBox objects?
366
 
        bool valid_pb_objects;
367
 
 
368
 
        // These may go later, but are helpful for now
369
 
 
370
 
        // A list of the selected whitelists from the user
371
 
        QMap<QDBusObjectPath, bool> whitelist;
372
 
 
373
 
        // A user-selected list of tests. We store the object path
374
 
        QMap<QDBusObjectPath, bool> tests;
375
 
 
376
 
        // All the jobs ultimately selected by the user
377
 
        QList<QDBusObjectPath> m_final_run_list;
378
 
 
379
 
        // We only care about one session
380
 
        QDBusObjectPath m_session;
381
 
 
382
 
        // Job Tree as defined by the "via" properties
383
 
        JobTreeNode* job_tree;
384
 
 
385
 
        QList<QDBusObjectPath> m_job_list;
386
 
 
387
 
        QList<QDBusObjectPath> m_desired_job_list;
388
 
 
389
 
        QList<QDBusObjectPath> m_run_list;
390
 
 
391
 
        QList<QDBusObjectPath> m_local_job_list;
392
 
 
393
 
        QList<QDBusObjectPath> m_local_run_list;
394
 
 
395
 
        QList<QDBusObjectPath> m_desired_local_job_list;
396
 
 
397
 
        /* Re-run list. First time round it contains ALL m_run_list
398
 
         * but on subsequent rounds its only those selected by the user
399
 
         */
400
 
        QList<QDBusObjectPath> m_rerun_list;
401
 
 
402
 
        /* Visible job list; this is mainly for the benefit
403
 
         * of the gui, which needs to show real jobs being run,
404
 
         * together with local jobs used to group the real tests being
405
 
         * run.
406
 
         *
407
 
         * Its not ideal, just an interim solution. Ultimately,
408
 
         * it would be best to be able to populate the gui with a single
409
 
         * call to extract all the relevant data from the gui-engine.
410
 
         */
411
 
        QList<QDBusObjectPath> m_visible_run_list;
412
 
 
413
 
        // The currently running job as an index into m_run_list
414
 
        int m_current_job_index;
415
 
 
416
 
        // The current job path (for tests being run)
417
 
        QDBusObjectPath m_current_job_path;
418
 
 
419
 
        // Job State Map
420
 
        jsm_t m_jsm;
421
 
 
422
 
        // Job State List (NB: These are NOT in pb_objects!)
423
 
        QList<PBTreeNode*> m_job_state_list;
424
 
 
425
 
        /* Job Results. These could be either DiskJobResults or MemoryJobResults
426
 
         *
427
 
         * (NB: These are NOT in pb_objects!)
428
 
         */
429
 
        QList<PBTreeNode*> m_job_state_results;
430
 
 
431
 
        // Are we running tests or not? (Used for Pause/Resume)
432
 
        bool m_running;
433
 
        bool m_waiting_result;
434
 
 
435
 
        // Are we resuming a session?
436
 
        bool m_resuming;
437
 
 
438
 
        // Are we resuming a session and forcing the previous test result?
439
 
        bool m_resuming_force_result;
440
 
 
441
 
        // Used to preserve interim data from Manual Interaction event
442
 
        QDBusObjectPath m_runner;
443
 
 
444
 
        /* lets us choose whether to raise the manual interaction dialog
445
 
        * or simply update it
446
 
        */
447
 
        bool m_running_manual_job;
448
 
 
449
 
        /* Records whether the results of running the tests have been submitted
450
 
        * Note that depending on the GUI, this may simply mean saved to disk,
451
 
        * or submitted to a validation website. it may not even matter. But this
452
 
        * is here in order to allow the state to be preserved by plainbox
453
 
        * in a saved session.
454
 
        */
455
 
        bool m_submitted;
456
 
// Used by the test program
457
 
protected:
458
 
        bool m_local_jobs_done;
459
 
 
460
 
        bool m_jobs_done;
461
 
 
462
 
        bool m_testing_manual_job;
463
 
};
464
 
 
465
 
 #endif