20#ifndef ORES_QT_CLIENT_MANAGER_HPP
21#define ORES_QT_CLIENT_MANAGER_HPP
28#include <boost/asio/io_context.hpp>
29#include <boost/asio/executor_work_guard.hpp>
30#include <boost/uuid/uuid.hpp>
33#include "ores.comms/net/client.hpp"
34#include "ores.comms/service/remote_event_adapter.hpp"
35#include "ores.eventing/service/event_bus.hpp"
36#include "ores.utility/log/make_logger.hpp"
51 inline static std::string_view logger_name =
52 "ores.qt.client_manager";
54 [[nodiscard]]
static auto& lg() {
56 static auto instance = make_logger(logger_name);
61 explicit ClientManager(std::shared_ptr<eventing::service::event_bus> event_bus,
62 QObject* parent =
nullptr);
75 const std::string& host,
77 const std::string& username,
78 const std::string& password);
106 std::expected<comms::messaging::frame, comms::messaging::error_code>
112 std::shared_ptr<comms::net::client>
getClient()
const {
return client_; }
118 return io_context_->get_executor();
150 supported_compression_ = compression;
158 void connectionError(
const QString& message);
174 std::unique_ptr<boost::asio::io_context> io_context_;
175 std::unique_ptr<boost::asio::executor_work_guard<
176 boost::asio::io_context::executor_type>> work_guard_;
177 std::unique_ptr<std::thread> io_thread_;
180 std::shared_ptr<comms::net::client> client_;
183 std::unique_ptr<comms::service::remote_event_adapter> event_adapter_;
186 std::optional<boost::uuids::uuid> logged_in_account_id_;
189 std::shared_ptr<eventing::service::event_bus> event_bus_;
192 std::string connected_host_;
193 std::uint16_t connected_port_{0};
196 std::uint8_t supported_compression_{0x07};
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:35
Implements logging for ORE Studio.
Definition lifecycle_manager.hpp:30
Complete frame with header and payload.
Definition frame.hpp:77
Manages the lifecycle of the network client and IO context.
Definition ClientManager.hpp:47
bool logout()
Logout the current user without disconnecting.
Definition ClientManager.cpp:263
void unsubscribeFromEvent(const std::string &eventType)
Unsubscribe from server-push notifications for an event type.
Definition ClientManager.cpp:363
std::expected< comms::messaging::frame, comms::messaging::error_code > sendRequest(comms::messaging::frame request)
Send a request if connected.
Definition ClientManager.cpp:333
void notificationReceived(const QString &eventType, const QDateTime ×tamp)
Emitted when a notification is received from the server.
void subscribeToEvent(const std::string &eventType)
Subscribe to server-push notifications for an event type.
Definition ClientManager.cpp:340
bool isConnected() const
Check if currently connected.
Definition ClientManager.cpp:328
std::pair< bool, QString > connectAndLogin(const std::string &host, std::uint16_t port, const std::string &username, const std::string &password)
Connect to the server and perform login.
Definition ClientManager.cpp:80
std::shared_ptr< comms::net::client > getClient() const
Get the current client (internal use only).
Definition ClientManager.hpp:112
void disconnect()
Logout the current user and disconnect from the server.
Definition ClientManager.cpp:243
boost::asio::any_io_executor getExecutor()
Get the IO context executor.
Definition ClientManager.hpp:117
void setSupportedCompression(std::uint8_t compression)
Set the supported compression bitmask for client connections.
Definition ClientManager.hpp:149