-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split OdbApp and OdbServerApp apart for deriving from a base app with…
… or without crow server capability
- Loading branch information
Showing
8 changed files
with
144 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "IOdbServerApp.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include "CommandLineArgs.h" | ||
#include "DesignCache.h" | ||
#include "ExitCode.h" | ||
#include "odbdesign_export.h" | ||
|
||
using namespace Utils; | ||
|
||
namespace Odb::Lib | ||
{ | ||
class ODBDESIGN_EXPORT IOdbApp | ||
{ | ||
public: | ||
virtual ~IOdbApp() {} | ||
|
||
virtual const CommandLineArgs& arguments() const = 0; | ||
virtual DesignCache& design_cache() = 0; | ||
|
||
virtual ExitCode Run() = 0; | ||
|
||
protected: | ||
// abstract class/interface | ||
IOdbApp() = default; | ||
|
||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,20 @@ | ||
#pragma once | ||
|
||
#include "CommandLineArgs.h" | ||
#include "DesignCache.h" | ||
#include "ExitCode.h" | ||
#include "IOdbApp.h" | ||
#include "crow_win.h" | ||
#include "odbdesign_export.h" | ||
|
||
namespace Odb::Lib | ||
{ | ||
class ODBDESIGN_EXPORT IOdbServerApp | ||
class ODBDESIGN_EXPORT IOdbServerApp : public virtual IOdbApp | ||
{ | ||
public: | ||
virtual ~IOdbServerApp() {} | ||
|
||
virtual const Utils::CommandLineArgs& arguments() const = 0; | ||
virtual crow::SimpleApp& crow_app() = 0; | ||
virtual Odb::Lib::DesignCache& design_cache() = 0; | ||
|
||
virtual Utils::ExitCode Run() = 0; | ||
|
||
protected: | ||
// abstract class/interface | ||
IOdbServerApp() = default; | ||
|
||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "OdbServerAppBase.h" | ||
|
||
namespace Odb::Lib | ||
{ | ||
OdbAppBase::OdbAppBase(int argc, char* argv[]) | ||
: m_designCache("designs") | ||
, m_commandLineArgs(argc, argv) | ||
{ | ||
} | ||
|
||
OdbAppBase::~OdbAppBase() | ||
{ | ||
} | ||
|
||
const CommandLineArgs& OdbAppBase::arguments() const | ||
{ | ||
return m_commandLineArgs; | ||
} | ||
|
||
DesignCache& OdbAppBase::design_cache() | ||
{ | ||
return m_designCache; | ||
} | ||
|
||
Utils::ExitCode OdbAppBase::Run() | ||
{ | ||
//m_crowApp.loglevel(crow::LogLevel::Debug) | ||
|
||
return Utils::ExitCode::Success; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include "IOdbServerApp.h" | ||
#include "DesignCache.h" | ||
#include "Logger.h" | ||
#include "CommandLineArgs.h" | ||
#include "odbdesign_export.h" | ||
|
||
using namespace Utils; | ||
|
||
namespace Odb::Lib | ||
{ | ||
class ODBDESIGN_EXPORT OdbAppBase : public virtual IOdbApp | ||
{ | ||
public: | ||
OdbAppBase(int argc, char* argv[]); | ||
virtual ~OdbAppBase(); | ||
|
||
static Logger m_logger; | ||
|
||
const CommandLineArgs& arguments() const override; | ||
DesignCache& design_cache() override; | ||
|
||
virtual Utils::ExitCode Run() override; | ||
|
||
protected: | ||
DesignCache m_designCache; | ||
CommandLineArgs m_commandLineArgs; | ||
|
||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,47 @@ | ||
#include "OdbServerAppBase.h" | ||
|
||
|
||
namespace Odb::Lib | ||
{ | ||
OdbServerAppBase::OdbServerAppBase(int argc, char* argv[]) | ||
: m_designCache("designs") | ||
, m_commandLineArgs(argc, argv) | ||
{ | ||
} | ||
|
||
OdbServerAppBase::~OdbServerAppBase() | ||
{ | ||
m_vecControllers.clear(); | ||
} | ||
|
||
Utils::ExitCode OdbServerAppBase::Run() | ||
{ | ||
//m_crowApp.loglevel(crow::LogLevel::Debug) | ||
m_crowApp.use_compression(crow::compression::algorithm::GZIP); | ||
|
||
// let subclasses add controller types | ||
add_controllers(); | ||
|
||
// register all controllers' routes | ||
register_routes(); | ||
|
||
// run the server | ||
m_crowApp.port(18080).multithreaded().run(); | ||
|
||
return Utils::ExitCode::Success; | ||
} | ||
|
||
void OdbServerAppBase::register_routes() | ||
{ | ||
for (const auto& pController : m_vecControllers) | ||
{ | ||
pController->register_routes(); | ||
} | ||
} | ||
Odb::Lib::OdbServerAppBase::OdbServerAppBase(int argc, char* argv[]) | ||
: OdbAppBase(argc, argv) | ||
{ | ||
} | ||
|
||
Odb::Lib::OdbServerAppBase::~OdbServerAppBase() | ||
{ | ||
m_vecControllers.clear(); | ||
} | ||
|
||
ExitCode Odb::Lib::OdbServerAppBase::Run() | ||
{ | ||
auto result = OdbAppBase::Run(); | ||
if (result != ExitCode::Success) return result; | ||
|
||
m_crowApp.use_compression(crow::compression::algorithm::GZIP); | ||
|
||
// let subclasses add controller types | ||
add_controllers(); | ||
|
||
// register all added controllers' routes | ||
register_routes(); | ||
|
||
// run the server | ||
m_crowApp.port(18080).multithreaded().run(); | ||
|
||
return ExitCode::Success; | ||
} | ||
|
||
crow::SimpleApp& Odb::Lib::OdbServerAppBase::crow_app() | ||
{ | ||
return m_crowApp; | ||
} | ||
|
||
void OdbServerAppBase::register_routes() | ||
{ | ||
for (const auto& pController : m_vecControllers) | ||
{ | ||
pController->register_routes(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,31 @@ | ||
#pragma once | ||
|
||
#include "IOdbServerApp.h" | ||
#include "crow_win.h" | ||
#include "DesignCache.h" | ||
#include "Logger.h" | ||
#include "CommandLineArgs.h" | ||
#include "OdbAppBase.h" | ||
#include "RouteController.h" | ||
#include "crow_win.h" | ||
#include "odbdesign_export.h" | ||
|
||
using namespace Utils; | ||
|
||
namespace Odb::Lib | ||
{ | ||
class ODBDESIGN_EXPORT OdbServerAppBase : public IOdbServerApp | ||
class ODBDESIGN_EXPORT OdbServerAppBase : public OdbAppBase, public IOdbServerApp | ||
{ | ||
public: | ||
OdbServerAppBase(int argc, char* argv[]); | ||
virtual ~OdbServerAppBase(); | ||
|
||
static Logger m_logger; | ||
crow::SimpleApp& crow_app() override; | ||
|
||
inline const CommandLineArgs& arguments() const override { return m_commandLineArgs; } | ||
inline crow::SimpleApp& crow_app() override { return m_crowApp; } | ||
inline DesignCache& design_cache() override { return m_designCache; } | ||
|
||
virtual Utils::ExitCode Run() override; | ||
ExitCode Run() override; | ||
|
||
protected: | ||
DesignCache m_designCache; | ||
crow::SimpleApp m_crowApp; | ||
CommandLineArgs m_commandLineArgs; | ||
RouteController::Vector m_vecControllers; | ||
|
||
RouteController::Vector m_vecControllers; | ||
|
||
// implement in subclasses to add route controllers | ||
virtual void add_controllers() = 0; | ||
virtual void add_controllers() = 0; | ||
|
||
private: | ||
void register_routes(); | ||
|
||
}; | ||
} |