diff --git a/OdbDesignLib/CMakeLists.txt b/OdbDesignLib/CMakeLists.txt index e05b3879..3eb9310d 100644 --- a/OdbDesignLib/CMakeLists.txt +++ b/OdbDesignLib/CMakeLists.txt @@ -1,7 +1,7 @@ # CMakeList.txt : CMake project for OdbDesignLib # -add_library(OdbDesign SHARED "odbdesign_export.h" "ComponentLayerDirectory.cpp" "ComponentLayerDirectory.h" "EdaDataFile.cpp" "EdaDataFile.h" "LayerDirectory.cpp" "LayerDirectory.h" "NetlistFile.cpp" "NetlistFile.h" "FileArchive.cpp" "FileArchive.h" "StepDirectory.cpp" "StepDirectory.h" "Net.h" "Net.cpp" "Component.h" "Component.cpp" "Pin.h" "Pin.cpp" "PinConnection.h" "PinConnection.cpp" "Package.h" "Package.cpp" "Part.h" "Part.cpp" "Via.h" "Via.cpp" "Design.h" "Design.cpp" "BoardSide.h" "OdbDesign.h" "DesignCache.h" "DesignCache.cpp" "win.h" "proto/edadatafile.pb.h" "proto/edadatafile.pb.cc" "IProtoBuffable.h" "crow_win.h" "OdbFile.h" "OdbFile.cpp" "OdbFileRecord.h" "OdbFileRecord.cpp" "IOdbServerApp.h" "IOdbServerApp.cpp" "OdbServerAppBase.h" "OdbServerAppBase.cpp" "RouteController.h" "RouteController.cpp") +add_library(OdbDesign SHARED "odbdesign_export.h" "ComponentLayerDirectory.cpp" "ComponentLayerDirectory.h" "EdaDataFile.cpp" "EdaDataFile.h" "LayerDirectory.cpp" "LayerDirectory.h" "NetlistFile.cpp" "NetlistFile.h" "FileArchive.cpp" "FileArchive.h" "StepDirectory.cpp" "StepDirectory.h" "Net.h" "Net.cpp" "Component.h" "Component.cpp" "Pin.h" "Pin.cpp" "PinConnection.h" "PinConnection.cpp" "Package.h" "Package.cpp" "Part.h" "Part.cpp" "Via.h" "Via.cpp" "Design.h" "Design.cpp" "BoardSide.h" "OdbDesign.h" "DesignCache.h" "DesignCache.cpp" "win.h" "proto/edadatafile.pb.h" "proto/edadatafile.pb.cc" "IProtoBuffable.h" "crow_win.h" "OdbFile.h" "OdbFile.cpp" "OdbFileRecord.h" "OdbFileRecord.cpp" "IOdbApp.h" "IOdbApp.cpp" "OdbAppBase.h" "OdbAppBase.cpp" "RouteController.h" "RouteController.cpp" "IOdbServerApp.h" "OdbServerAppBase.h" "OdbServerAppBase.cpp" "IOdbServerApp.cpp") # required for SWIG set_property(TARGET OdbDesign PROPERTY POSITION_INDEPENDENT_CODE ON) diff --git a/OdbDesignLib/IOdbApp.cpp b/OdbDesignLib/IOdbApp.cpp new file mode 100644 index 00000000..edc74ed1 --- /dev/null +++ b/OdbDesignLib/IOdbApp.cpp @@ -0,0 +1 @@ +#include "IOdbServerApp.h" \ No newline at end of file diff --git a/OdbDesignLib/IOdbApp.h b/OdbDesignLib/IOdbApp.h new file mode 100644 index 00000000..8f1372d4 --- /dev/null +++ b/OdbDesignLib/IOdbApp.h @@ -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; + + }; +} diff --git a/OdbDesignLib/IOdbServerApp.h b/OdbDesignLib/IOdbServerApp.h index 5951a763..7745cc12 100644 --- a/OdbDesignLib/IOdbServerApp.h +++ b/OdbDesignLib/IOdbServerApp.h @@ -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; - + }; } diff --git a/OdbDesignLib/OdbAppBase.cpp b/OdbDesignLib/OdbAppBase.cpp new file mode 100644 index 00000000..e0257a23 --- /dev/null +++ b/OdbDesignLib/OdbAppBase.cpp @@ -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; + } +} \ No newline at end of file diff --git a/OdbDesignLib/OdbAppBase.h b/OdbDesignLib/OdbAppBase.h new file mode 100644 index 00000000..b6dd1d70 --- /dev/null +++ b/OdbDesignLib/OdbAppBase.h @@ -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; + + }; +} diff --git a/OdbDesignLib/OdbServerAppBase.cpp b/OdbDesignLib/OdbServerAppBase.cpp index 0879725d..36551670 100644 --- a/OdbDesignLib/OdbServerAppBase.cpp +++ b/OdbDesignLib/OdbServerAppBase.cpp @@ -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(); + } + } } \ No newline at end of file diff --git a/OdbDesignLib/OdbServerAppBase.h b/OdbDesignLib/OdbServerAppBase.h index de32862e..a0a9974c 100644 --- a/OdbDesignLib/OdbServerAppBase.h +++ b/OdbDesignLib/OdbServerAppBase.h @@ -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(); - }; }