cutelyst  5.0.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-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 
103 Q_SIGNALS:
111  void processRequestAsync(Cutelyst::EngineRequest *request);
112 
113 protected:
118  bool initApplication();
119 
130  bool postForkApplication();
131 
135  [[nodiscard]] Headers &defaultHeaders();
136 
137  EnginePrivate *d_ptr;
138 
139 private:
140  Q_DECLARE_PRIVATE(Engine)
141  friend class Application;
142  friend class Response;
143 
147  virtual bool init() = 0;
148 };
149 
150 inline bool Engine::isZeroWorker() const
151 {
152  return !workerId() && !workerCore();
153 }
154 
155 } // namespace Cutelyst
Container for HTTP headers.
Definition: headers.h:23
A Cutelyst response.
Definition: response.h:28
The Cutelyst namespace holds all public Cutelyst API.
The Cutelyst application.
Definition: application.h:72
virtual int workerId() const =0
The Cutelyst Engine.
Definition: engine.h:19
int workerCore() const
Definition: engine.cpp:67
bool isZeroWorker() const
Definition: engine.h:150