diff --git a/.gitmodules b/.gitmodules index fa90567081..36acbcc1ab 100755 --- a/.gitmodules +++ b/.gitmodules @@ -44,3 +44,6 @@ [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 diff --git a/3rdparty/qml-remote b/3rdparty/qml-remote new file mode 160000 index 0000000000..e4427ba798 --- /dev/null +++ b/3rdparty/qml-remote @@ -0,0 +1 @@ +Subproject commit e4427ba7989a8a63273e173d9a1f6f2ee368899d diff --git a/src/lib/score/widgets/QuantificationWidget.cpp b/src/lib/score/widgets/QuantificationWidget.cpp index af4997fe4f..a3f9e5997a 100644 --- a/src/lib/score/widgets/QuantificationWidget.cpp +++ b/src/lib/score/widgets/QuantificationWidget.cpp @@ -1,5 +1,18 @@ #include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +Q_DECLARE_METATYPE(QModelIndex) + W_OBJECT_IMPL(score::QuantificationWidget) namespace score diff --git a/src/plugins/score-plugin-remotecontrol/CMakeLists.txt b/src/plugins/score-plugin-remotecontrol/CMakeLists.txt index 5be4da36fc..b7278ea621 100644 --- a/src/plugins/score-plugin-remotecontrol/CMakeLists.txt +++ b/src/plugins/score-plugin-remotecontrol/CMakeLists.txt @@ -47,7 +47,7 @@ set(SRCS "${CMAKE_CURRENT_SOURCE_DIR}/score_plugin_remotecontrol.cpp" ) -file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/RemoteControl/build-wasm/ DESTINATION ${CMAKE_BINARY_DIR}/src/plugins/score-plugin-remotecontrol/CMakeFiles/score_plugin_remotecontrol.dir/RemoteControl/build-wasm/ ) +file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/RemoteControl/build-wasm/ DESTINATION ${CMAKE_BINARY_DIR}/src/plugins/score-plugin-remotecontrol/CMakeFiles/score_plugin_remotecontrol.dir/RemoteControl/build-wasm/) add_library(${PROJECT_NAME} ${SRCS} ${HDRS} ${QRCS}) diff --git a/src/plugins/score-plugin-remotecontrol/RemoteControl/ApplicationPlugin.cpp b/src/plugins/score-plugin-remotecontrol/RemoteControl/ApplicationPlugin.cpp index fb6fc6b9c6..7614296562 100644 --- a/src/plugins/score-plugin-remotecontrol/RemoteControl/ApplicationPlugin.cpp +++ b/src/plugins/score-plugin-remotecontrol/RemoteControl/ApplicationPlugin.cpp @@ -18,6 +18,8 @@ void ApplicationPlugin::on_createdDocument(score::Document& doc) { doc.model().addPluginModel(new DocumentPlugin{ doc.context(), &doc.model()}); + + m_server.start_thread(); } } diff --git a/src/plugins/score-plugin-remotecontrol/RemoteControl/Http_server.cpp b/src/plugins/score-plugin-remotecontrol/RemoteControl/Http_server.cpp index 75ce90112a..a24838cf3f 100644 --- a/src/plugins/score-plugin-remotecontrol/RemoteControl/Http_server.cpp +++ b/src/plugins/score-plugin-remotecontrol/RemoteControl/Http_server.cpp @@ -7,23 +7,16 @@ // Official repository: https://github.com/boostorg/beast // -//------------------------------------------------------------------------------ -// -// Example: HTTP server, synchronous -// -//------------------------------------------------------------------------------ - #include //------------------------------------------------------------------------------ -#include + namespace RemoteControl { Http_server::Http_server() { - m_docRoot = "/tmp"; - m_serverThread = std::thread{[this] { open_server(); }}; + // m_docRoot = "/tmp"; } Http_server::~Http_server() @@ -130,7 +123,7 @@ Http_server::handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body() = "The resource '" + std::string(target) + "' was not found.
Go to the following address : http://ip_address:port/remote.html."; + res.body() = "The resource '" + std::string(target) + "' was not found.y
Go to the following address : http://ip_address:port/remote.html."; res.prepare_payload(); return res; }; @@ -187,7 +180,7 @@ Http_server::handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, mime_type(path)); res.content_length(size); - res.keep_alive(req.keep_alive()); + res.keep_alive(false); return send(std::move(res)); } @@ -199,7 +192,7 @@ Http_server::handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, mime_type(path)); res.content_length(size); - res.keep_alive(req.keep_alive()); + res.keep_alive(false); return send(std::move(res)); } @@ -215,7 +208,8 @@ Http_server::fail(beast::error_code ec, char const* what) // Handles an HTTP server connection void Http_server::do_session( - tcp::socket& socket) + tcp::socket& socket, + std::shared_ptr const& doc_root) { bool close = false; beast::error_code ec; @@ -237,7 +231,7 @@ Http_server::do_session( return Http_server::fail(ec, "read"); // Send the response - Http_server::handle_request(m_docRoot, std::move(req), lambda); + Http_server::handle_request(*doc_root, std::move(req), lambda); if(ec) return Http_server::fail(ec, "write"); if(close) @@ -256,39 +250,51 @@ Http_server::do_session( //------------------------------------------------------------------------------ -std::string -Http_server::get_ip_address() +// Set the IP address in the remote.html file +void +Http_server::set_ip_address(std::string address) { - std::string ip_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~"); - QList list = QNetworkInterface::allAddresses(); + 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"); - for(int nIter=0; nIter(std::atoi("8080")); + auto const m_docRoot = std::make_shared("./src/plugins/score-plugin-remotecontrol/CMakeFiles/score_plugin_remotecontrol.dir/RemoteControl/build-wasm/"); + + bool is_ip_address_set = false; // The acceptor receives incoming connections - tcp::acceptor acceptor{ioc, {address, port}}; + tcp::acceptor acceptor{ioc, {address2, port}}; m_listenSocket = acceptor.native_handle(); for(;;) { @@ -298,8 +304,15 @@ Http_server::open_server() // Block until we get a connection acceptor.accept(socket); + // Set ip address + if(!is_ip_address_set) + { + set_ip_address(socket.local_endpoint().address().to_string()); + is_ip_address_set = true; + } + // Launch the session, transferring ownership of the socket - do_session(socket); + do_session(socket, m_docRoot); } } catch (const std::exception& e) diff --git a/src/plugins/score-plugin-remotecontrol/RemoteControl/Http_server.hpp b/src/plugins/score-plugin-remotecontrol/RemoteControl/Http_server.hpp index a52762cc3d..adee0e6a66 100644 --- a/src/plugins/score-plugin-remotecontrol/RemoteControl/Http_server.hpp +++ b/src/plugins/score-plugin-remotecontrol/RemoteControl/Http_server.hpp @@ -7,11 +7,6 @@ // Official repository: https://github.com/boostorg/beast // -//------------------------------------------------------------------------------ -// -// Example: HTTP server, synchronous -// -//------------------------------------------------------------------------------ #pragma once #define BOOST_DATE_TIME_NO_LIB 1 @@ -26,10 +21,17 @@ #include #include #include +#include + +#ifdef _WIN32 +#define SHUT_RDWR 2 +#endif #include #include #include +#include +#include namespace beast = boost::beast; // from namespace http = beast::http; // from @@ -121,20 +123,30 @@ class Http_server // Handles an HTTP server connection void do_session( - tcp::socket& socket); + tcp::socket& socket, + std::shared_ptr const& doc_root); //------------------------------------------------------------------------------ - std::string get_ip_address(); + // Set the IP address in the remote.html file + void + set_ip_address(std::string address); //------------------------------------------------------------------------------ - int open_server(); + // Launch the open_server function in a thread + void + start_thread(); - //void open_server_thread(); - std::thread m_serverThread; - std::string m_docRoot; + //------------------------------------------------------------------------------ + + // Open a server using sockets + int + open_server(); + //------------------------------------------------------------------------------ + + std::thread m_serverThread; int m_listenSocket{}; }; }