2018-04-18 09:33:38 +02: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_EVENTS_H
|
|
|
|
|
|
|
|
namespace ircd::m::events
|
|
|
|
{
|
2019-01-10 02:06:50 +01:00
|
|
|
struct range;
|
2019-08-21 03:44:58 +02:00
|
|
|
using closure = std::function<bool (const event::idx &, const event &)>;
|
2018-04-18 09:33:38 +02:00
|
|
|
|
2019-08-13 09:48:58 +02:00
|
|
|
// Iterate viable event indexes in a range
|
2019-04-16 23:42:28 +02:00
|
|
|
bool for_each(const range &, const event::closure_idx_bool &);
|
|
|
|
bool for_each(const range &, const event_filter &, const event::closure_idx_bool &);
|
|
|
|
|
2019-08-13 09:48:58 +02:00
|
|
|
// Iterate events in an index range
|
2019-08-21 03:44:58 +02:00
|
|
|
bool for_each(const range &, const closure &);
|
|
|
|
bool for_each(const range &, const event_filter &, const closure &);
|
2019-06-01 02:48:55 +02:00
|
|
|
|
|
|
|
// util
|
|
|
|
void dump__file(const string_view &filename);
|
2019-09-08 05:32:46 +02:00
|
|
|
void rebuild();
|
2018-04-18 09:33:38 +02:00
|
|
|
}
|
2019-01-10 02:06:50 +01:00
|
|
|
|
2019-08-21 03:44:58 +02:00
|
|
|
/// Interface to the types of all events known to this server.
|
|
|
|
namespace ircd::m::events::type
|
|
|
|
{
|
|
|
|
using closure = std::function<bool (const string_view &, const event::idx &)>;
|
|
|
|
using closure_name = std::function<bool (const string_view &)>;
|
|
|
|
|
|
|
|
// Iterate the names of all event types.
|
|
|
|
bool for_each(const closure_name &);
|
|
|
|
bool for_each(const string_view &prefix, const closure_name &);
|
|
|
|
|
|
|
|
// Iterate the events for a specific type.
|
|
|
|
bool for_each_in(const string_view &, const closure &);
|
2019-08-21 03:48:35 +02:00
|
|
|
|
|
|
|
// Test if type name is known to the server.
|
|
|
|
bool has_prefix(const string_view &);
|
|
|
|
bool has(const string_view &);
|
2019-08-21 03:44:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Interface to the senders of all events known to the server.
|
|
|
|
namespace ircd::m::events::sender
|
|
|
|
{
|
|
|
|
using closure = std::function<bool (const id::user &, const event::idx &)>;
|
|
|
|
using closure_name = std::function<bool (const id::user &)>;
|
|
|
|
|
|
|
|
// Iterate all of the sender mxids known to the server.
|
|
|
|
bool for_each(const closure_name &);
|
|
|
|
bool for_each(const string_view &key, const closure_name &);
|
|
|
|
|
|
|
|
// Iterate all of the events for a specific sender mxid.
|
|
|
|
bool for_each_in(const id::user &, const closure &);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Interface to the servers of the senders of all events known to this server.
|
|
|
|
namespace ircd::m::events::origin
|
|
|
|
{
|
|
|
|
using closure_name = std::function<bool (const string_view &)>;
|
|
|
|
|
|
|
|
// Iterate all server names known to this server.
|
|
|
|
bool for_each(const closure_name &);
|
|
|
|
bool for_each(const string_view &hostlb, const closure_name &);
|
|
|
|
|
|
|
|
// Iterate all senders mxids on a specific server.
|
|
|
|
bool for_each_in(const string_view &, const sender::closure &);
|
|
|
|
}
|
|
|
|
|
2020-02-27 03:17:10 +01:00
|
|
|
/// Interface to the state_key index of all events known to this server.
|
|
|
|
namespace ircd::m::events::state
|
|
|
|
{
|
|
|
|
using tuple = dbs::event_state_tuple;
|
|
|
|
using closure = std::function<bool (const tuple &)>;
|
|
|
|
|
|
|
|
bool for_each(const tuple &, const closure &);
|
|
|
|
bool for_each(const closure &);
|
|
|
|
}
|
|
|
|
|
2019-01-10 02:06:50 +01:00
|
|
|
/// Range to start (inclusive) and stop (exclusive). If start is greater than
|
|
|
|
/// stop a reverse iteration will occur. -1 (or unsigned max value) can be used
|
|
|
|
/// to start or stop at the end. 0 can be used to start or stop at the beginning.
|
2019-01-13 23:02:54 +01:00
|
|
|
/// (event::idx of 0 is a sentinel)
|
2019-01-10 02:06:50 +01:00
|
|
|
///
|
|
|
|
struct ircd::m::events::range
|
2019-02-28 23:39:15 +01:00
|
|
|
:event::idx_range
|
2019-01-10 02:06:50 +01:00
|
|
|
{
|
2019-01-10 02:57:13 +01:00
|
|
|
const event::fetch::opts *fopts {nullptr};
|
|
|
|
|
|
|
|
range(const event::idx &start,
|
|
|
|
const event::idx &stop = -1,
|
|
|
|
const event::fetch::opts *const &fopts = nullptr)
|
2019-02-28 23:39:15 +01:00
|
|
|
:event::idx_range{start, stop}
|
2019-01-10 02:57:13 +01:00
|
|
|
,fopts{fopts}
|
2019-01-10 02:06:50 +01:00
|
|
|
{}
|
|
|
|
};
|
2019-08-21 03:44:58 +02:00
|
|
|
|
|
|
|
inline bool
|
|
|
|
ircd::m::events::origin::for_each(const closure_name &closure)
|
|
|
|
{
|
|
|
|
return for_each(string_view{}, closure);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
ircd::m::events::sender::for_each(const closure_name &closure)
|
|
|
|
{
|
|
|
|
return for_each(string_view{}, closure);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
ircd::m::events::type::for_each(const closure_name &closure)
|
|
|
|
{
|
|
|
|
return for_each(string_view{}, closure);
|
|
|
|
}
|