Cutelyst  1.8.0
dispatcher.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 #ifndef CUTELYST_DISPATCHER_H
20 #define CUTELYST_DISPATCHER_H
21 
22 #include <QtCore/qobject.h>
23 #include <QtCore/qhash.h>
24 #include <QtCore/qstringlist.h>
25 
26 #include <Cutelyst/action.h>
27 #include <Cutelyst/cutelyst_global.h>
28 
29 namespace Cutelyst {
30 
31 class Context;
32 class Controller;
33 class DispatchType;
34 class DispatcherPrivate;
35 
41 class CUTELYST_LIBRARY Dispatcher : public QObject
42 {
43  Q_OBJECT
44 public:
48  Dispatcher(QObject *parent = nullptr);
49  ~Dispatcher();
50 
54  Action *getAction(const QString &name, const QString &nameSpace = QString()) const;
55 
59  Action* getActionByPath(const QString &path) const;
60 
65  ActionList getActions(const QString &name, const QString &nameSpace) const;
66 
70  QMap<QString, Controller *> controllers() const;
71 
80  QString uriForAction(Action *action, const QStringList &captures) const;
81 
86  Action *expandAction(Context *c, Action *action) const;
87 
92  QVector<DispatchType *> dispatchers() const;
93 
94 protected:
98  void setupActions(const QVector<Controller *> &controllers, const QVector<DispatchType *> &dispatchers, bool printActions);
99 
104  bool dispatch(Context *c);
105 
109  bool forward(Context *c, Component *component);
110 
114  bool forward(Context *c, const QString &opname);
115 
119  void prepareAction(Context *c);
120 
121 protected:
122  friend class Application;
123  friend class Context;
124  friend class Controller;
125  DispatcherPrivate *d_ptr;
126 
127 private:
128  Q_DECLARE_PRIVATE(Dispatcher)
129 };
130 
131 }
132 
133 #endif // CUTELYST_DISPATCHER_H
QVector< Action * > ActionList
Definition: action.h:164
The Cutelyst Component base class.
Definition: component.h:40
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