TreeFrogFramework 2.10
Loading...
Searching...
No Matches
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
14class QTextCodec;
15
16
18#ifdef TF_USE_GUI_MODULE
19 : public QApplication
20#else
21 : public QCoreApplication
22#endif
23{
24 Q_OBJECT
25public:
27 Invalid = 0,
28 Thread = 1,
29 Epoll = 2,
30 };
31
32 TWebApplication(int &argc, char **argv);
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 QStringConverter::Encoding encodingForInternal() const { return _encodingInternal; }
69 QStringConverter::Encoding encodingForHttpOutput() const { return _encodingHttp; }
70 int applicationServerId() const { return _appServerId; }
71 QThread *databaseContextMainThread() const;
72 TDatabaseContext *mainDatabaseContext() const;
73 const QVariantMap &getConfig(const QString &configName);
74 QVariant getConfigValue(const QString &configName, const QString &key, const QVariant &defaultValue = QVariant());
75 void initializeCache();
76 void cleanupCache();
77
78#if defined(Q_OS_UNIX)
79 void watchUnixSignal(int sig, bool watch = true);
80 void ignoreUnixSignal(int sig, bool ignore = true);
81#endif
82
83#if defined(Q_OS_WIN)
84 void watchConsoleSignal();
85 void ignoreConsoleSignal();
86 void watchLocalSocket();
87 static bool sendLocalCtrlMessage(const QByteArray &msg, int targetProcess);
88
89private slots:
90 void recvLocalSocket();
91#endif // Q_OS_WIN
92
93protected:
94 void timerEvent(QTimerEvent *event);
95 static int signalNumber();
96
97private:
98 QString _webRootAbsolutePath;
99 QString _dbEnvironment;
100 QVector<QVariantMap> _sqlSettings;
101 QVector<QVariantMap> _kvsSettings {(int)Tf::KvsEngine::Num};
102 QVariantMap _loggerSetting;
103 QVariantMap _validationSetting;
104 QVariantMap _mediaTypes;
105 QStringConverter::Encoding _encodingInternal {QStringConverter::Utf8};
106 QStringConverter::Encoding _encodingHttp {QStringConverter::Utf8};
107
108 int _appServerId {-1};
109 QBasicTimer _timer;
110 QMap<QString, QVariantMap> _configMap;
111 int _cacheSqlDbIndex {-1};
113
114 static void resetSignalNumber();
115
118};
119
120
125inline void TWebApplication::setDatabaseEnvironment(const QString &environment)
126{
127 _dbEnvironment = environment;
128}
129
130
131#if defined(Q_OS_WIN)
132#include <QAbstractNativeEventFilter>
133
134class T_CORE_EXPORT TNativeEventFilter : public QAbstractNativeEventFilter {
135public:
136 virtual bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *);
137};
138
139#endif // Q_OS_WIN
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:68
void setMultiProcessingModule(MultiProcessingModule mpm)
Definition twebapplication.h:61
MultiProcessingModule
Definition twebapplication.h:26
int applicationServerId() const
Definition twebapplication.h:70
QStringConverter::Encoding encodingForHttpOutput() const
Definition twebapplication.h:69
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:125
@ Invalid
Definition tfnamespace.h:22
KvsEngine
Definition tfnamespace.h:239
@ 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