Cutelyst  2.5.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 Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 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  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 #ifndef CUTELYST_DISPATCHER_H
19 #define CUTELYST_DISPATCHER_H
20 
21 #include <QtCore/qobject.h>
22 #include <QtCore/qhash.h>
23 #include <QtCore/qstringlist.h>
24 
25 #include <Cutelyst/action.h>
26 #include <Cutelyst/cutelyst_global.h>
27 
28 namespace Cutelyst {
29 
30 class Context;
31 class Controller;
32 class DispatchType;
33 class DispatcherPrivate;
34 
40 class CUTELYST_LIBRARY Dispatcher : public QObject
41 {
42  Q_OBJECT
43 public:
47  Dispatcher(QObject *parent = nullptr);
48  ~Dispatcher();
49 
53  Action *getAction(const QString &name, const QString &nameSpace = QString()) const;
54 
58  Action* getActionByPath(const QString &path) const;
59 
64  ActionList getActions(const QString &name, const QString &nameSpace) const;
65 
69  QMap<QString, Controller *> controllers() const;
70 
79  QString uriForAction(Action *action, const QStringList &captures) const;
80 
85  Action *expandAction(const Context *c, Action *action) const;
86 
91  QVector<DispatchType *> dispatchers() const;
92 
93 protected:
97  void setupActions(const QVector<Controller *> &controllers, const QVector<DispatchType *> &dispatchers, bool printActions);
98 
103  bool dispatch(Context *c);
104 
108  bool forward(Context *c, Component *component);
109 
113  bool forward(Context *c, const QString &opname);
114 
118  void prepareAction(Context *c);
119 
120 protected:
121  friend class Application;
122  friend class Context;
123  friend class Controller;
124  DispatcherPrivate *d_ptr;
125 
126 private:
127  Q_DECLARE_PRIVATE(Dispatcher)
128 };
129 
130 }
131 
132 #endif // CUTELYST_DISPATCHER_H
QVector< Action * > ActionList
Definition: action.h:162
The Cutelyst Component base class.
Definition: component.h:38
This class represents a Cutelyst Action.
Definition: action.h:47
The Cutelyst Context.
Definition: context.h:50
Cutelyst Controller base class
Definition: controller.h:102
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:40