QtBackgroundProcess  1.5.2
A Library to create background applications with simple, automated foreground control
app.h
1 #ifndef QTBACKGROUNDPROCESS_APP_H
2 #define QTBACKGROUNDPROCESS_APP_H
3 
4 #include "QtBackgroundProcess/qtbackgroundprocess_global.h"
5 
6 #include <QtCore/qcommandlineparser.h>
7 #include <QtCore/qcoreapplication.h>
8 #include <QtCore/qexception.h>
9 
10 #include <functional>
11 
14 
15 class Terminal;
16 
18 class Q_BACKGROUNDPROCESS_EXPORT NotAllowedInRunningStateException : public QException
19 {
20 public:
22 
24  const char *what() const noexcept override;
25 
27  void raise() const override;
29  QException *clone() const override;
30 };
31 
32 class AppPrivate;
34 class Q_BACKGROUNDPROCESS_EXPORT App : public QCoreApplication
35 {
36  Q_OBJECT
37  friend class AppPrivate;
38 
40  Q_PROPERTY(QString instanceID READ instanceID WRITE setInstanceID RESET createDefaultInstanceID)
42  Q_PROPERTY(bool forwardMasterLog READ forwardMasterLog WRITE setForwardMasterLog)
44  Q_PROPERTY(bool autoStartMaster READ autoStartMaster WRITE setAutoStartMaster)
46  Q_PROPERTY(bool ignoreMultiStarts READ ignoreMultiStarts WRITE setIgnoreMultiStarts)
48  Q_PROPERTY(bool autoDeleteTerminals READ autoDeleteTerminals WRITE setAutoDeleteTerminals)
50  Q_PROPERTY(bool autoKillTerminals READ autoKillTerminals WRITE setAutoKillTerminals)
52  Q_PROPERTY(QList<Terminal*> connectedTerminals READ connectedTerminals NOTIFY connectedTerminalsChanged)
53 
54 public:
56  App(int &argc, char **argv, int flags = ApplicationFlags);
58  ~App();
59 
61  QString instanceID() const;
63  bool forwardMasterLog() const;
65  bool autoStartMaster() const;
67  bool ignoreMultiStarts() const;
69  bool autoDeleteTerminals() const;
71  bool autoKillTerminals() const;
72 
74  void setParserSetupFunction(const std::function<void(QCommandLineParser &)> &function);
76  void setStartupFunction(const std::function<int (const QCommandLineParser &)> &function);
78  void setShutdownRequestFunction(const std::function<bool(const QCommandLineParser &, int&)> &function);
80  void setShutdownRequestFunction(const std::function<bool(Terminal*, int&)> &function);
81 
83  int exec();
84 
86  QList<Terminal*> connectedTerminals() const;
87 
88 public Q_SLOTS:
90  void createDefaultInstanceID(bool overwrite = true);
92  void setInstanceID(QString instanceID, bool useAsSeed = true);
94  void setForwardMasterLog(bool forwardMasterLog);
96  void setAutoStartMaster(bool autoStartMaster);
98  void setIgnoreMultiStarts(bool ignoreMultiStarts);
100  void setAutoDeleteTerminals(bool autoDeleteTerminals, bool changeCurrent = false);
102  void setAutoKillTerminals(bool autoKillTerminals, bool killCurrent = false);
103 
104 Q_SIGNALS:
106  void newTerminalConnected(QtBackgroundProcess::Terminal *terminal, QPrivateSignal);
108  void commandReceived(QSharedPointer<QCommandLineParser> parser, bool isStarter, QPrivateSignal);
109 
111  void connectedTerminalsChanged(QList<Terminal*> connectedTerminals, QPrivateSignal);
112 
113 protected:
115  virtual void setupParser(QCommandLineParser &parser, bool useShortOptions = true);
117  virtual int startupApp(const QCommandLineParser &parser);
119  virtual bool requestAppShutdown(Terminal *terminal, int &exitCode);
120 
121 private:
122  AppPrivate* d;
123 };
124 
125 }
126 
127 #undef qApp
128 #define qApp static_cast<QtBackgroundProcess::App*>(QCoreApplication::instance())
129 
130 #endif // QTBACKGROUNDPROCESS_APP_H
Represents a connection to a terminal in the master process.
Definition: terminal.h:16
STL namespace.
The Namespace containing all classes of the QtBackgroundProcess module.
Definition: app.h:13
Will be thrown, if you perform an operation, that is not allowed in running state.
Definition: app.h:18
The background process application. The main class of QtBackgroundProcess.
Definition: app.h:34