SNode.C
Loading...
Searching...
No Matches
Controller.h
Go to the documentation of this file.
1/*
2 * SNode.C - a slim toolkit for network communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef EXPRESS_DISPATCHER_CONTROLLER_H
21#define EXPRESS_DISPATCHER_CONTROLLER_H
22
23namespace web::http::server {
24 class Request;
25 class Response;
26} // namespace web::http::server
27
28namespace express {
29 class Request;
30 class Response;
31 class RootRoute;
32 class Route;
33} // namespace express
34
35#ifndef DOXYGEN_SHOULD_SKIP_THIS
36
37#include <memory>
38#include <string>
39
40#endif /* DOXYGEN_SHOULD_SKIP_THIS */
41
42namespace express {
43
44 class Controller {
45 public:
46 Controller(const std::shared_ptr<web::http::server::Request>& request,
47 const std::shared_ptr<web::http::server::Response>& response);
48 Controller(const Controller& controller);
49
50 Controller& operator=(const Controller& controller) noexcept;
51
52 void setRootRoute(RootRoute* rootRoute);
53 void setCurrentRoute(Route* currentRoute);
54
57
58 int getFlags() const;
59
60 void next(const std::string& how) const;
61 bool nextRouter();
62 bool dispatchNext(const std::string& parentMountPath);
63
64 bool laxRouting();
65
66 enum Flags { NONE = 0, NEXT = 1 << 0, NEXT_ROUTE = 1 << 1, NEXT_ROUTER = 1 << 2 };
67
68 private:
71
72 RootRoute* rootRoute = nullptr;
73
74 mutable Route* lastRoute = nullptr;
75 Route* currentRoute = nullptr;
76
77 unsigned long lastTick = 0;
78
79 mutable int flags = NONE;
80 };
81
82} // namespace express
83
84#endif // EXPRESS_DISPATCHER_CONTROLLER_H
#define DECLARE_ROUTER_REQUESTMETHOD(METHOD)
Definition Router.h:48
#define APPLICATION(req, res)
Definition Router.h:45
unsigned long lastTick
Definition Controller.h:77
void next(const std::string &how) const
const std::shared_ptr< Request > & getRequest()
RootRoute * rootRoute
Definition Controller.h:72
Controller(const std::shared_ptr< web::http::server::Request > &request, const std::shared_ptr< web::http::server::Response > &response)
std::shared_ptr< Response > response
Definition Controller.h:70
Controller(const Controller &controller)
void setCurrentRoute(Route *currentRoute)
void setRootRoute(RootRoute *rootRoute)
std::shared_ptr< Request > request
Definition Controller.h:69
bool dispatchNext(const std::string &parentMountPath)
int getFlags() const
Controller & operator=(const Controller &controller) noexcept
const std::shared_ptr< Response > & getResponse()
void operator()(const std::string &how="") const
Definition Next.cpp:34
Next(Controller &controller)
Definition Next.cpp:30
Controller controller
Definition Next.h:44
Route & head(const Router &router) const
Definition Router.cpp:70
Route & all(const Router &router) const
Definition Router.cpp:61
Route & options(const Router &router) const
Definition Router.cpp:67
Route & connect(const Router &router) const
Definition Router.cpp:66
Route & post(const Router &router) const
Definition Router.cpp:64
Route & del(const Router &router) const
Definition Router.cpp:65
Router(const Router &)=default
Route & use(const Router &router) const
Definition Router.cpp:60
Route & get(const Router &router) const
Definition Router.cpp:62
Route & trace(const Router &router) const
Definition Router.cpp:68
Route & patch(const Router &router) const
Definition Router.cpp:69
void laxRouting(bool strict=false)
Definition Router.cpp:56
Route & put(const Router &router) const
Definition Router.cpp:63
std::shared_ptr< RootRoute > rootRoute
Definition Router.h:95
WebAppT(const std::string &name, const Router &router)
Definition WebAppT.h:58
WebAppT(const std::string &name)
Definition WebAppT.h:54
static void free()
Definition WebApp.cpp:50
static void init(int argc, char *argv[])
Definition WebApp.cpp:34
static void stop()
Definition WebApp.cpp:42
static core::TickStatus tick(const utils::Timeval &timeOut=0)
Definition WebApp.cpp:46
static core::State state()
Definition WebApp.cpp:54
static int start(const utils::Timeval &timeOut={LONG_MAX, 0})
Definition WebApp.cpp:38
WebApp(const Router &router)
Definition WebApp.cpp:30
int main(int argc, char *argv[])
Definition Config.h:37