SNode.C
Loading...
Searching...
No Matches
express::Controller Class Reference

#include <Controller.h>

Collaboration diagram for express::Controller:

Public Types

enum  Flags { NONE = 0 , NEXT = 1 << 0 , NEXT_ROUTE = 1 << 1 , NEXT_ROUTER = 1 << 2 }
 

Public Member Functions

 Controller (const std::shared_ptr< web::http::server::Request > &request, const std::shared_ptr< web::http::server::Response > &response)
 
 Controller (const Controller &controller)
 
Controlleroperator= (const Controller &controller) noexcept
 
void setRootRoute (RootRoute *rootRoute)
 
void setCurrentRoute (Route *currentRoute)
 
const std::shared_ptr< Request > & getRequest ()
 
const std::shared_ptr< Response > & getResponse ()
 
int getFlags () const
 
void next (const std::string &how) const
 
bool nextRouterCalled ()
 
bool dispatchNext (const std::string &parentMountPath)
 
bool setStrictRouting (bool strictRouting)
 
bool getStrictRouting () const
 

Private Attributes

std::shared_ptr< Requestrequest
 
std::shared_ptr< Responseresponse
 
RootRouterootRoute = nullptr
 
RoutelastRoute = nullptr
 
RoutecurrentRoute = nullptr
 
bool strictRouting
 
unsigned long lastTick = 0
 
int flags = NONE
 

Detailed Description

Definition at line 66 of file Controller.h.

Member Enumeration Documentation

◆ Flags

Enumerator
NONE 
NEXT 
NEXT_ROUTE 
NEXT_ROUTER 

Definition at line 90 of file Controller.h.

Constructor & Destructor Documentation

◆ Controller() [1/2]

express::Controller::Controller ( const std::shared_ptr< web::http::server::Request > &  request,
const std::shared_ptr< web::http::server::Response > &  response 
)

Definition at line 55 of file Controller.cpp.

57 : request(std::make_shared<Request>(request))
58 , response(std::make_shared<Response>(response))
60 }
static unsigned long getTickCounter()
Definition EventLoop.cpp:85
unsigned long lastTick
Definition Controller.h:103
std::shared_ptr< Response > response
Definition Controller.h:94
std::shared_ptr< Request > request
Definition Controller.h:93

References core::EventLoop::getTickCounter(), lastTick, request, and response.

Referenced by express::WebAppT< ServerT >::WebAppT().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Controller() [2/2]

express::Controller::Controller ( const Controller controller)

Definition at line 62 of file Controller.cpp.

63 : request(controller.request)
64 , response(controller.response)
65 , rootRoute(controller.rootRoute)
66 , lastRoute(controller.lastRoute)
67 , currentRoute(controller.currentRoute)
68 , lastTick(controller.lastTick)
69 , flags(controller.flags) {
70 }
RootRoute * rootRoute
Definition Controller.h:96

References currentRoute, flags, lastRoute, lastTick, request, response, and rootRoute.

Referenced by express::Next::Next().

Here is the caller graph for this function:

Member Function Documentation

◆ dispatchNext()

bool express::Controller::dispatchNext ( const std::string &  parentMountPath)

Definition at line 132 of file Controller.cpp.

132 {
133 bool dispatched = false;
134
135 if (((flags & Controller::NEXT) != 0)) {
136 if (lastRoute == currentRoute) {
137 flags &= ~Controller::NEXT;
138 if ((flags & Controller::NEXT_ROUTE) != 0) {
139 flags &= ~Controller::NEXT_ROUTE;
140 } else if ((flags & Controller::NEXT_ROUTER) == 0) {
141 dispatched = currentRoute->dispatchNext(*this, parentMountPath);
142 }
143 } else { // ? Optimization: Dispatch only parent route matched path
144 dispatched = currentRoute->dispatchNext(*this, parentMountPath);
145 }
146 }
147
148 return dispatched;
149 }
bool dispatchNext(Controller &controller, const std::string &parentMountPath)
Definition Route.cpp:110

References currentRoute, express::Route::dispatchNext(), flags, lastRoute, NEXT, NEXT_ROUTE, and NEXT_ROUTER.

Referenced by express::Route::dispatch().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFlags()

int express::Controller::getFlags ( ) const

Definition at line 102 of file Controller.cpp.

102 {
103 return flags;
104 }

References flags.

Referenced by express::dispatcher::ApplicationDispatcher::dispatch(), and express::dispatcher::MiddlewareDispatcher::dispatch().

Here is the caller graph for this function:

◆ getRequest()

const std::shared_ptr< Request > & express::Controller::getRequest ( )

Definition at line 94 of file Controller.cpp.

94 {
95 return request;
96 }

References request.

Referenced by express::dispatcher::ApplicationDispatcher::dispatch(), express::dispatcher::MiddlewareDispatcher::dispatch(), and express::dispatcher::RouterDispatcher::dispatch().

Here is the caller graph for this function:

◆ getResponse()

const std::shared_ptr< Response > & express::Controller::getResponse ( )

Definition at line 98 of file Controller.cpp.

98 {
99 return response;
100 }

References response.

