TreeFrogFramework  1.18
twebapplication.h
Go to the documentation of this file.
1 #ifndef TWEBAPPLICATION_H
2 #define TWEBAPPLICATION_H
3 
4 #ifdef TF_USE_GUI_MODULE
5 # include <QApplication>
6 #else
7 # include <QCoreApplication>
8 #endif
9 
10 #include <QVector>
11 #include <QSettings>
12 #include <QBasicTimer>
13 #include <TGlobal>
14 #include "qplatformdefs.h"
15 
16 class QTextCodec;
17 
18 
20 #ifdef TF_USE_GUI_MODULE
21  : public QApplication
22 #else
23  : public QCoreApplication
24 #endif
25 {
26  Q_OBJECT
27 public:
29  Invalid = 0,
32  };
33 
34  TWebApplication(int &argc, char **argv);
35  ~TWebApplication();
36 
37  int exec();
38  QString webRootPath() const { return webRootAbsolutePath; }
39  bool webRootExists() const;
40  QString publicPath() const;
41  QString configPath() const;
42  QString libPath() const;
43  QString logPath() const;
44  QString pluginPath() const;
45  QString tmpPath() const;
46  QString databaseEnvironment() const { return dbEnvironment; }
47  void setDatabaseEnvironment(const QString &environment);
48 
49  bool appSettingsFileExists() const;
50  QString appSettingsFilePath() const;
51  QSettings &sqlDatabaseSettings(int databaseId) const;
52  int sqlDatabaseSettingsCount() const;
53  bool isSqlDatabaseAvailable() const;
54  QSettings &mongoDbSettings() const;
55  bool isMongoDbAvailable() const;
56  QSettings &redisSettings() const;
57  bool isRedisAvailable() const;
58  QSettings &loggerSettings() const { return *loggerSetting; }
59  QSettings &validationSettings() const { return *validationSetting; }
60  QString validationErrorMessage(int rule) const;
61  QByteArray internetMediaType(const QString &ext, bool appendCharset = false);
62  MultiProcessingModule multiProcessingModule() const;
63  int maxNumberOfAppServers() const;
64  int maxNumberOfThreadsPerAppServer() const;
65  QString routesConfigFilePath() const;
66  QString systemLogFilePath() const;
67  QString accessLogFilePath() const;
68  QString sqlQueryLogFilePath() const;
69  QTextCodec *codecForInternal() const { return codecInternal; }
70  QTextCodec *codecForHttpOutput() const { return codecHttp; }
71  int applicationServerId() const { return appServerId; }
72  QThread *databaseContextMainThread() const;
73  const QVariantMap &getConfig(const QString &configName);
74  QVariant getConfigValue(const QString &configName, const QString &key, const QVariant &defaultValue = QVariant());
75 
76 #if defined(Q_OS_UNIX)
77  void watchUnixSignal(int sig, bool watch = true);
78  void ignoreUnixSignal(int sig, bool ignore = true);
79 #endif
80 
81 #if defined(Q_OS_WIN)
82  void watchConsoleSignal();
83  void ignoreConsoleSignal();
84 
85 # if QT_VERSION < 0x050000
86  virtual bool winEventFilter(MSG *msg, long *result);
87 # else
88  void watchLocalSocket();
89  static bool sendLocalCtrlMessage(const QByteArray &msg, int targetProcess);
90 
91 private slots:
92  void recvLocalSocket();
93 # endif
94 #endif // Q_OS_WIN
95 
96 protected:
97  void timerEvent(QTimerEvent *event);
98  static int signalNumber();
99 
100 private:
101  QString webRootAbsolutePath;
102  QString dbEnvironment;
103  QVector<QSettings *> sqlSettings;
104  QSettings *mongoSetting {nullptr};
105  QSettings *redisSetting {nullptr};
106  QSettings *loggerSetting {nullptr};
107  QSettings *validationSetting {nullptr};
108  QSettings *mediaTypes {nullptr};
109  QTextCodec *codecInternal {nullptr};
110  QTextCodec *codecHttp {nullptr};
111  int appServerId {-1};
112  QBasicTimer timer;
113  mutable MultiProcessingModule mpm {Invalid};
114  QMap<QString, QVariantMap> configMap;
115 
116  static void resetSignalNumber();
117 
120 };
121 
122 
127 inline void TWebApplication::setDatabaseEnvironment(const QString &environment)
128 {
129  dbEnvironment = environment;
130 }
131 
132 
133 #if defined(Q_OS_WIN) && QT_VERSION >= 0x050000
134 #include <QAbstractNativeEventFilter>
135 
136 class T_CORE_EXPORT TNativeEventFilter : public QAbstractNativeEventFilter
137 {
138 public:
139  virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *);
140 };
141 
142 #endif // QT_VERSION >= 0x050000
143 
144 #endif // TWEBAPPLICATION_H
QSettings & validationSettings() const
Returns a reference to the QSettings object for settings of the validation, which file is validation...
Definition: twebapplication.h:59
#define T_CORE_EXPORT
Definition: tglobal.h:81
Definition: tfnamespace.h:24
MultiProcessingModule
Definition: twebapplication.h:28
QTextCodec * codecForHttpOutput() const
Returns a pointer to the codec of the HTTP output stream used by an action view, which is set by the ...
Definition: twebapplication.h:70
QString databaseEnvironment() const
Returns the database environment, which string is used to load the settings in database.ini.
Definition: twebapplication.h:46
#define T_DISABLE_COPY(Class)
Definition: tglobal.h:137
#define T_DISABLE_MOVE(Class)
Definition: tglobal.h:141
int applicationServerId() const
Definition: twebapplication.h:71
void setDatabaseEnvironment(const QString &environment)
Sets the database environment to environment.
Definition: twebapplication.h:127
Definition: twebapplication.h:31
QTextCodec * codecForInternal() const
Returns a pointer to the codec used internally, which is set by the setting InternalEncoding in the a...
Definition: twebapplication.h:69
Definition: twebapplication.h:30
QString webRootPath() const
Returns the absolute path of the web root directory.
Definition: twebapplication.h:38
The TWebApplication class provides an event loop for TreeFrog applications.
Definition: twebapplication.h:19
QSettings & loggerSettings() const
Returns a reference to the QSettings object for settings of the logger, which file is logger...
Definition: twebapplication.h:58