NAWA  0.8
Web Application Framework for C++
RequestHandler.h
Go to the documentation of this file.
1 
6 /*
7  * Copyright (C) 2019-2021 Tobias Flaig.
8  *
9  * This file is part of nawa.
10  *
11  * nawa is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License,
13  * version 3, as published by the Free Software Foundation.
14  *
15  * nawa is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with nawa. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef NAWA_REQUESTHANDLER_H
25 #define NAWA_REQUESTHANDLER_H
26 
27 #include <memory>
29 #include <nawa/config/Config.h>
31 #include <nawa/internal/fwdecl.h>
32 #include <nawa/internal/macros.h>
33 #include <optional>
34 
35 namespace nawa {
38 
39  protected:
41 
42  public:
47  virtual ~RequestHandler();
48 
59  static std::unique_ptr<RequestHandler>
60  newRequestHandler(std::shared_ptr<HandleRequestFunctionWrapper> const& handleRequestFunction, Config config,
61  int concurrency);
62 
73  static std::unique_ptr<RequestHandler>
74  newRequestHandler(HandleRequestFunction handleRequestFunction, Config config, int concurrency);
75 
81  void setAppRequestHandler(std::shared_ptr<HandleRequestFunctionWrapper> handleRequestFunction) noexcept;
82 
87  void setAccessFilters(AccessFilterList accessFilters) noexcept;
88 
93  [[nodiscard]] std::shared_ptr<Config const> getConfig() const noexcept;
94 
100  void setConfig(Config config) noexcept;
101 
108  void reconfigure(std::optional<std::shared_ptr<HandleRequestFunctionWrapper>> handleRequestFunction,
109  std::optional<AccessFilterList> accessFilters, std::optional<Config> config) noexcept;
110 
117  void reconfigure(HandleRequestFunction handleRequestFunction, std::optional<AccessFilterList> accessFilters,
118  std::optional<Config> config) noexcept;
119 
129  virtual void start() = 0;
130 
135  virtual void stop() noexcept = 0;
136 
143  virtual void terminate() noexcept = 0;
144 
150  virtual void restart() noexcept {}
151 
157  virtual void join() noexcept = 0;
158 
164  void handleRequest(Connection& connection);
165  };
166 }// namespace nawa
167 
168 #endif//NAWA_REQUESTHANDLER_H
Options to check the path and invoke certain actions before forwarding the request to the app.
Reader for config files and accessor to config values.
Function wrapper for handleRequest functions of nawa apps.
std::shared_ptr< Config const > getConfig() const noexcept
virtual void stop() noexcept=0
virtual void start()=0
virtual void restart() noexcept
void handleRequest(Connection &connection)
void setConfig(Config config) noexcept
virtual void join() noexcept=0
void setAccessFilters(AccessFilterList accessFilters) noexcept
static std::unique_ptr< RequestHandler > newRequestHandler(std::shared_ptr< HandleRequestFunctionWrapper > const &handleRequestFunction, Config config, int concurrency)
void reconfigure(std::optional< std::shared_ptr< HandleRequestFunctionWrapper >> handleRequestFunction, std::optional< AccessFilterList > accessFilters, std::optional< Config > config) noexcept
virtual void terminate() noexcept=0
void setAppRequestHandler(std::shared_ptr< HandleRequestFunctionWrapper > handleRequestFunction) noexcept
Forward declarations.
Macros for frequently used patterns.
#define NAWA_DEFAULT_CONSTRUCTOR_DEF(Class)
Definition: macros.h:39
#define NAWA_PRIVATE_DATA()
Definition: macros.h:30
Definition: AppInit.h:31
std::function< int(nawa::Connection &)> HandleRequestFunction