xbot/snote_thread.hpp

57 lines
1.0 KiB
C++

#pragma once
#include "thread.hpp"
#include <hs.h>
#include <memory>
class Connection;
enum class SnoteTag
{
ClientConnecting,
ClientExiting,
};
struct SnoteEvent : Event
{
SnoteEvent(SnoteTag tag, std::vector<std::string_view> parts)
: tag{tag}
, parts{std::move(parts)}
{}
SnoteTag tag;
std::vector<std::string_view> parts;
};
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>;
};