ThreadWeaver

state.h
1 /* -*- C++ -*-
2  This file implements the state handling in ThreadWeaver.
3 
4  SPDX-FileCopyrightText: 2005-2013 Mirko Boehm <[email protected]>
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 
21 namespace ThreadWeaver
22 {
23 class Job;
24 class Thread;
25 
26 /** All weaver objects maintain a state of operation which can be
27  * queried by the application. See the threadweaver documentation on
28  * how the different states are related.
29  */
30 
31 enum StateId {
32  /** The object is in the state of construction and has not yet
33  * started to process jobs. */
34  InConstruction = 0,
35  /** Jobs are being processed. */
36  WorkingHard,
37  /** Job processing is suspended, but some jobs which where already
38  * in progress are not finished yet. */
39  Suspending,
40  /** Job processing is suspended, and no jobs are being
41  * processed. */
42  Suspended,
43  /** The object is being destructed. Jobs might still be processed,
44  * the destructor will wait for all threads to exit and then
45  * end. */
46  ShuttingDown,
47  /** The object is being destructed, and all threads have
48  * exited. No jobs are handled anymore. */
49  Destructed,
50  /** Not a state, but a sentinel for the number of defined states. */
51  NoOfStates,
52 };
53 
54 /** We use a State pattern to handle the system state in ThreadWeaver. */
55 class THREADWEAVER_EXPORT State : public QueueInterface, public WeaverInterface
56 {
57 public:
58  /** Default constructor. */
59  explicit State(QueueSignals *weaver);
60 
61  /** Destructor. */
62  ~State() override;
63 
64  /** The ID of the current state.
65  * @see StateNames, StateID
66  */
67  QString stateName() const;
68 
69  /** The state Id. */
70  virtual StateId stateId() const = 0;
71 
72  /** The state has been changed so that this object is responsible for
73  * state handling. */
74  virtual void activated();
75 
76 protected:
77  /** The Weaver interface this state handles. */
78  virtual QueueInterface *weaver();
79  virtual const QueueInterface *weaver() const;
80 
81 private:
82  class Private;
83  Private *const d;
84 };
85 
86 }
87 
88 #endif // THREADWEAVER_STATE_H
QueueSignals declares the Qt signals shared by the Queue and Weaver classes.
Definition: queuesignals.h:23
We use a State pattern to handle the system state in ThreadWeaver.
Definition: state.h:55
WeaverInterface provides a common interface for weaver implementations.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 04:09:38 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.