26#include <fmt/format.h>
34 static std::atomic<int32_t> NEXT_ID{0};
36 int32_t next_id = NEXT_ID;
37 while (next_id <= 256)
38 if (NEXT_ID.compare_exchange_weak(next_id, next_id + 1))
46 char* demangled = abi::__cxa_demangle(name,
nullptr,
nullptr,
nullptr);
47 std::string demangled2{demangled};
55 os <<
"digraph {" << std::endl;
58 for (
auto& module : modules)
59 os << fmt::format(
" \"{}\"", module.second.name) << std::endl;
62 for (
auto& module : modules)
64 for (
auto& dep :
module.second.deps)
66 os << fmt::format(" \"{}\" -> \"{}\"", module.second.name,
72 os <<
"}" << std::endl;
79 for (
auto& module : modules)
81 LOG_DEBUG(logger,
"Configuring [{}]...", module.second.name);
83 module.second.injectable->inject(injector);
87 LOG_INFO(logger,
"Configuring successful!");
89 LOG_ERR(logger,
"Failed to inject modules!");
94bool DependencyManager::insertImpl(int32_t
id,
void* raw,
102 .insert({id, ModuleInfo{
demangleName(name), raw, injectable, {}}})
106void* DependencyManager::getImpl(int32_t
id)
108 auto iter = modules.find(
id);
109 if (iter == modules.end())
112 return iter->second.raw;
115void* DependencyInjector::getImpl(int32_t
id)
117 void* ptr = manager.getImpl(
id);
121 manager.load_success =
false;
122 LOG_ERR(logger,
"[{}] requires a modules which doesn't exist",
129 info.deps.push_back(
id);
std::string demangleName(const char *name)
#define LOG_INFO(logger,...)
#define LOG_ERR(logger,...)
#define LOG_DEBUG(logger,...)
Proxy class used to obtain dependencies.
bool inject()
Inject all dependencies into all inserted .
void graphviz(std::ostream &os)
Generate a gaphviz compatible output showing dependencies. Needs to be called after inject.
Interface for an injectable dependency.
This file includes all the types the logdecoder script will decode.
int32_t getNextDependencyId()
Returns the next available id.