2018-02-09 08:35:42 +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.
|
|
|
|
|
|
|
|
namespace ircd::mods
|
|
|
|
{
|
2019-02-08 05:51:38 +01:00
|
|
|
extern const std::string prefix;
|
|
|
|
extern const std::string suffix;
|
2018-02-09 08:35:42 +01:00
|
|
|
|
2019-02-08 05:51:38 +01:00
|
|
|
template<class R, class F> R info(const string_view &, F&& closure);
|
2018-02-09 08:35:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Internal module representation
|
|
|
|
struct ircd::mods::mod
|
|
|
|
:std::enable_shared_from_this<mod>
|
|
|
|
{
|
2018-10-23 19:46:45 +02:00
|
|
|
static std::forward_list<mod *> loading; // State of current dlopen() recursion.
|
2018-10-23 19:59:16 +02:00
|
|
|
static std::forward_list<mod *> unloading; // dlclose() is not recursive but we have this
|
2018-03-25 23:32:24 +02:00
|
|
|
static std::map<string_view, mod *, std::less<>> loaded;
|
2018-02-09 08:35:42 +01:00
|
|
|
|
2019-02-08 05:51:38 +01:00
|
|
|
std::string path;
|
2018-02-09 08:35:42 +01:00
|
|
|
load_mode::type mode;
|
|
|
|
std::deque<mod *> children;
|
2019-02-10 00:51:55 +01:00
|
|
|
std::map<std::string, std::string> exports;
|
2018-02-09 08:35:42 +01:00
|
|
|
boost::dll::shared_library handle;
|
|
|
|
const std::string _name;
|
|
|
|
const std::string _location;
|
|
|
|
mapi::header *header;
|
|
|
|
|
|
|
|
// Metadata
|
2018-10-25 22:03:07 +02:00
|
|
|
const string_view &operator[](const string_view &s) const;
|
|
|
|
string_view &operator[](const string_view &s);
|
2018-02-09 08:35:42 +01:00
|
|
|
|
2018-10-25 22:03:07 +02:00
|
|
|
// Convenience accessors
|
2018-02-09 08:35:42 +01:00
|
|
|
auto &name() const { return _name; }
|
|
|
|
auto &location() const { return _location; }
|
|
|
|
auto &version() const { return header->version; }
|
|
|
|
auto &description() const { return (*this)["description"]; }
|
|
|
|
|
|
|
|
bool unload();
|
|
|
|
|
2019-02-08 05:51:38 +01:00
|
|
|
explicit mod(std::string path, const load_mode::type &);
|
2018-02-09 08:35:42 +01:00
|
|
|
|
2018-03-26 00:25:32 +02:00
|
|
|
mod(mod &&) = delete;
|
|
|
|
mod(const mod &) = delete;
|
|
|
|
mod &operator=(mod &&) = delete;
|
|
|
|
mod &operator=(const mod &) = delete;
|
2018-02-09 08:35:42 +01:00
|
|
|
~mod() noexcept;
|
|
|
|
};
|