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
|
|
|
|
{
|
|
|
|
struct site;
|
|
|
|
struct list;
|
|
|
|
|
|
|
|
IRCD_EXCEPTION(ircd::error, error)
|
|
|
|
|
|
|
|
struct list static list;
|
|
|
|
|
|
|
|
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;
|
|
|
|
bool registered;
|
|
|
|
|
|
|
|
string_view site_name() 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));
|
|
|
|
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
|
|
|
|
/// and registers itself with the master extern hook::list. Each hook
|
|
|
|
/// then registers itself with a hook::site. The site contains internal
|
|
|
|
/// state to manage the efficient calling of the participating hooks.
|
|
|
|
struct ircd::m::hook::site
|
|
|
|
{
|
|
|
|
json::strung _feature;
|
|
|
|
json::object feature;
|
|
|
|
bool registered;
|
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;
|
|
|
|
|
|
|
|
friend class hook;
|
|
|
|
bool add(hook &);
|
|
|
|
bool del(hook &);
|
|
|
|
|
|
|
|
public:
|
|
|
|
void operator()(const event &);
|
|
|
|
|
|
|
|
site(const json::members &);
|
|
|
|
site(site &&) = delete;
|
|
|
|
site(const site &) = delete;
|
|
|
|
~site() noexcept;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// The hook list is the registry of all of the hook sites. This is a singleton
|
|
|
|
/// class with an extern instance. Each hook::site will register itself here
|
|
|
|
/// by human readable name.
|
|
|
|
struct ircd::m::hook::list
|
|
|
|
:std::map<string_view, hook::site *>
|
|
|
|
{
|
|
|
|
friend class site;
|
|
|
|
bool add(site &);
|
|
|
|
bool del(site &);
|
|
|
|
|
|
|
|
friend class hook;
|
|
|
|
bool add(hook &);
|
|
|
|
bool del(hook &);
|
|
|
|
|
|
|
|
public:
|
|
|
|
list() = default;
|
|
|
|
list(list &&) = delete;
|
|
|
|
list(const list &) = delete;
|
|
|
|
};
|