Skip to content

Commit

Permalink
Update build configuration and server implementation
Browse files Browse the repository at this point in the history
- Add npm install and build targets for the oRatio GUI in CMakeLists.txt
- Update .gitignore to include additional files
- Modify server constructor to use a relative path for assets directory
- Implement assets route in the server to serve static files
- Enhance main function to handle multiple input files and output solution
- Update submodule references for rationet and riddle
  • Loading branch information
riccardodebenedictis committed Jan 15, 2025
1 parent caafb28 commit da9d396
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.vscode
build
.z3-trace
build
solution.json
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ if(BUILD_ORATIO_SERVER)
target_link_libraries(oRatioServer PUBLIC oRatioLib ratioNet)

setup_sanitizers(oRatioServer)

add_custom_target(npm_install ALL COMMAND npm install WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/gui COMMENT "Installing the oRatio GUI" VERBATIM)
add_custom_target(npm_build ALL COMMAND npm run build WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/gui COMMENT "Building the oRatio GUI" VERBATIM DEPENDS npm_install)
endif()

if(BUILD_TESTING)
Expand Down
2 changes: 1 addition & 1 deletion extern/rationet
2 changes: 1 addition & 1 deletion extern/riddle
3 changes: 2 additions & 1 deletion include/server/solver_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ namespace ratio::server
#endif
{
public:
server(std::string_view assets_dir = "/gui/dist");
server(std::string_view assets_dir = "./gui/dist");

private:
std::unique_ptr<network::response> index(const network::request &req);
std::unique_ptr<network::response> assets(const network::request &req);

private:
void state_changed() override;
Expand Down
37 changes: 37 additions & 0 deletions src/server/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,43 @@
#include "solver_server.hpp"
#include "logging.hpp"
#include <thread>

int main(int argc, char const *argv[])
{
if (argc < 3)
{
LOG_FATAL("usage: oRatio <input-file> [<input-file> ...] <output-file>");
return -1;
}

// the problem files..
std::vector<std::string> prob_names;
for (int i = 1; i < argc - 1; i++)
prob_names.push_back(argv[i]);

// the solution file..
std::string sol_name = argv[argc - 1];

LOG_INFO("starting oRatio server");

ratio::server::server server;

auto srv_ft = std::async(std::launch::async, [&server]
{ server.start(); });
std::this_thread::sleep_for(std::chrono::seconds(1));
server.read(prob_names);

if (server.solve())
{
LOG_INFO("hurray!! we have found a solution..");

std::ofstream sol_file;
sol_file.open(sol_name);
sol_file << server.to_json().dump();
sol_file.close();
}
else
LOG_INFO("the problem is unsolvable..");

return 0;
}
17 changes: 14 additions & 3 deletions src/server/solver_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,26 @@
namespace ratio::server
{
#if defined(SEMITONE)
server::server() : network::server(), ratio::semitonesolver()
server::server() : network::server(SERVER_HOST, SERVER_PORT, 1), ratio::semitonesolver()
#elif defined(Z3)
server::server(std::string_view assets_dir) : network::server(), ratio::z3solver(), assets_dir(assets_dir)
server::server(std::string_view assets_dir) : network::server(SERVER_HOST, SERVER_PORT, 1), ratio::z3solver(), assets_dir(assets_dir)
#endif
{
add_route(network::Get, "^/$", std::bind(&server::index, this, network::placeholders::request));
add_route(network::Get, "^(/assets/.+)|/.+\\.ico|/.+\\.png", std::bind(&server::assets, this, network::placeholders::request));
}

std::unique_ptr<network::response> server::index(const network::request &) { return std::make_unique<network::file_response>(assets_dir + "/index.html"); }
std::unique_ptr<network::response> server::index(const network::request &)
{
return std::make_unique<network::file_response>(assets_dir + "/index.html");
}
std::unique_ptr<network::response> server::assets(const network::request &req)
{
std::string target = req.get_target();
if (target.find('?') != std::string::npos)
target = target.substr(0, target.find('?'));
return std::make_unique<network::file_response>(assets_dir + target);
}

void server::state_changed() {}
void server::flaw_created(const ratio::flaw &f) {}
Expand Down

0 comments on commit da9d396

Please sign in to comment.