Skip to content

Commit

Permalink
split OdbApp and OdbServerApp apart for deriving from a base app with…
Browse files Browse the repository at this point in the history
… or without crow server capability
  • Loading branch information
nam20485 committed Oct 13, 2023
1 parent 9d53c2f commit 7eaa064
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 65 deletions.
2 changes: 1 addition & 1 deletion OdbDesignLib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
1 change: 1 addition & 0 deletions OdbDesignLib/IOdbApp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "IOdbServerApp.h"
27 changes: 27 additions & 0 deletions OdbDesignLib/IOdbApp.h
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;

};
}
13 changes: 3 additions & 10 deletions OdbDesignLib/IOdbServerApp.h
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;

};
}
31 changes: 31 additions & 0 deletions OdbDesignLib/OdbAppBase.cpp
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;
}
}
31 changes: 31 additions & 0 deletions OdbDesignLib/OdbAppBase.h
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;

};
}
77 changes: 42 additions & 35 deletions OdbDesignLib/OdbServerAppBase.cpp
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();
}
}
}
27 changes: 8 additions & 19 deletions OdbDesignLib/OdbServerAppBase.h
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();

};
}

0 comments on commit 7eaa064

Please sign in to comment.