Referenced by express::RootRoute::dispatch(), express::dispatcher::ApplicationDispatcher::dispatch(), and express::dispatcher::MiddlewareDispatcher::dispatch().

Here is the caller graph for this function:

◆ getStrictRouting()

bool express::Controller::getStrictRouting ( ) const

Definition at line 159 of file Controller.cpp.

159 {
160 return strictRouting;
161 }

References strictRouting.

Referenced by express::Route::dispatch(), express::dispatcher::ApplicationDispatcher::dispatch(), express::dispatcher::MiddlewareDispatcher::dispatch(), and express::dispatcher::RouterDispatcher::dispatch().

Here is the caller graph for this function:

◆ next()

void express::Controller::next ( const std::string &  how) const

Definition at line 106 of file Controller.cpp.

106 {
107 flags = NEXT;
108
109 if (how == "route") {
110 flags |= NEXT_ROUTE;
111 } else if (how == "router") {
113 }
114
116
117 if (lastTick != core::EventLoop::getTickCounter()) { // If asynchronous next() start traversing of route-tree
118 rootRoute->dispatch(*const_cast<express::Controller*>(this));
119 }
120 }
void dispatch(Controller &&controller)

References currentRoute, express::RootRoute::dispatch(), flags, core::EventLoop::getTickCounter(), lastRoute, lastTick, NEXT, NEXT_ROUTE, NEXT_ROUTER, and rootRoute.

Referenced by express::Next::operator()().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nextRouterCalled()

bool express::Controller::nextRouterCalled ( )

Definition at line 122 of file Controller.cpp.

122 {
123 const bool breakDispatching = lastRoute == currentRoute && (flags & Controller::NEXT_ROUTER) != 0;
124
125 if (breakDispatching) {
126 flags &= ~Controller::NEXT_ROUTER;
127 }
128
129 return breakDispatching;
130 }

References currentRoute, flags, lastRoute, and NEXT_ROUTER.

Referenced by express::dispatcher::RouterDispatcher::dispatch().

Here is the caller graph for this function:

◆ operator=()

Controller & express::Controller::operator= ( const Controller controller)
noexcept

Definition at line 72 of file Controller.cpp.

72 {
73 if (this != &controller) {
74 request = controller.request;
75 response = controller.response;
76 rootRoute = controller.rootRoute;
77 lastRoute = controller.lastRoute;
78 currentRoute = controller.currentRoute;
79 lastTick = controller.lastTick;
80 flags = controller.flags;
81 }
82
83 return *this;
84 }

References currentRoute, flags, lastRoute, lastTick, request, response, and rootRoute.

Referenced by express::dispatcher::MiddlewareDispatcher::dispatch().

Here is the caller graph for this function:

◆ setCurrentRoute()

void express::Controller::setCurrentRoute ( Route currentRoute)

Definition at line 90 of file Controller.cpp.

90 {
92 }

References currentRoute.

Referenced by express::Route::dispatch().

Here is the caller graph for this function:

◆ setRootRoute()

void express::Controller::setRootRoute ( RootRoute rootRoute)

Definition at line 86 of file Controller.cpp.

86 {
87 this->rootRoute = rootRoute;
88 }

References rootRoute.

Referenced by express::RootRoute::dispatch().

Here is the caller graph for this function:

◆ setStrictRouting()

bool express::Controller::setStrictRouting ( bool  strictRouting)

Definition at line 151 of file Controller.cpp.

151 {
152 const bool oldStrictRouting = this->strictRouting;
153
155
156 return oldStrictRouting;
157 }

References strictRouting.

Referenced by express::RootRoute::dispatch(), express::Route::dispatch(), and express::dispatcher::RouterDispatcher::dispatch().

Here is the caller graph for this function:

Member Data Documentation

◆ currentRoute

Route* express::Controller::currentRoute = nullptr
private

◆ flags

int express::Controller::flags = NONE
mutableprivate

Definition at line 105 of file Controller.h.

Referenced by Controller(), dispatchNext(), getFlags(), next(), nextRouterCalled(), and operator=().

◆ lastRoute

Route* express::Controller::lastRoute = nullptr
mutableprivate

Definition at line 98 of file Controller.h.

Referenced by Controller(), dispatchNext(), next(), nextRouterCalled(), and operator=().

◆ lastTick

unsigned long express::Controller::lastTick = 0
private

Definition at line 103 of file Controller.h.

Referenced by Controller(), Controller(), next(), and operator=().

◆ request

std::shared_ptr<Request> express::Controller::request
private

Definition at line 93 of file Controller.h.

Referenced by Controller(), Controller(), getRequest(), and operator=().

◆ response

std::shared_ptr<Response> express::Controller::response
private

Definition at line 94 of file Controller.h.

Referenced by Controller(), Controller(), getResponse(), and operator=().

◆ rootRoute

RootRoute* express::Controller::rootRoute = nullptr
private

Definition at line 96 of file Controller.h.

Referenced by Controller(), next(), operator=(), and setRootRoute().

◆ strictRouting

bool express::Controller::strictRouting
private

Definition at line 101 of file Controller.h.

Referenced by getStrictRouting(), and setStrictRouting().


The documentation for this class was generated from the following files: