Skip to content

Commit

Permalink
change RouteController's member field for server app from a pointer t…
Browse files Browse the repository at this point in the history
…o a reference
  • Loading branch information
nam20485 committed Oct 13, 2023
1 parent 7eaa064 commit 82d1a84
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions OdbDesignLib/RouteController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Odb::Lib
{
RouteController::RouteController(IOdbServerApp* pServerApp)
: m_pServerApp(pServerApp)
RouteController::RouteController(IOdbServerApp& serverApp)
: m_serverApp(serverApp)
{
}

Expand Down
4 changes: 2 additions & 2 deletions OdbDesignLib/RouteController.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ namespace Odb::Lib
class ODBDESIGN_EXPORT RouteController
{
public:
RouteController(IOdbServerApp* pServerApp);
RouteController(IOdbServerApp& serverApp);

virtual void register_routes() = 0;

typedef std::vector<std::shared_ptr<RouteController>> Vector;

protected:
IOdbServerApp* m_pServerApp;
IOdbServerApp& m_serverApp;

typedef std::function<crow::response(const crow::request& req)> TRouteHandlerFunction;

Expand Down
8 changes: 4 additions & 4 deletions OdbDesignServer/Controllers/HelloWorldController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@

namespace Odb::App::Server
{
HelloWorldController::HelloWorldController(IOdbServerApp* pServerApp)
: RouteController(pServerApp)
HelloWorldController::HelloWorldController(IOdbServerApp& serverApp)
: RouteController(serverApp)
{
}

void HelloWorldController::register_routes()
{
// /helloworld
CROW_ROUTE(m_pServerApp->crow_app(), "/helloworld")([]() {
CROW_ROUTE(m_serverApp.crow_app(), "/helloworld")([]() {
//return "Hello world";
auto page = crow::mustache::load_text("helloworld.html");
return page;
});

// /hellodesign/<string>
CROW_ROUTE(m_pServerApp->crow_app(), "/hellodesign/<string>")([](std::string designName) {
CROW_ROUTE(m_serverApp.crow_app(), "/hellodesign/<string>")([](std::string designName) {
auto page = crow::mustache::load("helloworld.html");
crow::mustache::context ctx({ {"design", designName} });
return page.render(ctx);
Expand Down
2 changes: 1 addition & 1 deletion OdbDesignServer/Controllers/HelloWorldController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Odb::App::Server
class HelloWorldController : public RouteController
{
public:
HelloWorldController(IOdbServerApp* pServerApp);
HelloWorldController(IOdbServerApp& serverApp);

void register_routes() override;

Expand Down
8 changes: 4 additions & 4 deletions OdbDesignServer/Controllers/StepsEdaDataController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ using namespace Utils;

namespace Odb::App::Server
{
StepsEdaDataController::StepsEdaDataController(IOdbServerApp* pServerApp)
: RouteController(pServerApp)
StepsEdaDataController::StepsEdaDataController(IOdbServerApp& serverApp)
: RouteController(serverApp)
{
}

Expand All @@ -25,7 +25,7 @@ namespace Odb::App::Server
//app.route_dynamic(url)

// TODO: figure out why capture here is weird (i.e. how to capture pServerApp so it can be used in the member fxn handler)
CROW_ROUTE(m_pServerApp->crow_app(), "/steps/eda_data")
CROW_ROUTE(m_serverApp.crow_app(), "/steps/eda_data")
([&](const crow::request& req)
{
return this->steps_edadata_route_handler(req);
Expand All @@ -52,7 +52,7 @@ namespace Odb::App::Server
return crow::response(crow::status::BAD_REQUEST, "step name not specified");
}

auto pFileArchive = m_pServerApp->design_cache().GetFileArchive(designName);
auto pFileArchive = m_serverApp.design_cache().GetFileArchive(designName);
if (pFileArchive == nullptr)
{
std::stringstream ss;
Expand Down
2 changes: 1 addition & 1 deletion OdbDesignServer/Controllers/StepsEdaDataController.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Odb::App::Server
class StepsEdaDataController : public RouteController
{
public:
StepsEdaDataController(IOdbServerApp* pServerApp);
StepsEdaDataController(IOdbServerApp& serverApp);

void register_routes() override;

Expand Down
4 changes: 2 additions & 2 deletions OdbDesignServer/OdbDesignServerApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Odb::App::Server

void OdbDesignServerApp::add_controllers()
{
m_vecControllers.push_back(std::make_shared<HelloWorldController>(this));
m_vecControllers.push_back(std::make_shared<StepsEdaDataController>(this));
m_vecControllers.push_back(std::make_shared<HelloWorldController>(*this));
m_vecControllers.push_back(std::make_shared<StepsEdaDataController>(*this));
}
}

0 comments on commit 82d1a84

Please sign in to comment.