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)
 
bool laxRouting ()
 

Private Attributes

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

Detailed Description

Definition at line 44 of file Controller.h.

Member Enumeration Documentation

◆ Flags

Enumerator
NONE 
NEXT 
NEXT_ROUTE 
NEXT_ROUTER 

Definition at line 66 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 33 of file Controller.cpp.

35 : request(std::make_shared<Request>(request))
36 , response(std::make_shared<Response>(response))
38 }
static unsigned long getTickCounter()
Definition EventLoop.cpp:63
unsigned long lastTick
Definition Controller.h:77
std::shared_ptr< Response > response
Definition Controller.h:70
std::shared_ptr< Request > request
Definition Controller.h:69

References lastTick.

◆ Controller() [2/2]

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

Definition at line 40 of file Controller.cpp.

41 : request(controller.request)
42 , response(controller.response)
43 , rootRoute(controller.rootRoute)
44 , lastRoute(controller.lastRoute)
45 , currentRoute(controller.currentRoute)
46 , lastTick(controller.lastTick)
47 , flags(controller.flags) {
48 }
RootRoute * rootRoute
Definition Controller.h:72

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 110 of file Controller.cpp.

110 {
111 bool dispatched = false;
112
113 if (((flags & Controller::NEXT) != 0)) {
114 if (lastRoute == currentRoute) {
115 flags &= ~Controller::NEXT;
116 if ((flags & Controller::NEXT_ROUTE) != 0) {
117 flags &= ~Controller::NEXT_ROUTE;
118 } else if ((flags & Controller::NEXT_ROUTER) == 0) {
119 dispatched = currentRoute->dispatchNext(*this, parentMountPath);
120 }
121 } else { // ? Optimization: Dispatch only parent route matched path
122 dispatched = currentRoute->dispatchNext(*this, parentMountPath);
123 }
124 }
125
126 return dispatched;
127 }
bool dispatchNext(Controller &controller, const std::string &parentMountPath)
Definition Route.cpp:74

References flags, NEXT, NEXT_ROUTE, and NEXT_ROUTER.

◆ getFlags()

int express::Controller::getFlags ( ) const

Definition at line 80 of file Controller.cpp.

80 {
81 return flags;
82 }

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 72 of file Controller.cpp.

72 {
73 return request;
74 }

◆ getResponse()

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

Definition at line 76 of file Controller.cpp.

76 {
77 return response;
78 }

◆ laxRouting()

bool express::Controller::laxRouting ( )

Definition at line 129 of file Controller.cpp.

129 {
130 bool ret = false;
131
132 if (!request->url.ends_with('/')) {
133 request->url.append("/");
134
135 ret = true;
136 }
137
138 return ret;
139 }

◆ next()

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

Definition at line 84 of file Controller.cpp.

84 {
85 flags = NEXT;
86
87 if (how == "route") {
89 } else if (how == "router") {
91 }
92
94
95 if (lastTick != core::EventLoop::getTickCounter()) { // If asynchronous next() start traversing of route-tree
96 rootRoute->dispatch(*const_cast<express::Controller*>(this));
97 }
98 }
void dispatch(Controller &&controller)
Definition RootRoute.cpp:69

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

◆ nextRouter()

bool express::Controller::nextRouter ( )

Definition at line 100 of file Controller.cpp.

100 {
101 const bool breakDispatching = lastRoute == currentRoute && (flags & Controller::NEXT_ROUTER) != 0;
102
103 if (breakDispatching) {
104 flags &= ~Controller::NEXT_ROUTER;
105 }
106
107 return breakDispatching;
108 }

References flags, and NEXT_ROUTER.

◆ operator=()

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

Definition at line 50 of file Controller.cpp.

50 {
51 if (this != &controller) {
52 request = controller.request;
53 response = controller.response;
54 rootRoute = controller.rootRoute;
55 lastRoute = controller.lastRoute;
56 currentRoute = controller.currentRoute;
57 lastTick = controller.lastTick;
58 flags = controller.flags;
59 }
60
61 return *this;
62 }

References flags, and lastTick.

◆ setCurrentRoute()

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

Definition at line 68 of file Controller.cpp.

68 {
70 }

◆ setRootRoute()

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

Definition at line 64 of file Controller.cpp.

64 {
65 this->rootRoute = rootRoute;
66 }

Member Data Documentation

◆ currentRoute

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

Definition at line 75 of file Controller.h.

◆ flags

int express::Controller::flags = NONE
mutableprivate

Definition at line 79 of file Controller.h.

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

◆ lastRoute

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

Definition at line 74 of file Controller.h.

◆ lastTick

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

Definition at line 77 of file Controller.h.

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

◆ request

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

Definition at line 69 of file Controller.h.

◆ response

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

Definition at line 70 of file Controller.h.

◆ rootRoute

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

Definition at line 72 of file Controller.h.


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