9#ifndef MAXOS_PROCESSES_RESOURCES_RESOURCE_H
10#define MAXOS_PROCESSES_RESOURCES_RESOURCE_H
14#include <libcommon/map.h>
15#include <libcommon/vector.h>
16#include <libcommon/string.h>
17#include <libcommon/mem.h>
18#include <libkpi/syscalls.h>
19#include <libkpi/resource.h>
23namespace MaxOS::processes::resources {
76 auto resource =
new Type(name, flags,
type());
104 common::Map<resource_type_t, BaseResourceRegistry*> m_registries;
124 common::Map<uint64_t, Resource*> m_resources;
126 uint64_t m_next_handle = 1;
132 common::Map<uint64_t, Resource*>
resources();
Manages the creation, retention and destruction of resources of a certain type. Should be subclassed ...
resource_type_t m_type
The resource type that this registry manages.
resource_type_t type()
Gets the type of resources this registry handles.
common::Spinlock m_lock
The lock to make the registry threadsafe.
virtual Resource * get_resource(const string &name)
Gets a resource from the registry by name.
void close_resource(Resource *resource, size_t flags)
Close the resource provided, if it exists in this registry.
~BaseResourceRegistry()
Destructor for BaseResourceRegistry, removes it from the global list.
common::Map< string, uint64_t > m_resource_uses
The map of resource names to how many processes are using them.
common::Map< string, Resource * > m_resources
The map of resource names to resource instances.
bool register_resource(Resource *resource)
Registers a resource in the registry.
virtual Resource * create_resource(const string &name, size_t flags, uintptr_t data)
Try to create a new resource with the specified name, will fail if the name is in use.
Manages all the resource registries for each resource type.
static void add_registry(resource_type_t type, BaseResourceRegistry *registry)
Adds a registry to the global list if there is not already one for that type.
static BaseResourceRegistry * get_registry(resource_type_t type)
Gets a registry of a type.
~GlobalResourceRegistry()
Destructor for GlobalResourceRegistry, unsets it as the current global registry if it is.
static void remove_registry(BaseResourceRegistry *registry)
Adds a registry to the global list if there is not already one for that type.
GlobalResourceRegistry()
Constructs a new GlobalResourceRegistry and sets it as the current global registry.
Manages the open resources for a process.
Resource * get_resource(uint64_t handle)
Gets a resource based on the handle id.
void close_resource(uint64_t handle, size_t flags)
Un registers the resource and then closes it.
~ResourceManager()
Destructor for ResourceManager, closes all open resources.
common::Map< uint64_t, Resource * > resources()
Get the resources currently open.
uint64_t open_resource(resource_type_t type, const string &name, size_t flags)
Registers a resource with the resource manager and then opens it.
A resource registry for a specific resource type.
ResourceRegistry(resource_type_t type)
Constructor for ResourceRegistry of a specific type.
Resource * create_resource(const string &name, size_t flags, uintptr_t data) override
Create a new resource of the specific type.
Defines a Logger class for logging messages with different severity levels to multiple output streams...
KPI::Resource Resource
Alias to make the libsyscore Resource accessible here.
KPI::ResourceType resource_type_t
Alias to make the libsyscore ResourceType accessible here.