TreeFrogFramework  2.8
twebapplication.h
Go to the documentation of this file.
1 #pragma once
2 #ifdef TF_USE_GUI_MODULE
3 #include <QApplication>
4 #else
5 #include <QCoreApplication>
6 #endif
7 
8 #include "qplatformdefs.h"
9 #include <QBasicTimer>
10 #include <QVariant>
11 #include <QVector>
12 #include <TGlobal>
13 
14 class QTextCodec;
15 
16 
18 #ifdef TF_USE_GUI_MODULE
19  : public QApplication
20 #else
21  : public QCoreApplication
22 #endif
23 {
24  Q_OBJECT
25 public:
27  Invalid = 0,
28  Thread = 1,
29  Epoll = 2,
30  };
31 
32  TWebApplication(int &argc, char **argv);
33  ~TWebApplication();
34 
35  int exec();
36  QString webRootPath() const { return _webRootAbsolutePath; }
37  bool webRootExists() const;
38  QString publicPath() const;
39  QString configPath() const;
40  QString libPath() const;
41  QString logPath() const;
42  QString pluginPath() const;
43  QString tmpPath() const;
44  QString databaseEnvironment() const { return _dbEnvironment; }
45  void setDatabaseEnvironment(const QString &environment);
46 
47  bool appSettingsFileExists() const;
48  QString appSettingsFilePath() const;
49  const QVariantMap &sqlDatabaseSettings(int databaseId) const;
50  int sqlDatabaseSettingsCount() const;
51  const QVariantMap &kvsSettings(Tf::KvsEngine engine) const;
52  bool isKvsAvailable(Tf::KvsEngine engine) const;
53  bool cacheEnabled() const;
54  QString cacheBackend() const;
55  int databaseIdForCache() const;
56  const QVariantMap &loggerSettings() const { return _loggerSetting; }
57  const QVariantMap &validationSettings() const { return _validationSetting; }
58  QString validationErrorMessage(int rule) const;
59  QByteArray internetMediaType(const QString &ext, bool appendCharset = false);
60  MultiProcessingModule multiProcessingModule() const;
61  void setMultiProcessingModule(MultiProcessingModule mpm) { _mpmTemp = mpm; }
62  int maxNumberOfAppServers() const;
63  int maxNumberOfThreadsPerAppServer() const;
64  QString routesConfigFilePath() const;
65  QString systemLogFilePath() const;
66  QString accessLogFilePath() const;
67  QString sqlQueryLogFilePath() const;
68 #if QT_VERSION < 0x060000
69  QTextCodec *codecForInternal() const { return _codecInternal; }
70  QTextCodec *codecForHttpOutput() const { return _codecHttp; }
71 #else
72  QStringConverter::Encoding encodingForInternal() const { return _encodingInternal; }
73  QStringConverter::Encoding encodingForHttpOutput() const { return _encodingHttp; }
74 #endif
75  int applicationServerId() const { return _appServerId; }
76  QThread *databaseContextMainThread() const;
77  TDatabaseContext *mainDatabaseContext() const;
78  const QVariantMap &getConfig(const QString &configName);
79  QVariant getConfigValue(const QString &configName, const QString &key, const QVariant &defaultValue = QVariant());
80  void initializeCache();
81  void cleanupCache();
82 
83 #if defined(Q_OS_UNIX)
84  void watchUnixSignal(int sig, bool watch = true);
85  void ignoreUnixSignal(int sig, bool ignore = true);
86 #endif
87 
88 #if defined(Q_OS_WIN)
89  void watchConsoleSignal();
90  void ignoreConsoleSignal();
91  void watchLocalSocket();
92  static bool sendLocalCtrlMessage(const QByteArray &msg, int targetProcess);
93 
94 private slots:
95  void recvLocalSocket();
96 #endif // Q_OS_WIN
97 
98 protected:
99  void timerEvent(QTimerEvent *event);
100  static int signalNumber();
101 
102 private:
103  QString _webRootAbsolutePath;
104  QString _dbEnvironment;
105  QVector<QVariantMap> _sqlSettings;
106  QVector<QVariantMap> _kvsSettings {(int)Tf::KvsEngine::Num};
107  QVariantMap _loggerSetting;
108  QVariantMap _validationSetting;
109  QVariantMap _mediaTypes;
110 #if QT_VERSION < 0x060000
111  QTextCodec *_codecInternal {nullptr};
112  QTextCodec *_codecHttp {nullptr};
113 #else
114  QStringConverter::Encoding _encodingInternal {QStringConverter::Utf8};
115  QStringConverter::Encoding _encodingHttp {QStringConverter::Utf8};
116 #endif
117  int _appServerId {-1};
118  QBasicTimer _timer;
119  QMap<QString, QVariantMap> _configMap;
120  int _cacheSqlDbIndex {-1};
121  MultiProcessingModule _mpmTemp {Invalid};
122 
123  static void resetSignalNumber();
124 
127 };
128 
129 
134 inline void TWebApplication::setDatabaseEnvironment(const QString &environment)
135 {
136  _dbEnvironment = environment;
137 }
138 
139 
140 #if defined(Q_OS_WIN)
141 #include <QAbstractNativeEventFilter>
142 
143 class T_CORE_EXPORT TNativeEventFilter : public QAbstractNativeEventFilter {
144 public:
145 #if QT_VERSION < 0x060000
146  virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *);
147 #else
148  virtual bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *);
149 #endif
150 };
151 
152 #endif // Q_OS_WIN
153 
The TDatabaseContext class is the base class of contexts for database access.
Definition: tdatabasecontext.h:11
The TWebApplication class provides an event loop for TreeFrog applications.
Definition: twebapplication.h:23
QString databaseEnvironment() const
Returns the database environment, which string is used to load the settings in database....
Definition: twebapplication.h:44
QStringConverter::Encoding encodingForInternal() const
Definition: twebapplication.h:72
void setMultiProcessingModule(MultiProcessingModule mpm)
Definition: twebapplication.h:61
MultiProcessingModule
Definition: twebapplication.h:26
int applicationServerId() const
Definition: twebapplication.h:75
QStringConverter::Encoding encodingForHttpOutput() const
Definition: twebapplication.h:73
const QVariantMap & validationSettings() const
Returns a reference to the QSettings object for settings of the validation, which file is validation....
Definition: twebapplication.h:57
QString webRootPath() const
Returns the absolute path of the web root directory.
Definition: twebapplication.h:36
const QVariantMap & loggerSettings() const
Returns a reference to the QSettings object for settings of the logger, which file is logger....
Definition: twebapplication.h:56
void setDatabaseEnvironment(const QString &environment)
Sets the database environment to environment.
Definition: twebapplication.h:134
@ Invalid
Definition: tfnamespace.h:22
KvsEngine
Definition: tfnamespace.h:239
@ Encoding
Definition: tfnamespace.h:86
@ MultiProcessingModule
Definition: tfnamespace.h:143
#define T_CORE_EXPORT
Definition: tdeclexport.h:28
#define T_DISABLE_COPY(Class)
Definition: tdeclexport.h:37
#define T_DISABLE_MOVE(Class)
Definition: tdeclexport.h:41