cutelyst 3.9.1
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
engine.h
1/*
2 * SPDX-FileCopyrightText: (C) 2013-2022 Daniel Nicoletti <dantti12@gmail.com>
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5#ifndef CUTELYST_ENGINE_H
6#define CUTELYST_ENGINE_H
7
8#include <Cutelyst/Headers>
9#include <Cutelyst/cutelyst_global.h>
10
11#include <QHostAddress>
12#include <QObject>
13
14namespace Cutelyst {
15
16class Application;
17class Context;
18class EngineRequest;
19class EnginePrivate;
20class CUTELYST_LIBRARY Engine : public QObject
21{
23public:
29 explicit Engine(Application *app, int workerCore, const QVariantMap &opts);
30 virtual ~Engine();
31
35 Application *app() const;
36
41 virtual int workerId() const = 0;
42
46 int workerCore() const;
47
55 inline bool isZeroWorker() const;
56
60 QVariantMap opts() const;
61
67 QVariantMap config(const QString &entity) const;
68
72 void setConfig(const QVariantMap &config);
73
77 static QVariantMap loadIniConfig(const QString &filename);
78
82 static QVariantMap loadJsonConfig(const QString &filename);
83
89 virtual quint64 time();
90
98 void processRequest(EngineRequest *request);
99
103 static inline QString camelCaseHeader(const QString &headerKey)
104 {
105 // The RFC 2616 and 7230 states keys are not case
106 // case sensitive, however several tools fail
107 // if the headers are not on camel case form.
108 QString key = headerKey;
109 bool lastWasLetter = false;
110 for (int i = 0; i < key.size(); ++i) {
111 QChar c = key[i];
112 if (c == u'_') {
113 key[i] = u'-';
114 lastWasLetter = false;
115 } else if (lastWasLetter) {
116 key[i] = c.toLower();
117 } else if (c.isLetter()) {
118 lastWasLetter = true;
119 }
120 }
121 return key;
122 }
123
127 static inline void camelCaseByteArrayHeader(QByteArray &key)
128 {
129 // The RFC 2616 and 7230 states keys are not case
130 // case sensitive, however several tools fail
131 // if the headers are not on camel case form.
132 bool lastWasLetter = false;
133 for (int i = 0; i < key.size(); ++i) {
134 char c = key[i];
135 if (c == '_') {
136 key[i] = '-';
137 lastWasLetter = false;
138 } else if (lastWasLetter) {
139 key[i] = QChar::toLower(c);
140 } else if (QChar::isLetter(c)) {
141 lastWasLetter = true;
142 }
143 }
144 }
145
149 Q_DECL_DEPRECATED_X("Will be removed in new major release")
150 static const char *httpStatusMessage(quint16 status, int *len = nullptr);
151
152Q_SIGNALS:
161
162protected:
172 bool initApplication();
173
186 bool postForkApplication();
187
192
193 EnginePrivate *d_ptr;
194
195private:
196 Q_DECLARE_PRIVATE(Engine)
197 friend class Application;
198 friend class Response;
199
204 virtual bool init() = 0;
205};
206
207inline bool Engine::isZeroWorker() const
208{
209 return !workerId() && !workerCore();
210}
211
212} // namespace Cutelyst
213
214#endif // CUTELYST_ENGINE_H
The Cutelyst Application.
Definition application.h:43
The Cutelyst Context.
Definition context.h:39
static QString camelCaseHeader(const QString &headerKey)
Definition engine.h:103
static QVariantMap loadJsonConfig(const QString &filename)
Definition engine.cpp:326
Engine(Application *app, int workerCore, const QVariantMap &opts)
Definition engine.cpp:41
static void camelCaseByteArrayHeader(QByteArray &key)
Definition engine.h:127
bool initApplication()
initApplication
Definition engine.cpp:95
int workerCore() const
Each worker process migth have a number of worker cores (threads), a single process with two worker t...
Definition engine.cpp:89
virtual int workerId() const =0
The id is the number of the spawned engine process, a single process workerId = 0,...
bool postForkApplication()
postForkApplication
Definition engine.cpp:112
bool isZeroWorker() const
Definition engine.h:207
void setConfig(const QVariantMap &config)
Definition engine.cpp:296
void processRequestAsync(Cutelyst::EngineRequest *request)
void processRequest(EngineRequest *request)
Definition engine.cpp:278
QVariantMap opts() const
Definition engine.cpp:284
QVariantMap config(const QString &entity) const
user configuration for the application
Definition engine.cpp:290
Application * app() const
application
Definition engine.cpp:63
virtual quint64 time()
Definition engine.cpp:126
Headers & defaultHeaders()
Definition engine.cpp:272
static QVariantMap loadIniConfig(const QString &filename)
Definition engine.cpp:302
The Cutelyst namespace holds all public Cutelyst API.
Definition Mainpage.dox:8
int size() const const
bool isLetter() const const
QChar toLower() const const
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
int size() const const