xbot/snote_thread.hpp

62 lines
1.1 KiB
C++
Raw Normal View History

2023-11-25 20:09:20 -08:00
#pragma once
2023-11-27 14:12:20 -08:00
#include "event.hpp"
2023-11-25 20:09:20 -08:00
2023-11-26 21:16:56 -08:00
#include <hs.h>
#include <memory>
2023-11-25 20:09:20 -08:00
class Connection;
2023-11-26 21:16:56 -08:00
enum class SnoteTag
{
ClientConnecting,
ClientExiting,
2023-11-27 14:12:20 -08:00
RejectingKlined,
NickChange,
CreateChannel,
TemporaryKlineExpired,
DisconnectingKlined,
2023-11-26 21:16:56 -08:00
};
2023-11-25 20:09:20 -08:00
struct SnoteEvent : Event
{
2023-11-26 21:16:56 -08:00
SnoteEvent(SnoteTag tag, std::vector<std::string_view> parts)
: tag{tag}
, parts{std::move(parts)}
{}
SnoteTag tag;
std::vector<std::string_view> parts;
2023-11-25 20:09:20 -08:00
};
2023-11-26 21:16:56 -08:00
struct SnoteThread
{
struct DbDeleter
{
auto operator()(hs_database_t * db) const -> void
{
if (HS_SUCCESS != hs_free_database(db))
{
abort();
}
}
};
struct ScratchDeleter
{
auto operator()(hs_scratch_t * scratch) const -> void
{
if (HS_SUCCESS != hs_free_scratch(scratch))
{
abort();
}
}
};
std::unique_ptr<hs_database_t, DbDeleter> db_;
std::unique_ptr<hs_scratch_t, ScratchDeleter> scratch_;
static auto start(Connection& connection) -> std::shared_ptr<SnoteThread>;
};