Cutelyst  1.5.0
controller.h
1 /*
2  * Copyright (C) 2013-2017 Daniel Nicoletti <dantti12@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifndef CUTELYST_CONTROLLER_H
21 #define CUTELYST_CONTROLLER_H
22 
23 #include <QObject>
24 
25 #include <Cutelyst/cutelyst_global.h>
26 #include <Cutelyst/action.h>
27 #include <Cutelyst/context.h>
28 #include <Cutelyst/request.h>
29 #include <Cutelyst/response.h>
30 
31 #define STR(X) #X
32 #define C_PATH(X, Y) Q_CLASSINFO(STR(X ## _Path), STR(Y))
33 #define C_NAMESPACE(value) Q_CLASSINFO("Namespace", value)
34 #define C_ATTR(X, Y) Q_CLASSINFO(STR(X), STR(Y)) Q_INVOKABLE
35 
36 # define CActionFor(str) \
37  ([this]() -> Cutelyst::Action * { \
38  static thread_local Cutelyst::Action *action = \
39  Cutelyst::Controller::actionFor(str); \
40  return action; \
41  }()) \
42 
43 
44 namespace Cutelyst {
45 
46 class ControllerPrivate;
104 class CUTELYST_LIBRARY Controller : public QObject
105 {
106  Q_OBJECT
107 public:
108  explicit Controller(QObject *parent = nullptr);
109  virtual ~Controller();
110 
120  QString ns() const;
121 
128  Action *actionFor(const QString &name) const;
129 
134  ActionList actions() const;
135 
139  bool operator==(const char *className);
140 
141 protected:
150  virtual bool preFork(Application *app);
151 
160  virtual bool postFork(Application *app);
161 
167  bool _DISPATCH(Context *c);
168 
169  ControllerPrivate *d_ptr;
170 
171 private:
172  Q_DECLARE_PRIVATE(Controller)
173  friend class Application;
174  friend class Dispatcher;
175 };
176 
177 }
178 
179 #endif // CUTELYST_CONTROLLER_H
This class represents a Cutelyst Action.
Definition: action.h:49
The Cutelyst Context.
Definition: context.h:52
Cutelyst Controller base class
Definition: controller.h:104
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7
The Cutelyst Application.
Definition: application.h:55
The Cutelyst Dispatcher.
Definition: dispatcher.h:41