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/frontend_handler.h"
52 #include "handlers/login_handler.h"
53 #include "handlers/websocket_handler.h"
54 #include "tools/output_logger.h"
55 
56 using namespace Poco;
57 using namespace Poco::Net;
58 using namespace Poco::JSON;
59 using namespace Poco::Data::Keywords;
60 
61 namespace NAF
62 {
63  namespace Core
64  {
65  struct HTTPRequestInfo;
66  class HandlerFactory;
67  }
68 }
69 
70 
72 {
73  HTTPRequestInfo(std::string uri, std::string method) : uri(uri), method(method){}
74 
75  std::string uri;
76  std::string method;
77 };
78 
80  public HTTPRequestHandlerFactory
81 {
82  public:
83  using FunctionHandler = std::function<NAF::Handlers::RootHandler*()>;
84  using FunctionHandlerCreator = std::function<NAF::Handlers::RootHandler*(Core::HTTPRequestInfo& info)>;
85  using Connections = std::map<std::string, Tools::HandlerConnection>;
86 
88  virtual ~HandlerFactory();
89 
90  Connections& get_connections()
91  {
92  auto& var = connections_;
93  return var;
94  }
95  FunctionHandlerCreator& get_handler_creator_()
96  {
97  auto& var = handler_creator_;
98  return var;
99  }
100  void set_handler_creator(FunctionHandlerCreator handler_creator){ handler_creator_ = handler_creator; }
101 
102  virtual HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request);
103 
104  protected:
105  void ErrorResponse_(const HTTPServerRequest& request, std::string error);
106 
107  private:
108  FunctionHandlerCreator handler_creator_;
109  Connections connections_;
110 };
111 
112 #endif // NAF_COREANDLER_FACTORY
Definition: handler_factory.h:81
Definition: root_handler.h:97
Definition: handler_factory.h:72