cutelyst 3.9.0
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{
22 Q_OBJECT
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 static const char *httpStatusMessage(quint16 status, int *len = nullptr);
150
151Q_SIGNALS:
160
161protected:
171 bool initApplication();
172
185 bool postForkApplication();
186
190 Headers &defaultHeaders();
191
192 EnginePrivate *d_ptr;
193
194private:
195 Q_DECLARE_PRIVATE(Engine)
196 friend class Application;
197 friend class Response;
198
203 virtual bool init() = 0;
204};
205
206inline bool Engine::isZeroWorker() const
207{
208 return !workerId() && !workerCore();
209}
210
211} // namespace Cutelyst
212
213#endif // CUTELYST_ENGINE_H
The Cutelyst Application.
Definition: application.h:43
The Cutelyst Engine.
Definition: engine.h:21
static QString camelCaseHeader(const QString &headerKey)
Definition: engine.h:103
static void camelCaseByteArrayHeader(QByteArray &key)
Definition: engine.h:127
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 isZeroWorker() const
Definition: engine.h:206
void processRequestAsync(Cutelyst::EngineRequest *request)
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:8
int size() const const
bool isLetter() const const
QChar toLower() const const
int size() const const