drogon
C++14/17-based HTTP application framework
Toggle main menu visibility
Loading...
Searching...
No Matches
HttpSimpleController.h
1
14
15
#pragma once
16
17
#include <
drogon/DrObject.h
>
18
#include <drogon/utils/HttpConstraint.h>
19
#include <
drogon/HttpAppFramework.h
>
20
#include <trantor/utils/Logger.h>
21
#include <iostream>
22
#include <string>
23
#include <vector>
24
#define PATH_LIST_BEGIN \
25
static void initPathRouting() \
26
{
27
#define PATH_ADD(path, ...) registerSelf__(path, {__VA_ARGS__})
28
#define PATH_LIST_END }
29
30
namespace
drogon
31
{
36
class
HttpSimpleControllerBase
:
public
virtual
DrObjectBase
37
{
38
public
:
46
virtual
void
asyncHandleHttpRequest
(
47
const
HttpRequestPtr &req,
48
std::function<
void
(
const
HttpResponsePtr &)> &&callback) = 0;
49
50
virtual
~HttpSimpleControllerBase
()
51
{
52
}
53
};
54
62
template
<
typename
T,
bool
AutoCreation = true>
63
class
HttpSimpleController :
public
DrObject<T>,
public
HttpSimpleControllerBase
64
{
65
public
:
66
static
const
bool
isAutoCreation = AutoCreation;
67
68
virtual
~HttpSimpleController()
69
{
70
}
71
72
protected
:
73
HttpSimpleController()
74
{
75
}
76
77
static
void
registerSelf__(
78
const
std::string &path,
79
const
std::vector<internal::HttpConstraint> &constraints)
80
{
81
LOG_TRACE <<
"register simple controller("
82
<< HttpSimpleController<T, AutoCreation>::classTypeName()
83
<<
") on path:"
<< path;
84
app
().
registerHttpSimpleController
(
85
path,
86
HttpSimpleController<T, AutoCreation>::classTypeName(),
87
constraints);
88
}
89
90
private
:
91
class
pathRegistrator
92
{
93
public
:
94
pathRegistrator()
95
{
96
if
(AutoCreation)
97
{
98
T::initPathRouting();
99
}
100
}
101
};
102
103
friend
pathRegistrator;
104
static
pathRegistrator registrator_;
105
106
virtual
void
*touch()
107
{
108
return
®istrator_;
109
}
110
};
111
112
template
<
typename
T,
bool
AutoCreation>
113
typename
HttpSimpleController<T, AutoCreation>::pathRegistrator
114
HttpSimpleController<T, AutoCreation>::registrator_;
115
116
}
// namespace drogon
DrObject.h
HttpAppFramework.h
drogon::DrObjectBase
The base class for all drogon reflection classes.
Definition
DrObject.h:34
drogon::HttpAppFramework::registerHttpSimpleController
virtual HttpAppFramework & registerHttpSimpleController(const std::string &pathName, const std::string &ctrlName, const std::vector< internal::HttpConstraint > &constraints={})=0
Register a HttpSimpleController object into the framework.
drogon::HttpSimpleControllerBase
The abstract base class for HTTP simple controllers.
Definition
HttpSimpleController.h:37
drogon::HttpSimpleControllerBase::asyncHandleHttpRequest
virtual void asyncHandleHttpRequest(const HttpRequestPtr &req, std::function< void(const HttpResponsePtr &)> &&callback)=0
The function is called when a HTTP request is routed to the controller.
drogon
Drogon Test is a minimal effort test framework developed because the major C++ test frameworks doesn'...
Definition
Attribute.h:23
drogon::app
HttpAppFramework & app()
A wrapper of the instance() method.
Definition
HttpAppFramework.h:1656
lib
inc
drogon
HttpSimpleController.h
Generated by
1.17.0