2018-11-29 23:54:50 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_M_ROOM_STATE_H
|
|
|
|
|
|
|
|
/// Interface to room state.
|
|
|
|
///
|
|
|
|
/// This interface focuses specifically on the details of room state. Most of
|
|
|
|
/// the queries to this interface respond in logarithmic time. If an event with
|
2019-08-30 23:26:07 +02:00
|
|
|
/// a state_key is present in room::events but it is not present in room::state
|
|
|
|
/// or room::state::space it was accepted into the room but we will not apply
|
|
|
|
/// it to our machine, though other parties may (this is a state-conflict).
|
2018-11-29 23:54:50 +01:00
|
|
|
///
|
|
|
|
struct ircd::m::room::state
|
|
|
|
{
|
|
|
|
struct opts;
|
2019-05-13 19:20:06 +02:00
|
|
|
struct space;
|
2019-06-16 09:14:15 +02:00
|
|
|
struct history;
|
2019-08-22 13:32:15 +02:00
|
|
|
struct rebuild;
|
2018-11-29 23:54:50 +01:00
|
|
|
|
2019-03-08 20:21:56 +01:00
|
|
|
using closure = std::function<void (const string_view &, const string_view &, const event::idx &)>;
|
|
|
|
using closure_bool = std::function<bool (const string_view &, const string_view &, const event::idx &)>;
|
2019-02-20 22:07:40 +01:00
|
|
|
IRCD_STRONG_TYPEDEF(string_view, type_prefix)
|
2018-11-29 23:54:50 +01:00
|
|
|
|
2019-06-16 11:18:04 +02:00
|
|
|
static conf::item<bool> enable_history;
|
2018-11-29 23:54:50 +01:00
|
|
|
static conf::item<size_t> readahead_size;
|
|
|
|
|
|
|
|
room::id room_id;
|
|
|
|
event::id::buf event_id;
|
|
|
|
const event::fetch::opts *fopts {nullptr};
|
|
|
|
mutable bool _not_present {false}; // cached result of !present()
|
|
|
|
|
2019-02-13 23:27:51 +01:00
|
|
|
// Check if this object is representing the present state or a past state.
|
2018-11-29 23:54:50 +01:00
|
|
|
bool present() const;
|
|
|
|
|
2019-02-13 23:27:51 +01:00
|
|
|
// Iterate the state
|
2019-03-08 20:21:56 +01:00
|
|
|
bool for_each(const string_view &type, const string_view &lower_bound, const closure_bool &view) const;
|
2018-11-29 23:54:50 +01:00
|
|
|
bool for_each(const string_view &type, const string_view &lower_bound, const event::closure_idx_bool &view) const;
|
|
|
|
bool for_each(const string_view &type, const string_view &lower_bound, const event::id::closure_bool &view) const;
|
|
|
|
bool for_each(const string_view &type, const string_view &lower_bound, const event::closure_bool &view) const;
|
2019-03-08 20:21:56 +01:00
|
|
|
bool for_each(const string_view &type, const closure_bool &view) const;
|
2018-11-29 23:54:50 +01:00
|
|
|
bool for_each(const string_view &type, const event::closure_idx_bool &view) const;
|
|
|
|
void for_each(const string_view &type, const event::closure_idx &) const;
|
|
|
|
bool for_each(const string_view &type, const event::id::closure_bool &view) const;
|
|
|
|
void for_each(const string_view &type, const event::id::closure &) const;
|
|
|
|
bool for_each(const string_view &type, const event::closure_bool &view) const;
|
|
|
|
void for_each(const string_view &type, const event::closure &) const;
|
2019-08-16 10:19:00 +02:00
|
|
|
bool for_each(const type_prefix &type, const closure_bool &view) const;
|
2019-03-08 20:21:56 +01:00
|
|
|
bool for_each(const closure_bool &view) const;
|
2018-11-29 23:54:50 +01:00
|
|
|
bool for_each(const event::closure_idx_bool &view) const;
|
|
|
|
void for_each(const event::closure_idx &) const;
|
|
|
|
bool for_each(const event::id::closure_bool &view) const;
|
|
|
|
void for_each(const event::id::closure &) const;
|
|
|
|
bool for_each(const event::closure_bool &view) const;
|
|
|
|
void for_each(const event::closure &) const;
|
|
|
|
|
|
|
|
// Counting / Statistics
|
|
|
|
size_t count(const string_view &type) const;
|
|
|
|
size_t count() const;
|
|
|
|
|
|
|
|
// Existential
|
|
|
|
bool has(const string_view &type, const string_view &state_key) const;
|
|
|
|
bool has(const string_view &type) const;
|
2019-08-21 06:36:00 +02:00
|
|
|
bool has(const event::idx &) const;
|
2018-11-29 23:54:50 +01:00
|
|
|
|
|
|
|
// Fetch a state event
|
|
|
|
bool get(std::nothrow_t, const string_view &type, const string_view &state_key, const event::closure_idx &) const;
|
|
|
|
bool get(std::nothrow_t, const string_view &type, const string_view &state_key, const event::id::closure &) const;
|
|
|
|
bool get(std::nothrow_t, const string_view &type, const string_view &state_key, const event::closure &) const;
|
|
|
|
void get(const string_view &type, const string_view &state_key, const event::closure_idx &) const;
|
|
|
|
void get(const string_view &type, const string_view &state_key, const event::id::closure &) const;
|
|
|
|
void get(const string_view &type, const string_view &state_key, const event::closure &) const;
|
2019-02-13 23:27:51 +01:00
|
|
|
event::idx get(std::nothrow_t, const string_view &type, const string_view &state_key = "") const;
|
|
|
|
event::idx get(const string_view &type, const string_view &state_key = "") const;
|
2018-11-29 23:54:50 +01:00
|
|
|
|
2019-09-18 22:34:23 +02:00
|
|
|
// Prefetch state cells
|
|
|
|
bool prefetch(const string_view &type, const string_view &state_key) const;
|
|
|
|
bool prefetch(const string_view &type) const;
|
2018-11-29 23:54:50 +01:00
|
|
|
|
|
|
|
state(const m::room &room, const event::fetch::opts *const & = nullptr);
|
|
|
|
state() = default;
|
|
|
|
state(const state &) = delete;
|
|
|
|
state &operator=(const state &) = delete;
|
2019-02-28 23:46:37 +01:00
|
|
|
|
2019-03-11 23:01:14 +01:00
|
|
|
static bool prev(const event::idx &, const event::closure_idx_bool &);
|
|
|
|
static bool next(const event::idx &, const event::closure_idx_bool &);
|
|
|
|
static event::idx prev(const event::idx &);
|
|
|
|
static event::idx next(const event::idx &);
|
|
|
|
|
2019-08-21 06:36:00 +02:00
|
|
|
static bool present(const event::idx &);
|
2019-08-16 11:16:00 +02:00
|
|
|
static size_t purge_replaced(const room::id &);
|
2019-05-07 05:47:12 +02:00
|
|
|
static bool is(std::nothrow_t, const event::idx &);
|
|
|
|
static bool is(const event::idx &);
|
2018-11-29 23:54:50 +01:00
|
|
|
};
|
2019-08-22 13:32:15 +02:00
|
|
|
|
|
|
|
struct ircd::m::room::state::rebuild
|
|
|
|
{
|
|
|
|
rebuild(const room::id &);
|
|
|
|
};
|