9#ifndef MAXOS_PROCESSES_RESOURCE_H
10#define MAXOS_PROCESSES_RESOURCE_H
20namespace MaxOS::processes {
43 virtual void open(
size_t flags);
44 virtual void close(
size_t flags);
46 virtual int read(
void* buffer,
size_t size,
size_t flags);
47 virtual int write(
const void* buffer,
size_t size,
size_t flags);
96 auto resource =
new Type(name, flags,
type());
146 uint64_t m_next_handle = 1;
Stores the left, top, width and height of a rectangle.
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.
virtual Resource * get_resource(const string &name)
Gets a resource from the registry by name.
virtual void close_resource(Resource *resource, size_t flags)
Close the resource provided, if it exists in this registry.
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.
~BaseResourceRegistry()
Destructor for BaseResourceRegistry, removes it from the global list.
virtual bool register_resource(Resource *resource)
Registers a resource in the registry.
virtual Resource * create_resource(const string &name, size_t flags)
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.
Resource * create_resource(const string &name, size_t flags) override
Create a new resource of the specific type.
ResourceRegistry(resource_type_t type)
Constructor for ResourceRegistry of a specific type.
Represents a generic resource that can be opened, closed, read from and written to.
virtual void open(size_t flags)
Opens the resource.
virtual void close(size_t flags)
Closes the resource.
string name()
Gets the name of this resource.
resource_type_t type()
Gets the type of this resource.
virtual int write(const void *buffer, size_t size, size_t flags)
write a certain amount of bytes to a resource
virtual int read(void *buffer, size_t size, size_t flags)
read a certain amount of bytes from a resource
Defines a Logger class for logging messages with different severity levels to multiple output streams...
Defines a Map class for storing key-value pairs.
::syscore::ResourceErrorBase resource_error_base_t
Alias to make the libsyscore ResourceErrorBase accessible here.
::syscore::ResourceType resource_type_t
Alias to make the libsyscore ResourceType accessible here.
Defines a String class for dynamically sized strings with various operations.
Defines the SyscallManager class for handling system calls from userspace applications.
Defines a Vector class for dynamically storing an array of elements.