Skip to content

Instantly share code, notes, and snippets.

@madmongo1
Created November 23, 2020 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madmongo1/ecb5fa42da0ed4748913e8a87c34c50e to your computer and use it in GitHub Desktop.
Save madmongo1/ecb5fa42da0ed4748913e8a87c34c50e to your computer and use it in GitHub Desktop.
#include "mark_view.hpp"
#include <boost/scope_exit.hpp>
#include <fmt/ostream.h>
#include <spdlog/spdlog.h>
#include <util/co_dispatch.hpp>
namespace program
{
auto
program::mark_view::main_loop() -> net::awaitable< void >
{
spdlog::debug("mark_view: {}", __func__);
auto feed = trade::deribit_index_price_names(service_);
auto conn = co_await feed.subscribe();
bool is_running = true;
auto stop =
stop_signal_.connect_extended([&](sigs::connection c) {
c.disconnect();
is_running = false;
conn.disconnect();
});
BOOST_SCOPE_EXIT_ALL(&) { stop.disconnect(); };
while (is_running)
{
auto snap = co_await conn.consume();
spdlog::info("mark_view: snapshot: {}", snap);
this->setColumnCount(1);
this->setRowCount(snap.names().size());
setHorizontalHeaderLabels(QStringList { tr("Currency Pairs") });
for (std::size_t i = 0; i < snap.names().size(); ++i)
{
auto item = new QTableWidgetItem();
item->setText(QString::fromStdString(snap.names()[i]));
item->setTextAlignment(Qt::AlignCenter);
setItem(i, 0, item);
}
}
spdlog::debug("mark_view: exit {}", __func__);
}
void
mark_view::closeEvent(QCloseEvent *event)
{
spdlog::debug("mark_view: {}", __func__);
destroy_guard();
QWidget::closeEvent(event);
}
void
mark_view::hideEvent(QHideEvent *event)
{
spdlog::debug("mark_view: {}", __func__);
stop_signal_();
QWidget::hideEvent(event);
}
void
mark_view::showEvent(QShowEvent *event)
{
spdlog::debug("mark_view: {}", __func__);
new_guard();
net::co_spawn(get_executor(), main_loop(), net::detached);
QWidget::showEvent(event);
}
mark_view::mark_view(entity::entity_service service,
QWidget * parent)
: QTableWidget(parent)
, service_(std::move(service))
{
}
} // namespace program
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment