Skip to content
Snippets Groups Projects
Commit b8057aeb authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Get connected slave details

parent a2565c0d
No related branches found
No related tags found
1 merge request!23Feature/gui implements #53
Pipeline #11209 passed
#include "ctrl_window.hpp" #include "ctrl_window.hpp"
#include <nanogui/layout.h> #include <nanogui/layout.h>
#include <nanogui/label.h>
#include <nanogui/combobox.h>
#include <vector>
#include <string>
using ftl::gui::ControlWindow; using ftl::gui::ControlWindow;
using std::string;
using std::vector;
ControlWindow::ControlWindow(nanogui::Widget *parent, ftl::ctrl::Master *ctrl) ControlWindow::ControlWindow(nanogui::Widget *parent, ftl::ctrl::Master *ctrl)
: nanogui::Window(parent, "Control"), ctrl_(ctrl) { : nanogui::Window(parent, "Control"), ctrl_(ctrl) {
setLayout(new nanogui::GroupLayout()); setLayout(new nanogui::GroupLayout());
using namespace nanogui;
new Label(this, "Select Node","sans-bold");
vector<string> details = ctrl->getSlaves();
LOG(INFO) << "Details count = " << details.size();
vector<string> available;
for (auto &d : details) {
auto detail = ftl::config::json_t::parse(d);
LOG(INFO) << "DETAIL RECEIVED " << detail;
available.push_back(detail["title"].get<string>());
}
auto select = new ComboBox(this, available);
select->setCallback([this,available](int ix) {
LOG(INFO) << "Change node: " << ix;
});
} }
ControlWindow::~ControlWindow() { ControlWindow::~ControlWindow() {
......
...@@ -168,6 +168,14 @@ class FTLApplication : public nanogui::Screen { ...@@ -168,6 +168,14 @@ class FTLApplication : public nanogui::Screen {
imageWindow->setLayout(new GroupLayout()); imageWindow->setLayout(new GroupLayout());
imageWindow->setSize(Vector2i(400,400)); imageWindow->setSize(Vector2i(400,400));
new Label(imageWindow, "Select source","sans-bold");
auto available = net->findAll<string>("list_streams");
auto select = new ComboBox(imageWindow, available);
select->setCallback([this,available](int ix) {
LOG(INFO) << "Change source: " << ix;
});
auto imageView = new VirtualCameraView(imageWindow); auto imageView = new VirtualCameraView(imageWindow);
//cam.view = imageView; //cam.view = imageView;
imageView->setGridThreshold(20); imageView->setGridThreshold(20);
...@@ -179,18 +187,7 @@ class FTLApplication : public nanogui::Screen { ...@@ -179,18 +187,7 @@ class FTLApplication : public nanogui::Screen {
} }
} }
auto window = new Window(this, "Sources"); auto window = new ftl::gui::ControlWindow(this, controller);
window->setLayout(new GroupLayout());
new Label(window, "Select source","sans-bold");
auto available = net->findAll<string>("list_streams");
auto select = new ComboBox(window, available);
select->setCallback([this,available](int ix) {
LOG(INFO) << "Change source: " << ix;
});
window = new ftl::gui::ControlWindow(this, controller);
setVisible(true); setVisible(true);
performLayout(); performLayout();
......
...@@ -98,6 +98,7 @@ Website: www.ilikebigbits.com ...@@ -98,6 +98,7 @@ Website: www.ilikebigbits.com
#define LOGURU_VERSION_PATCH 0 #define LOGURU_VERSION_PATCH 0
#define LOGURU_REPLACE_GLOG 1 #define LOGURU_REPLACE_GLOG 1
#define LOGURU_CATCH_SIGABRT 0
#if defined(_MSC_VER) #if defined(_MSC_VER)
#include <sal.h> // Needed for _In_z_ etc annotations #include <sal.h> // Needed for _In_z_ etc annotations
......
...@@ -37,6 +37,8 @@ class Master { ...@@ -37,6 +37,8 @@ class Master {
std::vector<std::string> getConfigurables(const ftl::UUID &peer); std::vector<std::string> getConfigurables(const ftl::UUID &peer);
std::vector<std::string> getSlaves();
std::vector<ftl::config::json_t> get(const std::string &uri); std::vector<ftl::config::json_t> get(const std::string &uri);
ftl::config::json_t getOne(const std::string &uri); ftl::config::json_t getOne(const std::string &uri);
......
...@@ -47,6 +47,10 @@ void Master::set(const ftl::UUID &peer, const string &uri, json_t &value) { ...@@ -47,6 +47,10 @@ void Master::set(const ftl::UUID &peer, const string &uri, json_t &value) {
net_->send(peer, "update_cfg", uri, (string)value); net_->send(peer, "update_cfg", uri, (string)value);
} }
vector<string> Master::getSlaves() {
return net_->findAll<string>("slave_details");
}
vector<string> Master::getConfigurables() { vector<string> Master::getConfigurables() {
return {}; return {};
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
using ftl::Configurable; using ftl::Configurable;
using ftl::net::Universe; using ftl::net::Universe;
using ftl::ctrl::Slave; using ftl::ctrl::Slave;
using std::string;
static void netLog(void* user_data, const loguru::Message& message) { static void netLog(void* user_data, const loguru::Message& message) {
Universe *net = (Universe*)user_data; Universe *net = (Universe*)user_data;
...@@ -30,6 +31,14 @@ Slave::Slave(Universe *net, ftl::Configurable *root) { ...@@ -30,6 +31,14 @@ Slave::Slave(Universe *net, ftl::Configurable *root) {
return ftl::config::resolve(uri); return ftl::config::resolve(uri);
}); });
net->bind("slave_details", [net,root]() -> std::vector<std::string> {
ftl::config::json_t json {
{"id", net->id().to_string()},
{"title", root->value("title", *root->get<string>("$id"))}
};
return {json.dump()};
});
loguru::add_callback("net_log", netLog, net, loguru::Verbosity_INFO); loguru::add_callback("net_log", netLog, net, loguru::Verbosity_INFO);
} }
......
...@@ -278,7 +278,7 @@ template <typename R, typename... ARGS> ...@@ -278,7 +278,7 @@ template <typename R, typename... ARGS>
R Universe::call(const ftl::UUID &pid, const std::string &name, ARGS... args) { R Universe::call(const ftl::UUID &pid, const std::string &name, ARGS... args) {
Peer *p = getPeer(pid); Peer *p = getPeer(pid);
if (p == nullptr) { if (p == nullptr) {
LOG(ERROR) << "Attempting to call an unknown peer : " << pid.to_string(); DLOG(WARNING) << "Attempting to call an unknown peer : " << pid.to_string();
throw -1; throw -1;
} }
return p->call<R>(name, args...); return p->call<R>(name, args...);
...@@ -288,7 +288,7 @@ template <typename... ARGS> ...@@ -288,7 +288,7 @@ template <typename... ARGS>
void Universe::send(const ftl::UUID &pid, const std::string &name, ARGS... args) { void Universe::send(const ftl::UUID &pid, const std::string &name, ARGS... args) {
Peer *p = getPeer(pid); Peer *p = getPeer(pid);
if (p == nullptr) { if (p == nullptr) {
LOG(ERROR) << "Attempting to call an unknown peer : " << pid.to_string(); DLOG(WARNING) << "Attempting to call an unknown peer : " << pid.to_string();
throw -1; throw -1;
} }
p->send(name, args...); p->send(name, args...);
......
...@@ -61,6 +61,7 @@ class Streamer : public ftl::Configurable { ...@@ -61,6 +61,7 @@ class Streamer : public ftl::Configurable {
std::shared_mutex mutex_; std::shared_mutex mutex_;
bool active_; bool active_;
ftl::net::Universe *net_; ftl::net::Universe *net_;
bool late_;
void _schedule(); void _schedule();
void _swap(detail::StreamSource &); void _swap(detail::StreamSource &);
......
...@@ -24,7 +24,7 @@ using std::chrono::milliseconds; ...@@ -24,7 +24,7 @@ using std::chrono::milliseconds;
#define THREAD_POOL_SIZE 6 #define THREAD_POOL_SIZE 6
Streamer::Streamer(nlohmann::json &config, Universe *net) Streamer::Streamer(nlohmann::json &config, Universe *net)
: ftl::Configurable(config), pool_(THREAD_POOL_SIZE) { : ftl::Configurable(config), pool_(THREAD_POOL_SIZE), late_(false) {
active_ = false; active_ = false;
net_ = net; net_ = net;
...@@ -169,11 +169,15 @@ void Streamer::_schedule() { ...@@ -169,11 +169,15 @@ void Streamer::_schedule() {
shared_lock<shared_mutex> slk(s.second->mutex); shared_lock<shared_mutex> slk(s.second->mutex);
if (s.second->state != 0) { if (s.second->state != 0) {
LOG(WARNING) << "Stream not ready to schedule on time: " << uri; if (!late_) LOG(WARNING) << "Stream not ready to schedule on time: " << uri;
late_ = true;
continue; continue;
} else {
late_ = false;
} }
if (s.second->clients[0].size() == 0) { if (s.second->clients[0].size() == 0) {
LOG(ERROR) << "Stream has no clients: " << uri; //LOG(ERROR) << "Stream has no clients: " << uri;
continue; continue;
} }
slk.unlock(); slk.unlock();
...@@ -184,7 +188,7 @@ void Streamer::_schedule() { ...@@ -184,7 +188,7 @@ void Streamer::_schedule() {
src->src->grab(); src->src->grab();
unique_lock<shared_mutex> lk(src->mutex); unique_lock<shared_mutex> lk(src->mutex);
LOG(INFO) << "Grab frame"; //LOG(INFO) << "Grab frame";
src->state |= ftl::rgbd::detail::kGrabbed; src->state |= ftl::rgbd::detail::kGrabbed;
_swap(*src); _swap(*src);
}); });
...@@ -225,7 +229,7 @@ void Streamer::_schedule() { ...@@ -225,7 +229,7 @@ void Streamer::_schedule() {
} }
unique_lock<shared_mutex> lk(src->mutex); unique_lock<shared_mutex> lk(src->mutex);
LOG(INFO) << "Tx Frame: " << uri; DLOG(2) << "Tx Frame: " << uri;
src->state |= ftl::rgbd::detail::kTransmitted; src->state |= ftl::rgbd::detail::kTransmitted;
_swap(*src); _swap(*src);
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment