Cutelyst  1.6.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:
111  explicit Controller(QObject *parent = nullptr);
112  virtual ~Controller();
113 
123  QString ns() const;
124 
131  Action *actionFor(const QString &name) const;
132 
137  ActionList actions() const;
138 
142  bool operator==(const char *className);
143 
144 protected:
153  virtual bool preFork(Application *app);
154 
163  virtual bool postFork(Application *app);
164 
170  bool _DISPATCH(Context *c);
171 
172  ControllerPrivate *d_ptr;
173 
174 private:
175  Q_DECLARE_PRIVATE(Controller)
176  friend class Application;
177  friend class Dispatcher;
178 };
179 
180 }
181 
182 #endif // CUTELYST_CONTROLLER_H
QVector< Action * > ActionList
Definition: action.h:164
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:56
The Cutelyst Dispatcher.
Definition: dispatcher.h:41