C++ Web Framework  3.0
cppwebserver.h
1 /*
2  Copyright 2017 Herik Lima de Castro and Marcelo Medeiros Eler
3  Distributed under MIT license, or public domain if desired and
4  recognized in your jurisdiction.
5  See file LICENSE for detail.
6 */
7 
8 #ifndef CPPWEBSERVER_H
9 #define CPPWEBSERVER_H
10 
11 #include <QTcpServer>
12 #include <QSslKey>
13 #include <QSslCertificate>
14 #include <QHttpMultiPart>
15 #include <QThreadPool>
16 #include <QTimer>
17 #include <atomic>
18 #include "qmapthreadsafety.h"
19 #include "httpreadrequest.h"
20 #include "controller.h"
21 #include "session.h"
22 #include "filter.h"
23 #include "controller.h"
24 #include "configuration.h"
25 #include "request.h"
26 #include "response.h"
27 #include "cppwebframework_global.h"
28 
29 CWF_BEGIN_NAMESPACE
33 class CPPWEBFRAMEWORKSHARED_EXPORT CppWebServer : public QTcpServer
34 {
35  Q_OBJECT
36 private:
37  Configuration configuration;
38  Filter *filter;
39  QTimer *timer;
40  QThreadPool pool;
43  QSslConfiguration *ssl = nullptr;
44  const int sleepTime = 10;
45  QAtomicInteger<qint8> block = 0;
46 public:
51  explicit CppWebServer(const Configuration &configuration, Filter *filter = nullptr);
55  virtual ~CppWebServer();
61  template<typename CONTROLLER>
62  void addController(const QString &url) noexcept
63  {
64  static_assert(std::is_base_of<Controller, CONTROLLER>::value, "CONTROLLER must be a descendant of Controller");
65  urlController.insert(url, new CONTROLLER);
66  }
67 protected:
72  void incomingConnection(qintptr socketfd) override;
76  void doClean();
77 };
78 
79 CWF_END_NAMESPACE
80 
81 #endif // CPPWEBSERVER_H
iterator insert(const Key &key, const T &value)
This method inserts a new key and value in the map.
Definition: qmapthreadsafety.h:166
void addController(const QString &url) noexcept
Hitches a url to a Controller.
Definition: cppwebserver.h:62
The QMapThreadSafety class is a thread safe QMap.
Definition: qmapthreadsafety.h:23
The CppWebServer class is a HTTP server, responsable to receive and dispatch the requisitions.
Definition: cppwebserver.h:33
The Filter class works like a filter. You can use this class to validate sessions or measuring runtim...
Definition: filter.h:23
All classes of C++ Web Framework are contained within the namespace CWF.
Definition: configuration.h:24