0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd::mods: Reorg primary interface / addl utils.

This commit is contained in:
Jason Volk 2018-10-23 11:15:21 -07:00
parent 15b300657f
commit bfa76efbc1
2 changed files with 67 additions and 53 deletions

View file

@ -25,30 +25,22 @@ namespace ircd::mods
string_view name(const mod &);
string_view path(const mod &);
bool loaded(const mod &);
bool loading(const mod &);
bool unloading(const mod &);
bool has(const mod &, const string_view &sym);
template<class T = uint8_t> const T *ptr(const mod &, const string_view &sym);
template<class T = uint8_t> T *ptr(mod &, const string_view &sym);
template<class T> const T &get(const mod &, const string_view &sym);
template<class T> T &get(mod &, const string_view &sym);
}
#include "paths.h"
#include "symbols.h"
#include "module.h"
#include "sym_ptr.h"
#include "import.h"
#include "import_shared.h"
// misc util
namespace ircd::mods
{
// Utils by name
bool loaded(const string_view &name);
bool loading(const string_view &name);
bool unloading(const string_view &name);
bool available(const string_view &name);
// Utils by path
bool is_module(const string_view &fullpath);
bool is_module(const string_view &fullpath, std::nothrow_t);
bool is_module(const string_view &fullpath, std::string &why);
@ -63,6 +55,13 @@ namespace ircd::mods
std::forward_list<std::string> available();
}
#include "paths.h"
#include "symbols.h"
#include "module.h"
#include "sym_ptr.h"
#include "import.h"
#include "import_shared.h"
// Exports down into ircd::
namespace ircd
{

View file

@ -221,6 +221,60 @@ ircd::mods::loaded(const string_view &name)
return mod::loaded.count(name);
}
template<> uint8_t *
ircd::mods::ptr<uint8_t>(mod &mod,
const string_view &sym)
{
return &mod.handle.get<uint8_t>(std::string{sym});
}
template<>
const uint8_t *
ircd::mods::ptr<const uint8_t>(const mod &mod,
const string_view &sym)
{
return &mod.handle.get<const uint8_t>(std::string{sym});
}
bool
ircd::mods::unloading(const mod &mod)
{
const auto &list(mod::unloading);
return end(list) != std::find(begin(list), end(list), &mod);
}
bool
ircd::mods::loading(const mod &mod)
{
const auto &list(mod::loading);
return end(list) != std::find(begin(list), end(list), &mod);
}
bool
ircd::mods::loaded(const mod &mod)
{
return mod.handle.is_loaded();
}
bool
ircd::mods::has(const mod &mod,
const string_view &name)
{
return mod.handle.has(std::string{name});
}
ircd::string_view
ircd::mods::name(const mod &mod)
{
return mod.name();
}
ircd::string_view
ircd::mods::path(const mod &mod)
{
return mod.location();
}
///////////////////////////////////////////////////////////////////////////////
//
// mods/import.h
@ -651,45 +705,6 @@ const
return std::find(begin(), end(), dir) != end();
}
///////////////////////////////////////////////////////////////////////////////
//
// mods/mods.h
//
template<> uint8_t *
ircd::mods::ptr<uint8_t>(mod &mod,
const string_view &sym)
{
return &mod.handle.get<uint8_t>(std::string{sym});
}
template<>
const uint8_t *
ircd::mods::ptr<const uint8_t>(const mod &mod,
const string_view &sym)
{
return &mod.handle.get<const uint8_t>(std::string{sym});
}
bool
ircd::mods::has(const mod &mod,
const string_view &name)
{
return mod.handle.has(std::string{name});
}
ircd::string_view
ircd::mods::name(const mod &mod)
{
return mod.name();
}
ircd::string_view
ircd::mods::path(const mod &mod)
{
return mod.location();
}
///////////////////////////////////////////////////////////////////////////////
//
// (internal) mods.h