Qx v0.5.8
Qt Extensions Library
Loading...
Searching...
No Matches
qx-processbider.h
1#ifndef QX_PROCCESSBIDER_H
2#define QX_PROCCESSBIDER_H
3
4// Shared Lib Support
5#include "qx/core/qx_core_export.h"
6
7// Qt Includes
8#include <QObject>
9
10// Inter-component Includes
12
13using namespace std::chrono_literals;
14
15namespace Qx
16{
17
18class QX_CORE_EXPORT ProcessBiderError final : public AbstractError<"Qx::ProcessBiderError", 6>
19{
20 friend class ProcessBider;
21//-Class Enums-------------------------------------------------------------
22public:
23 enum Type
24 {
25 NoError,
27 FailedToClose
28 };
29
30//-Class Variables-------------------------------------------------------------
31private:
32 static inline const QHash<Type, QString> ERR_STRINGS{
33 {NoError, u""_s},
34 {FailedToHook, u"Could not hook the process in order to bide on it."_s},
35 {FailedToClose, u"Could not close the bided process."_s}
36 };
37
38//-Instance Variables-------------------------------------------------------------
39private:
40 Type mType;
41 QString mProcessName;
42
43//-Constructor-------------------------------------------------------------
44private:
45 ProcessBiderError(Type t, const QString& pn);
46
47//-Instance Functions-------------------------------------------------------------
48private:
49 quint32 deriveValue() const override;
50 QString derivePrimary() const override;
51 QString deriveSecondary() const override;
52
53public:
54 bool isValid() const;
55 Type type() const;
56 QString processName() const;
57};
58
59class QX_CORE_EXPORT ProcessBider : public QObject
60{
61 friend class ProcessBiderManager;
62 Q_OBJECT
63//-Class Types----------------------------------------------------------------------------------------------
64public:
65 enum ResultType { Fail, Expired, Abandoned };
66
67//-Instance Members------------------------------------------------------------------------------------------
68private:
69 // Data
70 QString mName;
71 std::chrono::milliseconds mGrace;
72#ifdef __linux__
73 std::chrono::milliseconds mPollRate;
74#endif
75 bool mInitialGrace;
76
77 // Functional
78 bool mBiding;
79
80//-Constructor----------------------------------------------------------------------------------------------
81public:
82 explicit ProcessBider(QObject* parent = nullptr, const QString& processName = {});
83
84//-Instance Functions----------------------------------------------------------------------------------------------
85public:
86 bool isBiding() const;
87 QString processName() const;
88 std::chrono::milliseconds respawnGrace() const;
89 bool initialGrace() const;
90
91 void setProcessName(const QString& name);
92 void setRespawnGrace(std::chrono::milliseconds grace);
93 void setInitialGrace(bool initialGrace);
94
95#ifdef __linux__
96 std::chrono::milliseconds pollRate() const;
97 void setPollRate(std::chrono::milliseconds rate);
98#endif
99
100//-Slots------------------------------------------------------------------------------------------------------------
101private slots:
102 void handleResultReady(ResultType result);
103 void handleCloseFailure();
104
105public slots:
106 void start();
107 void stop();
108 void closeProcess(std::chrono::milliseconds timeout = 1000ms, bool force = false);
109
110//-Signals------------------------------------------------------------------------------------------------------------
111signals:
112 void started();
117 void stopped();
119 void finished(ResultType result);
120
122 // Temporary until using PIMPL or changing implementation otherwise
123 void __startClose(std::chrono::milliseconds timeout, bool force);
125};
126
127}
128
129#endif // QX_PROCCESSBIDER_H
The AbstractError template class completes the Error interface and acts as the base class from which ...
Definition qx-abstracterror.h:86
The ProcessBiderError class describes errors than can occur during process biding.
Definition qx-processbider.h:19
Type
Definition qx-processbider.h:24
@ FailedToHook
Definition qx-processbider.h:26
The ProcessBider class monitors the presence of a process and signals when that process ends.
Definition qx-processbider.h:60
void finished(ResultType result)
ResultType
Definition qx-processbider.h:65
void errorOccurred(ProcessBiderError error)
The Qx namespace is the main namespace through which all non-global functionality of the Qx library i...
Definition qx-processwaiter.cpp:5
QString processName(quint32 processId)
Definition qx-system_linux.cpp:434
The qx-abstracterror.h header file provides access to the base class from which custom error types sh...