meso: Implement KObjectRegistry
This commit is contained in:
@@ -389,6 +389,18 @@ class KLinkedList final {
|
||||
return nd->data;
|
||||
}
|
||||
|
||||
template< class... Args>
|
||||
T *emplace_back_or_fail(Args&&... args)
|
||||
{
|
||||
auto *nd = new typename List::Node{std::forward<Args>(args)...};
|
||||
if (nd != nullptr) {
|
||||
insert_node_after(list.last(), &nd->link);
|
||||
return &nd->data;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void pop_back()
|
||||
{
|
||||
auto *nd = list.last();
|
||||
|
||||
43
mesosphere/include/mesosphere/core/KObjectRegistry.hpp
Normal file
43
mesosphere/include/mesosphere/core/KObjectRegistry.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include <mesosphere/core/KAutoObject.hpp>
|
||||
#include <mesosphere/core/KLinkedList.hpp>
|
||||
#include <mesosphere/core/Result.hpp>
|
||||
#include <mesosphere/threading/KMutex.hpp>
|
||||
#include <cstring>
|
||||
|
||||
namespace mesosphere
|
||||
{
|
||||
|
||||
class KObjectRegistry {
|
||||
public:
|
||||
|
||||
static KObjectRegistry &GetInstance() { return instance; }
|
||||
|
||||
SharedPtr<KAutoObject> Find(const char *name) const;
|
||||
Result Register(SharedPtr<KAutoObject> obj, const char *name);
|
||||
Result Unregister(const char *name);
|
||||
|
||||
private:
|
||||
|
||||
struct Node {
|
||||
SharedPtr<KAutoObject> obj{};
|
||||
char name[12] = {0};
|
||||
|
||||
Node() = default;
|
||||
Node(SharedPtr<KAutoObject> &&obj, const char *name) : obj{obj}
|
||||
{
|
||||
std::strncpy(this->name, name, sizeof(this->name));
|
||||
}
|
||||
};
|
||||
|
||||
const Node *FindImpl(const char *name) const;
|
||||
Node *FindImpl(const char *name);
|
||||
|
||||
KLinkedList<Node> nameNodes{};
|
||||
mutable KMutex mutex{};
|
||||
|
||||
static KObjectRegistry instance;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user