2018-02-26 08:24:12 +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_HOOK_H
|
|
|
|
|
|
|
|
namespace ircd::m
|
|
|
|
{
|
|
|
|
struct hook;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ircd::m::hook
|
2018-05-07 06:53:23 +02:00
|
|
|
:instance_list<hook>
|
2018-02-26 08:24:12 +01:00
|
|
|
{
|
|
|
|
struct site;
|
|
|
|
|
|
|
|
IRCD_EXCEPTION(ircd::error, error)
|
|
|
|
|
|
|
|
json::strung _feature;
|
|
|
|
json::object feature;
|
2018-02-26 09:07:53 +01:00
|
|
|
m::event matching;
|
2018-02-26 08:24:12 +01:00
|
|
|
std::function<void (const m::event &)> function;
|
2018-05-07 06:53:23 +02:00
|
|
|
bool registered {false};
|
2018-05-13 04:52:25 +02:00
|
|
|
size_t matchers {0};
|
2018-05-13 04:43:57 +02:00
|
|
|
size_t calls {0};
|
2018-02-26 08:24:12 +01:00
|
|
|
|
|
|
|
string_view site_name() const;
|
2018-05-07 06:53:23 +02:00
|
|
|
site *find_site() const;
|
|
|
|
|
2018-02-26 09:25:48 +01:00
|
|
|
bool match(const m::event &) const;
|
2018-02-26 08:24:12 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
hook(const json::members &, decltype(function));
|
2018-03-03 06:12:11 +01:00
|
|
|
hook(decltype(function), const json::members &);
|
2018-02-26 08:24:12 +01:00
|
|
|
hook(hook &&) = delete;
|
|
|
|
hook(const hook &) = delete;
|
|
|
|
virtual ~hook() noexcept;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// The hook::site is the call-site for a hook. Each hook site is named
|
2018-05-07 06:53:23 +02:00
|
|
|
/// and registers itself with the master extern hook::site::list. Each hook
|
2018-02-26 08:24:12 +01:00
|
|
|
/// then registers itself with a hook::site. The site contains internal
|
|
|
|
/// state to manage the efficient calling of the participating hooks.
|
2018-05-06 23:53:00 +02:00
|
|
|
///
|
|
|
|
/// A hook::site can be created or destroyed at any time (for example if it's
|
|
|
|
/// in a module which is reloaded) while being agnostic to the hooks it
|
|
|
|
/// cooperates with.
|
2018-02-26 08:24:12 +01:00
|
|
|
struct ircd::m::hook::site
|
2018-05-07 06:53:23 +02:00
|
|
|
:instance_list<site>
|
2018-02-26 08:24:12 +01:00
|
|
|
{
|
|
|
|
json::strung _feature;
|
|
|
|
json::object feature;
|
2018-02-26 09:07:53 +01:00
|
|
|
size_t count {0};
|
2018-02-26 08:24:12 +01:00
|
|
|
|
|
|
|
string_view name() const;
|
|
|
|
|
|
|
|
std::multimap<string_view, hook *> origin;
|
|
|
|
std::multimap<string_view, hook *> room_id;
|
|
|
|
std::multimap<string_view, hook *> sender;
|
|
|
|
std::multimap<string_view, hook *> state_key;
|
|
|
|
std::multimap<string_view, hook *> type;
|
2018-04-27 00:17:28 +02:00
|
|
|
std::set<hook *> hooks;
|
2018-02-26 08:24:12 +01:00
|
|
|
|
|
|
|
friend class hook;
|
|
|
|
bool add(hook &);
|
|
|
|
bool del(hook &);
|
|
|
|
|
2018-03-16 21:13:33 +01:00
|
|
|
void call(hook &, const event &);
|
|
|
|
|
2018-02-26 08:24:12 +01:00
|
|
|
public:
|
|
|
|
void operator()(const event &);
|
|
|
|
|
|
|
|
site(const json::members &);
|
|
|
|
site(site &&) = delete;
|
|
|
|
site(const site &) = delete;
|
|
|
|
~site() noexcept;
|
|
|
|
};
|