From f7806adc66fbe79f1e2d08f33015789ae1252601 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Wed, 5 Jun 2019 16:41:30 +0300
Subject: [PATCH] Minor changes, attempt to receive log

---
 applications/gui/CMakeLists.txt       |  2 +-
 applications/gui/src/main.cpp         | 15 ++++++++++++---
 components/control/cpp/src/master.cpp |  3 ++-
 components/control/cpp/src/slave.cpp  |  1 +
 4 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/applications/gui/CMakeLists.txt b/applications/gui/CMakeLists.txt
index 5b1ba133f..652495e9e 100644
--- a/applications/gui/CMakeLists.txt
+++ b/applications/gui/CMakeLists.txt
@@ -18,6 +18,6 @@ target_include_directories(ftl-gui PUBLIC
 #endif()
 
 #target_include_directories(cv-node PUBLIC ${PROJECT_SOURCE_DIR}/include)
-target_link_libraries(ftl-gui ftlcommon ftlrgbd Threads::Threads ${OpenCV_LIBS} glog::glog ftlnet ftlrender nanogui GL)
+target_link_libraries(ftl-gui ftlcommon ftlctrl ftlrgbd Threads::Threads ${OpenCV_LIBS} glog::glog ftlnet ftlrender nanogui GL)
 
 
diff --git a/applications/gui/src/main.cpp b/applications/gui/src/main.cpp
index 297d7525f..fba870c53 100644
--- a/applications/gui/src/main.cpp
+++ b/applications/gui/src/main.cpp
@@ -1,8 +1,9 @@
 #include <ftl/configuration.hpp>
 #include <ftl/net/universe.hpp>
 #include <ftl/rgbd.hpp>
+#include <ftl/master.hpp>
 
-#include <glog/logging.h>
+#include <loguru.hpp>
 
 #include <opencv2/opencv.hpp>
 
@@ -148,7 +149,7 @@ class VirtualCameraView : public nanogui::ImageView {
 
 class FTLApplication : public nanogui::Screen {
 	public:
-	explicit FTLApplication(ftl::Configurable *root, ftl::net::Universe *net) : nanogui::Screen(Eigen::Vector2i(1024, 768), "FT-Lab GUI") {
+	explicit FTLApplication(ftl::Configurable *root, ftl::net::Universe *net, ftl::ctrl::Master *controller) : nanogui::Screen(Eigen::Vector2i(1024, 768), "FT-Lab GUI") {
 		using namespace nanogui;
 		net_ = net;
 
@@ -207,6 +208,11 @@ int main(int argc, char **argv) {
 
 	net->waitConnections();
 
+	ftl::ctrl::Master controller(root, net);
+	controller.onLog([](const ftl::ctrl::LogEvent &e){
+		LOG(INFO) << "Remote log: " << e.message;
+	});
+
 	/*auto available = net.findAll<string>("list_streams");
 	for (auto &a : available) {
 		std::cout << " -- " << a << std::endl;
@@ -216,7 +222,7 @@ int main(int argc, char **argv) {
 		nanogui::init();
 
 		/* scoped variables */ {
-			nanogui::ref<FTLApplication> app = new FTLApplication(root, net);
+			nanogui::ref<FTLApplication> app = new FTLApplication(root, net, &controller);
 			app->drawAll();
 			app->setVisible(true);
 			nanogui::mainloop();
@@ -233,5 +239,8 @@ int main(int argc, char **argv) {
 		return -1;
 	}
 
+	delete net;
+	delete root;
+
 	return 0;
 }
\ No newline at end of file
diff --git a/components/control/cpp/src/master.cpp b/components/control/cpp/src/master.cpp
index cba2234c2..9421a733c 100644
--- a/components/control/cpp/src/master.cpp
+++ b/components/control/cpp/src/master.cpp
@@ -11,7 +11,8 @@ using ftl::ctrl::LogEvent;
 
 Master::Master(Configurable *root, Universe *net)
 		: root_(root), net_(net) {
-	net_->bind("log", [this](const std::string &pre, const std::string &msg) {
+	net_->subscribe("log", [this](const std::string &pre, const std::string &msg) {
+		LOG(INFO) << "RECEIVE LOG";
 		for (auto f : log_handlers_) {
 			f({pre,msg});
 		}
diff --git a/components/control/cpp/src/slave.cpp b/components/control/cpp/src/slave.cpp
index 700c1da56..8a6253195 100644
--- a/components/control/cpp/src/slave.cpp
+++ b/components/control/cpp/src/slave.cpp
@@ -11,6 +11,7 @@ static void netLog(void* user_data, const loguru::Message& message) {
 }
 
 Slave::Slave(Universe *net, ftl::Configurable *root) {
+	net->createResource("log");
 	net->bind("restart", []() {
 		LOG(WARNING) << "Remote restart...";
 		exit(1);
-- 
GitLab