2018-02-04 03:22:01 +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.
|
MAPI IV. This iteration leverages the C++11 standardized RTTI.
* Simplifies the export declarations for module developers. While
MAPI III utilized a flexible key-value vector to eliminate positional
arguments in a header initializer, now the developer simply makes
a list of pointers to what they want to export for injection into
IRCd. Example:
mapi::header IRCD_MODULE
{
"mymod",
"My module adds a command, a hook, and a CLICAP",
&my_cmdtab,
&some_hook,
&clicaptab
};
* Distributes the handlers for items passed to the above vector.
Anyone can add a type-handler to the module system from anywhere in IRCd
(and other modules?) When your type is encountered a handler is called
providing the symbol name to read out of the module. Example in parser.cc:
mods::add_loader<Message>([]
(mod &loading, const std::string &symbol)
{
auto &msg(get<Message>(loading, symbol));
add_command(msg.name, msg);
});
2016-08-29 21:09:59 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_MAPI_H
|
|
|
|
|
2017-09-12 18:37:44 +02:00
|
|
|
/// Module API: Interface for module developers.
|
2017-08-28 23:51:22 +02:00
|
|
|
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 ()>;
|
MAPI IV. This iteration leverages the C++11 standardized RTTI.
* Simplifies the export declarations for module developers. While
MAPI III utilized a flexible key-value vector to eliminate positional
arguments in a header initializer, now the developer simply makes
a list of pointers to what they want to export for injection into
IRCd. Example:
mapi::header IRCD_MODULE
{
"mymod",
"My module adds a command, a hook, and a CLICAP",
&my_cmdtab,
&some_hook,
&clicaptab
};
* Distributes the handlers for items passed to the above vector.
Anyone can add a type-handler to the module system from anywhere in IRCd
(and other modules?) When your type is encountered a handler is called
providing the symbol name to read out of the module. Example in parser.cc:
mods::add_loader<Message>([]
(mod &loading, const std::string &symbol)
{
auto &msg(get<Message>(loading, symbol));
add_command(msg.name, msg);
});
2016-08-29 21:09:59 +02:00
|
|
|
|
2017-08-28 23:51:22 +02:00
|
|
|
const char *const header_symbol_name
|
|
|
|
{
|
|
|
|
"IRCD_MODULE"
|
|
|
|
};
|
MAPI IV. This iteration leverages the C++11 standardized RTTI.
* Simplifies the export declarations for module developers. While
MAPI III utilized a flexible key-value vector to eliminate positional
arguments in a header initializer, now the developer simply makes
a list of pointers to what they want to export for injection into
IRCd. Example:
mapi::header IRCD_MODULE
{
"mymod",
"My module adds a command, a hook, and a CLICAP",
&my_cmdtab,
&some_hook,
&clicaptab
};
* Distributes the handlers for items passed to the above vector.
Anyone can add a type-handler to the module system from anywhere in IRCd
(and other modules?) When your type is encountered a handler is called
providing the symbol name to read out of the module. Example in parser.cc:
mods::add_loader<Message>([]
(mod &loading, const std::string &symbol)
{
auto &msg(get<Message>(loading, symbol));
add_command(msg.name, msg);
});
2016-08-29 21:09:59 +02:00
|
|
|
|
2017-08-28 23:51:22 +02:00
|
|
|
constexpr const magic_t MAGIC
|
|
|
|
{
|
|
|
|
0x4D41
|
|
|
|
};
|
2016-11-02 23:12:56 +01:00
|
|
|
|
2017-08-28 23:51:22 +02:00
|
|
|
// 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;
|
|
|
|
}
|
MAPI IV. This iteration leverages the C++11 standardized RTTI.
* Simplifies the export declarations for module developers. While
MAPI III utilized a flexible key-value vector to eliminate positional
arguments in a header initializer, now the developer simply makes
a list of pointers to what they want to export for injection into
IRCd. Example:
mapi::header IRCD_MODULE
{
"mymod",
"My module adds a command, a hook, and a CLICAP",
&my_cmdtab,
&some_hook,
&clicaptab
};
* Distributes the handlers for items passed to the above vector.
Anyone can add a type-handler to the module system from anywhere in IRCd
(and other modules?) When your type is encountered a handler is called
providing the symbol name to read out of the module. Example in parser.cc:
mods::add_loader<Message>([]
(mod &loading, const std::string &symbol)
{
auto &msg(get<Message>(loading, symbol));
add_command(msg.name, msg);
});
2016-08-29 21:09:59 +02:00
|
|
|
|
2017-08-28 23:51:22 +02:00
|
|
|
struct ircd::mapi::header
|
2017-03-18 01:45:43 +01:00
|
|
|
{
|
2016-09-13 10:29:50 +02:00
|
|
|
magic_t magic; // The magic must match MAGIC
|
|
|
|
version_t version; // Version indicator
|
|
|
|
int64_t timestamp; // Module's compile epoch
|
2016-11-16 03:41:12 +01:00
|
|
|
init_function init; // Executed after dlopen()
|
|
|
|
fini_function fini; // Executed before dlclose()
|
2016-09-13 10:29:50 +02:00
|
|
|
metadata meta; // Various key-value metadata
|
|
|
|
|
|
|
|
// get and set metadata
|
|
|
|
auto &operator[](const std::string &s) const;
|
|
|
|
auto &operator[](const std::string &s);
|
MAPI IV. This iteration leverages the C++11 standardized RTTI.
* Simplifies the export declarations for module developers. While
MAPI III utilized a flexible key-value vector to eliminate positional
arguments in a header initializer, now the developer simply makes
a list of pointers to what they want to export for injection into
IRCd. Example:
mapi::header IRCD_MODULE
{
"mymod",
"My module adds a command, a hook, and a CLICAP",
&my_cmdtab,
&some_hook,
&clicaptab
};
* Distributes the handlers for items passed to the above vector.
Anyone can add a type-handler to the module system from anywhere in IRCd
(and other modules?) When your type is encountered a handler is called
providing the symbol name to read out of the module. Example in parser.cc:
mods::add_loader<Message>([]
(mod &loading, const std::string &symbol)
{
auto &msg(get<Message>(loading, symbol));
add_command(msg.name, msg);
});
2016-08-29 21:09:59 +02:00
|
|
|
|
2016-11-16 03:41:12 +01:00
|
|
|
header(const char *const &desc = "<no description>",
|
|
|
|
init_function = {},
|
|
|
|
fini_function = {});
|
2016-09-05 22:06:30 +02:00
|
|
|
|
2016-09-13 10:31:12 +02:00
|
|
|
~header() noexcept;
|
MAPI IV. This iteration leverages the C++11 standardized RTTI.
* Simplifies the export declarations for module developers. While
MAPI III utilized a flexible key-value vector to eliminate positional
arguments in a header initializer, now the developer simply makes
a list of pointers to what they want to export for injection into
IRCd. Example:
mapi::header IRCD_MODULE
{
"mymod",
"My module adds a command, a hook, and a CLICAP",
&my_cmdtab,
&some_hook,
&clicaptab
};
* Distributes the handlers for items passed to the above vector.
Anyone can add a type-handler to the module system from anywhere in IRCd
(and other modules?) When your type is encountered a handler is called
providing the symbol name to read out of the module. Example in parser.cc:
mods::add_loader<Message>([]
(mod &loading, const std::string &symbol)
{
auto &msg(get<Message>(loading, symbol));
add_command(msg.name, msg);
});
2016-08-29 21:09:59 +02:00
|
|
|
};
|
|
|
|
|
2016-11-16 03:41:12 +01:00
|
|
|
inline
|
2017-08-28 23:51:22 +02:00
|
|
|
ircd::mapi::header::header(const char *const &desc,
|
|
|
|
init_function init,
|
|
|
|
fini_function fini)
|
MAPI IV. This iteration leverages the C++11 standardized RTTI.
* Simplifies the export declarations for module developers. While
MAPI III utilized a flexible key-value vector to eliminate positional
arguments in a header initializer, now the developer simply makes
a list of pointers to what they want to export for injection into
IRCd. Example:
mapi::header IRCD_MODULE
{
"mymod",
"My module adds a command, a hook, and a CLICAP",
&my_cmdtab,
&some_hook,
&clicaptab
};
* Distributes the handlers for items passed to the above vector.
Anyone can add a type-handler to the module system from anywhere in IRCd
(and other modules?) When your type is encountered a handler is called
providing the symbol name to read out of the module. Example in parser.cc:
mods::add_loader<Message>([]
(mod &loading, const std::string &symbol)
{
auto &msg(get<Message>(loading, symbol));
add_command(msg.name, msg);
});
2016-08-29 21:09:59 +02:00
|
|
|
:magic(MAGIC)
|
|
|
|
,version(4)
|
|
|
|
,timestamp(RB_DATECODE)
|
2016-11-16 03:41:12 +01:00
|
|
|
,init{std::move(init)}
|
|
|
|
,fini{std::move(fini)}
|
2016-09-13 10:29:50 +02:00
|
|
|
,meta
|
|
|
|
{
|
|
|
|
{ "description", desc }
|
|
|
|
}
|
MAPI IV. This iteration leverages the C++11 standardized RTTI.
* Simplifies the export declarations for module developers. While
MAPI III utilized a flexible key-value vector to eliminate positional
arguments in a header initializer, now the developer simply makes
a list of pointers to what they want to export for injection into
IRCd. Example:
mapi::header IRCD_MODULE
{
"mymod",
"My module adds a command, a hook, and a CLICAP",
&my_cmdtab,
&some_hook,
&clicaptab
};
* Distributes the handlers for items passed to the above vector.
Anyone can add a type-handler to the module system from anywhere in IRCd
(and other modules?) When your type is encountered a handler is called
providing the symbol name to read out of the module. Example in parser.cc:
mods::add_loader<Message>([]
(mod &loading, const std::string &symbol)
{
auto &msg(get<Message>(loading, symbol));
add_command(msg.name, msg);
});
2016-08-29 21:09:59 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-09-13 10:31:12 +02:00
|
|
|
inline
|
2017-08-28 23:51:22 +02:00
|
|
|
ircd::mapi::header::~header()
|
2016-09-13 10:31:12 +02:00
|
|
|
noexcept
|
|
|
|
{
|
2016-11-16 03:41:12 +01:00
|
|
|
static_destruction = true;
|
2016-09-13 10:31:12 +02:00
|
|
|
}
|
|
|
|
|
2016-09-13 10:29:50 +02:00
|
|
|
inline auto &
|
2017-08-28 23:51:22 +02:00
|
|
|
ircd::mapi::header::operator[](const std::string &key)
|
2016-09-13 10:29:50 +02:00
|
|
|
{
|
|
|
|
return meta[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline auto &
|
2017-08-28 23:51:22 +02:00
|
|
|
ircd::mapi::header::operator[](const std::string &key)
|
2016-09-13 10:29:50 +02:00
|
|
|
const
|
|
|
|
{
|
|
|
|
return meta.at(key);
|
|
|
|
}
|