Loading...
Searching...
No Matches
handler_factory.h
1/*
2* Nebula Atom
3
4* This program is free software: you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation, either version 3 of the License, or
7* (at your option) any later version.
8*
9* This program 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
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef NAF_COREANDLER_FACTORY
19#define NAF_COREANDLER_FACTORY
20
21
22#include <map>
23#include <exception>
24#include <vector>
25#include <memory>
26#include <stdexcept>
27
28#include "Poco/Exception.h"
29#include "Poco/Format.h"
30#include <Poco/Net/HTTPRequestHandlerFactory.h>
31#include <Poco/JSON/JSON.h>
32#include <Poco/JSON/Array.h>
33#include <Poco/JSON/Object.h>
34#include <Poco/JSON/Parser.h>
35#include <Poco/Dynamic/Var.h>
36#include <Poco/Dynamic/Struct.h>
37#include <Poco/StreamCopier.h>
38#include "Poco/Data/Session.h"
39#include "Poco/Data/MySQL/Connector.h"
40#include <Poco/Data/MySQL/MySQLException.h>
41#include <Poco/Data/Statement.h>
42
43#include "tools/handler_connection.h"
44#include "tools/sessions_manager.h"
45#include "query/database_manager.h"
46#include "tools/route.h"
47#include "http/request.h"
48#include "handlers/root_handler.h"
49#include "handlers/null_handler.h"
50#include "handlers/backend_handler.h"
51#include "handlers/login_handler.h"
52#include "handlers/websocket_handler.h"
53#include "tools/output_logger.h"
54
55using namespace Poco;
56using namespace Poco::Net;
57using namespace Poco::JSON;
58using namespace Poco::Data::Keywords;
59
60namespace NAF
61{
62 namespace Core
63 {
64 struct HTTPRequestInfo;
65 class HandlerFactory;
66 }
67}
68
69
71{
72 HTTPRequestInfo(std::string uri, std::string method) : uri(uri), method(method){}
73
74 std::string uri;
75 std::string method;
76};
77
79 public HTTPRequestHandlerFactory
80{
81 public:
82 using FunctionHandler = std::function<NAF::Handlers::RootHandler*()>;
83 using FunctionHandlerCreator = std::function<NAF::Handlers::RootHandler*(Core::HTTPRequestInfo& info)>;
84 using Connections = std::map<std::string, Tools::HandlerConnection>;
85
87 virtual ~HandlerFactory();
88
89 Connections& get_connections()
90 {
91 auto& var = connections_;
92 return var;
93 }
94 FunctionHandlerCreator& get_handler_creator_()
95 {
96 auto& var = handler_creator_;
97 return var;
98 }
99 void set_handler_creator(FunctionHandlerCreator handler_creator){ handler_creator_ = handler_creator; }
100
101 virtual HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request);
102
103 protected:
104 void ErrorResponse_(const HTTPServerRequest& request, std::string error);
105
106 private:
107 FunctionHandlerCreator handler_creator_;
108 Connections connections_;
109};
110
111#endif // NAF_COREANDLER_FACTORY
Definition handler_factory.h:80
Definition root_handler.h:98
Definition handler_factory.h:71