mirror of
https://github.com/matrix-construct/construct
synced 2024-11-27 01:02:46 +01:00
d9a4f06bf6
This is not a move to c++17. If the compiler happens to have support for c++17 namespace scope resolution, they have been kind enough to backport it to gnu++14. This limits our support for really old c++14 compilers, but that was limited anyway. GCC 6.1 and clang 3.6 tested.
103 lines
2.9 KiB
C++
103 lines
2.9 KiB
C++
/*
|
|
* Copyright (C) 2016 Charybdis Development Team
|
|
* Copyright (C) 2016 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.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#pragma once
|
|
#define HAVE_IRCD_MAPI_H
|
|
|
|
namespace ircd::mapi
|
|
{
|
|
struct header;
|
|
using magic_t = uint16_t;
|
|
using version_t = uint16_t;
|
|
using metadata = std::map<std::string, std::string>;
|
|
using init_function = std::function<void ()>;
|
|
using fini_function = std::function<void ()>;
|
|
|
|
const char *const header_symbol_name
|
|
{
|
|
"IRCD_MODULE"
|
|
};
|
|
|
|
constexpr const magic_t MAGIC
|
|
{
|
|
0x4D41
|
|
};
|
|
|
|
// Used to communicate whether a module unload actually took place. dlclose() is allowed to return
|
|
// success but the actual static destruction of the module's contents doesn't lie. (mods.cc)
|
|
extern bool static_destruction;
|
|
}
|
|
|
|
struct ircd::mapi::header
|
|
{
|
|
magic_t magic; // The magic must match MAGIC
|
|
version_t version; // Version indicator
|
|
int64_t timestamp; // Module's compile epoch
|
|
init_function init; // Executed after dlopen()
|
|
fini_function fini; // Executed before dlclose()
|
|
metadata meta; // Various key-value metadata
|
|
|
|
// get and set metadata
|
|
auto &operator[](const std::string &s) const;
|
|
auto &operator[](const std::string &s);
|
|
|
|
header(const char *const &desc = "<no description>",
|
|
init_function = {},
|
|
fini_function = {});
|
|
|
|
~header() noexcept;
|
|
};
|
|
|
|
inline
|
|
ircd::mapi::header::header(const char *const &desc,
|
|
init_function init,
|
|
fini_function fini)
|
|
:magic(MAGIC)
|
|
,version(4)
|
|
,timestamp(RB_DATECODE)
|
|
,init{std::move(init)}
|
|
,fini{std::move(fini)}
|
|
,meta
|
|
{
|
|
{ "description", desc }
|
|
}
|
|
{
|
|
}
|
|
|
|
inline
|
|
ircd::mapi::header::~header()
|
|
noexcept
|
|
{
|
|
static_destruction = true;
|
|
}
|
|
|
|
inline auto &
|
|
ircd::mapi::header::operator[](const std::string &key)
|
|
{
|
|
return meta[key];
|
|
}
|
|
|
|
inline auto &
|
|
ircd::mapi::header::operator[](const std::string &key)
|
|
const
|
|
{
|
|
return meta.at(key);
|
|
}
|