cutelyst  4.4.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-2023 Daniel Nicoletti <dantti12@gmail.com>
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 #pragma once
6 
7 #include <Cutelyst/Headers>
8 #include <Cutelyst/cutelyst_export.h>
9 
10 #include <QHostAddress>
11 #include <QObject>
12 
13 namespace Cutelyst {
14 
15 class Application;
16 class Context;
17 class EngineRequest;
18 class EnginePrivate;
19 class CUTELYST_EXPORT Engine : public QObject
20 {
21  Q_OBJECT
22 public:
28  explicit Engine(Application *app, int workerCore, const QVariantMap &opts);
32  virtual ~Engine();
33 
37  [[nodiscard]] Application *app() const;
38 
48  [[nodiscard]] virtual int workerId() const = 0;
49 
57  [[nodiscard]] int workerCore() const;
58 
66  [[nodiscard]] inline bool isZeroWorker() const;
67 
71  [[nodiscard]] QVariantMap opts() const;
72 
79  [[nodiscard]] QVariantMap config(const QString &entity) const;
80 
84  void setConfig(const QVariantMap &config);
85 
89  [[nodiscard]] static QVariantMap loadIniConfig(const QString &filename);
90 
94  [[nodiscard]] static QVariantMap loadJsonConfig(const QString &filename);
95 
101  void processRequest(EngineRequest *request);
102 
107  Q_DECL_DEPRECATED_X("Will be removed in new major release")
108  static const char *httpStatusMessage(quint16 status, int *len = nullptr);
109 
110 Q_SIGNALS:
118  void processRequestAsync(Cutelyst::EngineRequest *request);
119 
120 protected:
125  bool initApplication();
126 
137  bool postForkApplication();
138 
142  [[nodiscard]] Headers &defaultHeaders();
143 
144  EnginePrivate *d_ptr;
145 
146 private:
147  Q_DECLARE_PRIVATE(Engine)
148  friend class Application;
149  friend class Response;
150 
154  virtual bool init() = 0;
155 };
156 
157 inline bool Engine::isZeroWorker() const
158 {
159  return !workerId() && !workerCore();
160 }
161 
162 } // namespace Cutelyst
The Cutelyst application.
Definition: application.h:66
The Cutelyst Engine.
Definition: engine.h:20
virtual int workerId() const =0
Container for HTTP headers.
Definition: headers.h:24
A Cutelyst response.
Definition: response.h:29
The Cutelyst namespace holds all public Cutelyst API.