jay/connection/connection.h

48 lines
1.1 KiB
C++

// SPDX-FileCopyrightText: 2024 Yury Gubich <blue@macaw.me>
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <memory>
#include <gloox/client.h>
#include <gloox/message.h>
#include <gloox/disco.h>
#include <gloox/connectionlistener.h>
#include <gloox/messagehandler.h>
#include "component/core.h"
class Connection:
public gloox::ConnectionListener,
public gloox::MessageHandler
{
public:
enum State {
initial,
disconnected,
connected
};
public:
Connection(const std::shared_ptr<Core>& core);
~Connection() noexcept;
void initiialize();
void deinitialize();
void connect();
void send(const std::string& jid, const std::string& body);
public:
void onConnect() override;
void onDisconnect(gloox::ConnectionError e) override;
bool onTLSConnect(const gloox::CertInfo&) override;
void handleMessage(const gloox::Message& message, gloox::MessageSession* session = 0) override;
private:
State state;
std::shared_ptr<Core> core;
std::unique_ptr<gloox::Client> gloox;
};