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 nextRouter ()
 
bool dispatchNext (const std::string &parentMountPath)
 
void 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 lastTick.

◆ 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 Controller(), flags, and lastTick.

Referenced by Controller().

Here is the call graph for this function:
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:96

References flags, NEXT, NEXT_ROUTE, and NEXT_ROUTER.

◆ 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 }

◆ getResponse()

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

Definition at line 98 of file Controller.cpp.

98 {
99 return response;
100 }

◆ getStrictRouting()

bool express::Controller::getStrictRouting ( ) const

Definition at line 155 of file Controller.cpp.

155 {
156 return strictRouting;
157 }

References strictRouting.

◆ 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)
Definition RootRoute.cpp:95

References flags, lastTick, NEXT, NEXT_ROUTE, and NEXT_ROUTER.

◆ nextRouter()

bool express::Controller::nextRouter ( )

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 flags, and NEXT_ROUTER.

◆ 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 flags, and lastTick.

◆ setCurrentRoute()

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

Definition at line 90 of file Controller.cpp.

90 {
92 }

◆ setRootRoute()

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

Definition at line 86 of file Controller.cpp.

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

◆ setStrictRouting()

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

Definition at line 151 of file Controller.cpp.

151 {
153 }

References strictRouting.

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

Here is the caller graph for this function:

Member Data Documentation

◆ currentRoute

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

Definition at line 99 of file Controller.h.

◆ flags

int express::Controller::flags = NONE
mutableprivate

Definition at line 105 of file Controller.h.

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

◆ lastRoute

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

Definition at line 98 of file Controller.h.

◆ 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.

◆ response

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

Definition at line 94 of file Controller.h.

◆ rootRoute

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

Definition at line 96 of file Controller.h.

◆ 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: