Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,4 @@
url = https://github.com/jcelerier/snappy
[submodule "3rdparty/hap"]
path = 3rdparty/hap
url = https://github.com/Vidvox/hap
[submodule "3rdparty/qml-remote"]
path = 3rdparty/qml-remote
url = https://github.com/ossia/qml-remote.git
url = https://github.com/Vidvox/hap
4 changes: 2 additions & 2 deletions src/plugins/score-plugin-remotecontrol/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ set(HDRS
"RemoteControl/DocumentPlugin.hpp"
"i-score-remote/RemoteApplication.hpp"
"score_plugin_remotecontrol.hpp"
"RemoteControl/Http_server.hpp"
"RemoteControl/HttpServer.hpp"
)
set(SRCS
"${CMAKE_CURRENT_SOURCE_DIR}/RemoteControl/Settings/Model.cpp"
Expand All @@ -42,7 +42,7 @@ set(SRCS
"${CMAKE_CURRENT_SOURCE_DIR}/RemoteControl/ApplicationPlugin.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/RemoteControl/DocumentPlugin.cpp"

"${CMAKE_CURRENT_SOURCE_DIR}/RemoteControl/Http_server.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/RemoteControl/HttpServer.cpp"

"${CMAKE_CURRENT_SOURCE_DIR}/score_plugin_remotecontrol.cpp"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include <score/plugins/application/GUIApplicationPlugin.hpp>

#include <RemoteControl/Http_server.hpp>
#include <RemoteControl/HttpServer.hpp>
namespace RemoteControl
{
class ApplicationPlugin final : public score::GUIApplicationPlugin
Expand All @@ -11,6 +11,6 @@ class ApplicationPlugin final : public score::GUIApplicationPlugin

protected:
void on_createdDocument(score::Document& doc) override;
Http_server m_server;
HttpServer m_server;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
// Official repository: https://github.com/boostorg/beast
//

#include <RemoteControl/Http_server.hpp>
#include <RemoteControl/HttpServer.hpp>

//------------------------------------------------------------------------------

namespace RemoteControl
{

Http_server::Http_server()
HttpServer::HttpServer()
{
// m_docRoot = "/tmp";
}

Http_server::~Http_server()
HttpServer::~HttpServer()
{
shutdown(m_listenSocket, SHUT_RDWR);
ioc.stop();
Expand All @@ -28,7 +28,7 @@ Http_server::~Http_server()

// Return a reasonable mime type based on the extension of a file.
beast::string_view
Http_server::mime_type(beast::string_view path)
HttpServer::mime_type(beast::string_view path)
{
using beast::iequals;
auto const ext = [&path]
Expand Down Expand Up @@ -65,7 +65,7 @@ Http_server::mime_type(beast::string_view path)
// Append an HTTP rel-path to a local filesystem path.
// The returned path is normalized for the platform.
std::string
Http_server::path_cat(
HttpServer::path_cat(
beast::string_view base,
beast::string_view path)
{
Expand Down Expand Up @@ -97,7 +97,7 @@ template<
class Body, class Allocator,
class Send>
void
Http_server::handle_request(
HttpServer::handle_request(
beast::string_view doc_root,
http::request<Body, http::basic_fields<Allocator>>&& req,
Send&& send)
Expand Down Expand Up @@ -200,14 +200,14 @@ Http_server::handle_request(

// Report a failure
void
Http_server::fail(beast::error_code ec, char const* what)
HttpServer::fail(beast::error_code ec, char const* what)
{
std::cerr << what << ": " << ec.message() << "\n";
}

// Handles an HTTP server connection
void
Http_server::do_session(
HttpServer::do_session(
tcp::socket& socket,
std::shared_ptr<std::string const> const& doc_root)
{
Expand All @@ -228,12 +228,12 @@ Http_server::do_session(
if(ec == http::error::end_of_stream)
break;
if(ec)
return Http_server::fail(ec, "read");
return HttpServer::fail(ec, "read");

// Send the response
Http_server::handle_request(*doc_root, std::move(req), lambda);
HttpServer::handle_request(*doc_root, std::move(req), lambda);
if(ec)
return Http_server::fail(ec, "write");
return HttpServer::fail(ec, "write");
if(close)
{
// This means we should close the connection, usually because
Expand All @@ -252,13 +252,13 @@ Http_server::do_session(

// Set the IP address in the remote.html file
void
Http_server::set_ip_address(std::string address)
HttpServer::set_ip_address(std::string address)
{
std::rename("./src/plugins/score-plugin-remotecontrol/CMakeFiles/score_plugin_remotecontrol.dir/RemoteControl/build-wasm/remote.html",
"./src/plugins/score-plugin-remotecontrol/CMakeFiles/score_plugin_remotecontrol.dir/RemoteControl/build-wasm/remote.html~");
QDebug << "buildWasmPath :" << buildWasmPath;
std::rename(buildWasmPath + "remote.html", buildWasmPath + "remote.html~");

std::ifstream old_file("./src/plugins/score-plugin-remotecontrol/CMakeFiles/score_plugin_remotecontrol.dir/RemoteControl/build-wasm/remote.html~");
std::ofstream new_file("./src/plugins/score-plugin-remotecontrol/CMakeFiles/score_plugin_remotecontrol.dir/RemoteControl/build-wasm/remote.html");
std::ifstream old_file(buildWasmPath + "remote.html~");
std::ofstream new_file(buildWasmPath + "remote.html");

std::string addr = "\"" + address + "\"";

Expand All @@ -274,7 +274,7 @@ Http_server::set_ip_address(std::string address)

// Launch the open_server function in a thread
void
Http_server::start_thread()
HttpServer::start_thread()
{
m_serverThread = std::thread{[this] { open_server(); }};
}
Expand All @@ -283,13 +283,17 @@ Http_server::start_thread()

// Open a server using sockets
int
Http_server::open_server()
HttpServer::open_server()
{
try
{
auto const address2 = net::ip::make_address("0.0.0.0");
auto const port = static_cast<unsigned short>(std::atoi("8080"));
auto const m_docRoot = std::make_shared<std::string>("./src/plugins/score-plugin-remotecontrol/CMakeFiles/score_plugin_remotecontrol.dir/RemoteControl/build-wasm/");
// auto const m_docRoot = std::make_shared<std::string>("./src/plugins/score-plugin-remotecontrol/CMakeFiles/score_plugin_remotecontrol.dir/RemoteControl/build-wasm/");
Comment thread
thibaudk marked this conversation as resolved.
Outdated
std::string packagesPath = score::AppContext().settings<Library::Settings::Model>().getPackagesPath().toUtf8().constData();
Comment thread
thibaudk marked this conversation as resolved.
Outdated
QDebug << "packagesPath :" << packagesPath;
Comment thread
thibaudk marked this conversation as resolved.
Outdated
buildWasmPath = packagesPath + "/build-wasm/";
auto const m_docRoot = std::make_shared<std::string>(buildWasmPath);

bool is_ip_address_set = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <string>
#include <thread>
#include <fstream>
#include <Library/LibrarySettings.hpp>
#include <score/application/ApplicationContext.hpp>

#ifdef _WIN32
#define SHUT_RDWR 2
Expand All @@ -42,16 +44,16 @@ using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>

namespace RemoteControl
{
class Http_server
class HttpServer
{
public:
net::io_context ioc;

//std::thread th1;

Http_server();
HttpServer();

~Http_server();
~HttpServer();

//------------------------------------------------------------------------------

Expand Down Expand Up @@ -148,5 +150,6 @@ class Http_server

std::thread m_serverThread;
int m_listenSocket{};
std::string buildWasmPath;
Comment thread
thibaudk marked this conversation as resolved.
Outdated
};
}