Cutelyst  1.5.0
dispatcher.h
1 /*
2  * Copyright (C) 2013-2016 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:
45  Dispatcher(QObject *parent = nullptr);
46  ~Dispatcher();
47 
51  Action *getAction(const QString &name, const QString &nameSpace = QString()) const;
52 
56  Action* getActionByPath(const QString &path) const;
57 
62  ActionList getActions(const QString &name, const QString &nameSpace) const;
63 
67  QMap<QString, Controller *> controllers() const;
68 
77  QString uriForAction(Action *action, const QStringList &captures) const;
78 
83  Action *expandAction(Context *c, Action *action) const;
84 
89  QVector<DispatchType *> dispatchers() const;
90 
91 protected:
95  void setupActions(const QVector<Controller *> &controllers, const QVector<DispatchType *> &dispatchers, bool printActions);
96 
101  bool dispatch(Context *c);
102 
106  bool forward(Context *c, Component *component);
107 
111  bool forward(Context *c, const QString &opname);
112 
116  void prepareAction(Context *c);
117 
118 protected:
119  friend class Application;
120  friend class Context;
121  friend class Controller;
122  DispatcherPrivate *d_ptr;
123 
124 private:
125  Q_DECLARE_PRIVATE(Dispatcher)
126 };
127 
128 }
129 
130 #endif // CUTELYST_DISPATCHER_H
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:55
The Cutelyst Dispatcher.
Definition: dispatcher.h:41