1/* -*- C++ -*-
2 This file implements the state handling in ThreadWeaver.
3
4 SPDX-FileCopyrightText: 2005-2013 Mirko Boehm <mirko@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7
8 $Id: State.h 32 2005-08-17 08:38:01Z mirko $
9*/
10
11#ifndef THREADWEAVER_STATE_H
12#define THREADWEAVER_STATE_H
13
14#include <QString>
15
16#include "queueinterface.h"
17#include "queuesignals.h"
18#include "threadweaver_export.h"
19#include "weaverinterface.h"
20
21namespace ThreadWeaver
22{
23class Job;
24class Thread;
25
26/*!
27 * \relates ThreadWeaver::State
28 *
29 * All weaver objects maintain a state of operation which can be
30 * queried by the application. See the threadweaver documentation on
31 * how the different states are related.
32 *
33 * \value InConstruction
34 * The object is in the state of construction and has not yet
35 * started to process jobs.
36 * \value WorkingHard
37 * Jobs are being processed.
38 * \value Suspending
39 * Job processing is suspended, but some jobs which where already
40 * in progress are not finished yet.
41 * \value Suspended
42 * Job processing is suspended, and no jobs are being
43 * processed.
44 * \value ShuttingDown
45 * The object is being destructed. Jobs might still be processed,
46 * the destructor will wait for all threads to exit and then
47 * end.
48 * \value Destructed
49 * The object is being destructed, and all threads have
50 * exited. No jobs are handled anymore.
51 * \value NoOfStates
52 * Not a state, but a sentinel for the number of defined states.
53 */
54enum StateId {
55 InConstruction = 0,
56 WorkingHard,
57 Suspending,
58 Suspended,
59 ShuttingDown,
60 Destructed,
61 NoOfStates,
62};
63
64/*!
65 * \class ThreadWeaver::State
66 * \inheaderfile ThreadWeaver/State
67 * \inmodule ThreadWeaver
68 *
69 * \brief We use a State pattern to handle the system state in ThreadWeaver.
70 */
71class THREADWEAVER_EXPORT State : public QueueInterface, public WeaverInterface
72{
73public:
74 /*! Default constructor. */
75 explicit State(QueueSignals *weaver);
76
77 /*! Destructor. */
78 ~State() override;
79
80 /*! The ID of the current state.
81 * \sa StateID
82 */
83 QString stateName() const;
84
85 /*! The state Id. */
86 virtual StateId stateId() const = 0;
87
88 /*! The state has been changed so that this object is responsible for
89 * state handling. */
90 virtual void activated();
91
92protected:
93 /*! The Weaver interface this state handles. */
94 virtual QueueInterface *weaver();
95 /*!
96 */
97 virtual const QueueInterface *weaver() const;
98
99private:
100 class Private;
101 Private *const d;
102};
103
104}
105
106#endif // THREADWEAVER_STATE_H
107

source code of threadweaver/src/state.h