make lmq object a global singleton in the gui
This commit is contained in:
parent
ce1ad4a53f
commit
8a0fc14339
|
@ -9,7 +9,6 @@
|
|||
ApiPoller::ApiPoller() :
|
||||
QObject(nullptr)
|
||||
{
|
||||
m_lmq.start();
|
||||
m_timer = new QTimer();
|
||||
m_timer->setInterval(DEFAULT_POLLING_INTERVAL_MS);
|
||||
connect(m_timer, &QTimer::timeout, this, &ApiPoller::pollDaemon);
|
||||
|
@ -54,13 +53,13 @@ void ApiPoller::pollDaemon() {
|
|||
}
|
||||
if(not m_Conn.has_value())
|
||||
{
|
||||
m_Conn = m_lmq.connect_remote(RPCURL, [](auto &&){},
|
||||
m_Conn = lmq.connect_remote(RPCURL, [](auto &&){},
|
||||
[=](auto,auto msg) {
|
||||
qInfo() << std::string{msg}.c_str();
|
||||
m_Conn = std::nullopt;
|
||||
});
|
||||
}
|
||||
m_lmq.request(*m_Conn, m_rpcMethod,
|
||||
lmq.request(*m_Conn, m_rpcMethod,
|
||||
[=](bool success, std::vector<std::string> data)
|
||||
{
|
||||
if(success and not data.empty())
|
||||
|
|
|
@ -8,9 +8,8 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QTimer>
|
||||
|
||||
#include <lokimq/lokimq.h>
|
||||
|
||||
|
||||
/**
|
||||
* The ApiPoller periodically requests a JSON-RPC endpoint from the Loki daemon.
|
||||
*/
|
||||
|
@ -77,7 +76,6 @@ private:
|
|||
void pollDaemon();
|
||||
|
||||
QTimer* m_timer;
|
||||
lokimq::LokiMQ m_lmq;
|
||||
std::optional<lokimq::ConnectionID> m_Conn;
|
||||
std::string m_rpcMethod;
|
||||
};
|
||||
|
|
|
@ -9,9 +9,8 @@ bool LokinetApiClient::invoke(const std::string& endpoint, QJsonObject args, Rep
|
|||
std::cout << "call " << endpoint;
|
||||
if(not m_lmqConnection.has_value())
|
||||
{
|
||||
m_lmqClient.start();
|
||||
m_lmqConnection =
|
||||
m_lmqClient.connect_remote(
|
||||
lmq.connect_remote(
|
||||
RPCURL,
|
||||
[](auto){},
|
||||
[&](auto, std::string_view reason) {
|
||||
|
@ -21,7 +20,7 @@ bool LokinetApiClient::invoke(const std::string& endpoint, QJsonObject args, Rep
|
|||
}
|
||||
QJsonDocument doc(args);
|
||||
const auto req = doc.toJson();
|
||||
m_lmqClient.request(
|
||||
lmq.request(
|
||||
*m_lmqConnection,
|
||||
std::string_view{endpoint},
|
||||
[cb = callback](bool success, std::vector<std::string> data)
|
||||
|
|
|
@ -98,7 +98,6 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
lokimq::LokiMQ m_lmqClient;
|
||||
std::optional<lokimq::ConnectionID> m_lmqConnection;
|
||||
signals:
|
||||
void
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
|
||||
#include <lokimq/lokimq.h>
|
||||
|
||||
|
||||
constexpr auto LOKINET_RPC_URL = "tcp://127.0.0.1:1190";
|
||||
|
||||
extern std::string RPCURL;
|
||||
|
||||
extern lokimq::LokiMQ lmq;
|
||||
|
|
|
@ -17,7 +17,8 @@ constexpr bool isSystemd = true;
|
|||
constexpr bool isSystemd = false;
|
||||
#endif
|
||||
|
||||
std::string RPCURL = LOKINET_RPC_URL;
|
||||
lokimq::LokiMQ lmq{};
|
||||
std::string RPCURL{LOKINET_RPC_URL};
|
||||
|
||||
int32_t main(int32_t argc, char *argv[])
|
||||
{
|
||||
|
@ -57,6 +58,8 @@ int32_t main(int32_t argc, char *argv[])
|
|||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||
#endif
|
||||
|
||||
lmq.start();
|
||||
|
||||
QApplication app(argc, argv);
|
||||
app.setWindowIcon(QIcon(":/res/images/icon.svg"));
|
||||
|
|
Loading…
Reference in New Issue