tufao  1.3.0
An asynchronous web framework for C++ built on top of Qt
classhandlermanager.h
1 /*
2  Copyright (c) 2013 Timothy Reaves treaves@silverfieldstech.com
3 
4  Permission is hereby granted, free of charge, to any person obtaining a copy
5  of this software and associated documentation files (the "Software"), to deal
6  in the Software without restriction, including without limitation the rights
7  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  copies of the Software, and to permit persons to whom the Software is
9  furnished to do so, subject to the following conditions:
10 
11  The above copyright notice and this permission notice shall be included in all
12  copies or substantial portions of the Software.
13 
14  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  SOFTWARE.
21  */
22 
23 #ifndef TUFAO_CLASSHANDLERMANAGER_H
24 #define TUFAO_CLASSHANDLERMANAGER_H
25 
26 #include <QtCore/QObject>
27 #include <QtCore/QList>
28 #include <QtCore/QHash>
29 #include <QtCore/QMap>
30 #include <QtCore/QMultiHash>
31 #include <QtCore/QStringList>
32 
33 #include "abstracthttpserverrequesthandler.h"
34 
35 namespace Tufao {
36 
37 class ClassHandler;
38 
72 {
73  Q_OBJECT
74  Q_PROPERTY(QString urlNamespace READ urlNamespace)
75 public:
86  explicit ClassHandlerManager(const QString &pluginID = QString{},
87  const QString &urlNamespace = QString{},
88  QObject * parent = 0);
89 
93  virtual ~ClassHandlerManager();
94 
95  QString urlNamespace() const;
96 
106  static void addPluginLocation(const QString location);
107 
108 public slots:
109  bool handleRequest(HttpServerRequest & request, HttpServerResponse & response) override;
110 
111 private:
112  struct PluginDescriptor
113  {
114  PluginDescriptor(){;}
116  ClassHandler * handler;
118  QString className;
120  QHash<uint, int> methods;
122  QList<QString> methodNames;
123  };
124 
131  void registerHandler(ClassHandler * handler);
132 
133  bool processRequest(HttpServerRequest & request,
134  HttpServerResponse & response,
135  const QString className,
136  const QString methodName,
137  const QHash<QString, QString> arguments);
138 
139  void dispatchVoidMethod(QMetaMethod method, ClassHandler * handler, const QGenericArgument * args) const;
140  void dispatchJSONMethod(HttpServerResponse & response,
141  QMetaMethod method,
142  ClassHandler * handler,
143  const QGenericArgument * args) const;
144 
145  int selectMethod(const QString className, const QString methodName, const QHash<QString, QString> arguments) const;
146 
148  static QStringList pluginLocations;
149 
150  struct Priv;
151  Priv *priv;
152 };
153 
154 } // namespace Tufao
155 
156 #endif // TUFAO_CLASSHANDLERMANAGER_H
This class provides an interface for HttpServerRequest handlers.
Definition: abstracthttpserverrequesthandler.h:50
The Tufao::HttpServerResponse is used to respond to a Tufao::HttpServerRequest.
Definition: httpserverresponse.h:142
The Tufao::HttpServer represents a HTTP request received by Tufao::HttpServer.
Definition: httpserverrequest.h:54
virtual ~ClassHandlerManager()
Destroys the object.
This class serves as the HttpServerRequestHandler for all ClassHandler plugins.
Definition: classhandlermanager.h:71
static void addPluginLocation(const QString location)
Adds a non-standard path to the search paths.
The ClassHandler class Define the interface to implement when creating a plugin.
Definition: classhandler.h:168
This is the namespace where all Tufão facilities are grouped.
Definition: abstracthttpserverrequesthandler.h:30
ClassHandlerManager(const QString &pluginID=QString{}, const QString &urlNamespace=QString{}, QObject *parent=0)
Constructs a ClassHandlerManager object.