Cutelyst  3.5.0
controller.h
1 /*
2  * SPDX-FileCopyrightText: (C) 2013-2022 Daniel Nicoletti <dantti12@gmail.com>
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 #ifndef CUTELYST_CONTROLLER_H
6 #define CUTELYST_CONTROLLER_H
7 
8 #include <QObject>
9 
10 #include <Cutelyst/cutelyst_global.h>
11 #include <Cutelyst/action.h>
12 #include <Cutelyst/context.h>
13 #include <Cutelyst/request.h>
14 #include <Cutelyst/response.h>
15 
16 #define STR(X) #X
17 #define C_PATH(X, Y) Q_CLASSINFO(STR(X ## _Path), STR(Y))
18 #define C_NAMESPACE(value) Q_CLASSINFO("Namespace", value)
19 #define C_ATTR(X, Y) Q_CLASSINFO(STR(X), STR(Y)) Q_INVOKABLE
20 
21 # define CActionFor(str) \
22  ([this]() -> Cutelyst::Action * { \
23  static thread_local Cutelyst::Action *action = \
24  Cutelyst::Controller::actionFor(str); \
25  return action; \
26  }()) \
27 
28 
29 namespace Cutelyst {
30 
31 class ControllerPrivate;
89 class CUTELYST_LIBRARY Controller : public QObject
90 {
91  Q_OBJECT
92 public:
96  explicit Controller(QObject *parent = nullptr);
97  virtual ~Controller();
98 
108  QString ns() const;
109 
116  Action *actionFor(const QString &name) const;
117 
124  Action *actionFor(QStringView name) const;
125 
130  ActionList actions() const;
131 
135  bool operator==(const char *className);
136 
137 protected:
146  virtual bool preFork(Application *app);
147 
156  virtual bool postFork(Application *app);
157 
163  bool _DISPATCH(Context *c);
164 
165  ControllerPrivate *d_ptr;
166 
167 private:
168  Q_DECLARE_PRIVATE(Controller)
169  friend class Application;
170  friend class Dispatcher;
171 };
172 
173 }
174 
175 #endif // CUTELYST_CONTROLLER_H
This class represents a Cutelyst Action.
Definition: action.h:34
The Cutelyst Context.
Definition: context.h:38
Cutelyst Controller base class
Definition: controller.h:89
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7
The Cutelyst Application.
Definition: application.h:42
The Cutelyst Dispatcher.
Definition: dispatcher.h:27