diff --git a/applications/gui/src/ctrl_window.cpp b/applications/gui/src/ctrl_window.cpp index 38a496376cd95b5ec96b72a9cd3c8bb0694ed124..ef28546400e123c1651504602ffd32809065f202 100644 --- a/applications/gui/src/ctrl_window.cpp +++ b/applications/gui/src/ctrl_window.cpp @@ -30,9 +30,9 @@ ControlWindow::ControlWindow(nanogui::Widget *parent, ftl::ctrl::Master *ctrl) button->setCallback([this] { ctrl_->restart(); }); - button = new Button(this, "Shutdown All", ENTYPO_ICON_POWER_PLUG); + button = new Button(this, "Pause All", ENTYPO_ICON_POWER_PLUG); button->setCallback([this] { - ctrl_->shutdown(); + ctrl_->pause(); }); new Label(this, "Select Node","sans-bold"); @@ -47,9 +47,9 @@ ControlWindow::ControlWindow(nanogui::Widget *parent, ftl::ctrl::Master *ctrl) ctrl_->restart(_getActiveID()); }); - button = new Button(this, "Shutdown Node", ENTYPO_ICON_POWER_PLUG); + button = new Button(this, "Pause Node", ENTYPO_ICON_POWER_PLUG); button->setCallback([this] { - ctrl_->shutdown(_getActiveID()); + ctrl_->pause(_getActiveID()); }); _changeActive(0); diff --git a/applications/reconstruct/CMakeLists.txt b/applications/reconstruct/CMakeLists.txt index 82e0182d3a4cea97b8e85dfb29f73342378ea97d..409a425e425adadb20a340006d2e5f8d41550893 100644 --- a/applications/reconstruct/CMakeLists.txt +++ b/applications/reconstruct/CMakeLists.txt @@ -26,6 +26,6 @@ set_property(TARGET ftl-reconstruct PROPERTY CUDA_SEPARABLE_COMPILATION ON) endif() #target_include_directories(cv-node PUBLIC ${PROJECT_SOURCE_DIR}/include) -target_link_libraries(ftl-reconstruct ftlcommon ftlrgbd Threads::Threads ${OpenCV_LIBS} glog::glog ftlnet ftlrender) +target_link_libraries(ftl-reconstruct ftlcommon ftlrgbd Threads::Threads ${OpenCV_LIBS} ftlctrl ftlnet ftlrender) diff --git a/applications/reconstruct/src/main.cpp b/applications/reconstruct/src/main.cpp index a041142b6cab2bd7ba35c219d6c084518b2b9416..d1c2c095a6c9ae928416b5216694fb07be8726f3 100644 --- a/applications/reconstruct/src/main.cpp +++ b/applications/reconstruct/src/main.cpp @@ -13,6 +13,7 @@ #include <ftl/rgbd.hpp> #include <ftl/virtual_source.hpp> #include <ftl/rgbd/streamer.hpp> +#include <ftl/slave.hpp> // #include <zlib.h> // #include <lz4.h> @@ -74,6 +75,7 @@ struct Cameras { static void run(ftl::Configurable *root) { Universe *net = ftl::create<Universe>(root, "net"); + ftl::ctrl::Slave slave(net, root); net->start(); net->waitConnections(); @@ -190,7 +192,7 @@ static void run(ftl::Configurable *root) { active = 0; - if (!paused) { + if (!slave.isPaused()) { //net.broadcast("grab"); // To sync cameras scene->nextFrame(); diff --git a/components/control/cpp/include/ftl/master.hpp b/components/control/cpp/include/ftl/master.hpp index e7c8e209e11ca45d42d50dad33109b4d8fb4947d..91a913ed93b0598aac656ae5196912be6a9a1d54 100644 --- a/components/control/cpp/include/ftl/master.hpp +++ b/components/control/cpp/include/ftl/master.hpp @@ -30,6 +30,10 @@ class Master { void shutdown(const ftl::UUID &peer); + void pause(); + + void pause(const ftl::UUID &peer); + void set(const std::string &uri, ftl::config::json_t &value); void set(const ftl::UUID &peer, const std::string &uri, ftl::config::json_t &value); diff --git a/components/control/cpp/include/ftl/slave.hpp b/components/control/cpp/include/ftl/slave.hpp index d62261df150ce72523910492038bbe3446b94311..a7ae0075a27b206e1fb6a2d980928075957dcfd8 100644 --- a/components/control/cpp/include/ftl/slave.hpp +++ b/components/control/cpp/include/ftl/slave.hpp @@ -9,6 +9,10 @@ namespace ftl { namespace ctrl { +struct SystemState { + bool paused; +}; + /** * Allows a node to be remote controlled and observed over the network. All * such nodes should create a single instance of this class, but must call @@ -29,12 +33,15 @@ class Slave { */ void sendLog(const loguru::Message& message); + bool isPaused() const { return state_.paused; } + private: std::vector<ftl::UUID> log_peers_; ftl::net::Universe *net_; std::recursive_mutex mutex_; bool in_log_; bool active_; + SystemState state_; }; } diff --git a/components/control/cpp/src/master.cpp b/components/control/cpp/src/master.cpp index bd4cadfe66fb4330eeec854e8a274f805e238666..823939d64b27ba53cca6a7aacd41048d3c795c99 100644 --- a/components/control/cpp/src/master.cpp +++ b/components/control/cpp/src/master.cpp @@ -53,6 +53,14 @@ void Master::shutdown(const ftl::UUID &peer) { net_->send(peer, "shutdown"); } +void Master::pause() { + net_->broadcast("pause"); +} + +void Master::pause(const ftl::UUID &peer) { + net_->send(peer, "pause"); +} + void Master::set(const string &uri, json_t &value) { net_->broadcast("update_cfg", uri, (string)value); } diff --git a/components/control/cpp/src/slave.cpp b/components/control/cpp/src/slave.cpp index e0740b3c29687fbb0979b1859a9c3dbda31ff4eb..b4823e1d11f1df861e27dca5818ccf7f3b9ae901 100644 --- a/components/control/cpp/src/slave.cpp +++ b/components/control/cpp/src/slave.cpp @@ -13,6 +13,10 @@ static void netLog(void* user_data, const loguru::Message& message) { } Slave::Slave(Universe *net, ftl::Configurable *root) : net_(net), in_log_(false), active_(true) { + + // Init system state + state_.paused = false; + net->bind("restart", []() { LOG(WARNING) << "Remote restart..."; //exit(1); @@ -26,6 +30,10 @@ Slave::Slave(Universe *net, ftl::Configurable *root) : net_(net), in_log_(false) ftl::running = false; }); + net->bind("pause", [this]() { + state_.paused = !state_.paused; + }); + net->bind("update_cfg", [](const std::string &uri, const std::string &value) { ftl::config::update(uri, nlohmann::json::parse(value)); });