14using namespace MaxOS::processes;
15using namespace MaxOS::processes::resources;
119 resource->close(flags);
150 if(s_current ==
this)
163 auto registry = s_current->m_registries.find(type);
164 if(registry == s_current->m_registries.end())
167 return registry->second;
179 if(s_current->m_registries.find(type) != s_current->m_registries.end())
182 s_current->m_registries.insert(type, registry);
193 if(s_current->m_registries.find(registry->
type()) == s_current->m_registries.end())
196 s_current->m_registries.erase(registry->
type());
200ResourceManager::ResourceManager() =
default;
208 common::Vector<uint64_t> handles;
209 for (
const auto& kv : m_resources)
210 handles.push_back(kv.first);
213 for (
auto h : handles)
249 m_resources.insert(m_next_handle, resource);
252 resource->open(flags);
253 return m_next_handle++;
264 auto it = m_resources.find(handle);
265 if(it == m_resources.end())
270 m_resources.erase(handle);
284 if(m_resources.find(handle) == m_resources.end())
287 return m_resources[handle];
298 for(
const auto& resource : m_resources)
299 if(resource.second->name() == name)
300 return resource.second;
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.
BaseResourceRegistry(resource_type_t type)
Constructs a new BaseResourceRegistry object and registers it globally.
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.
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.
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.
Defines classes for managing process resources such as files and devices.
KPI::Resource Resource
Alias to make the libsyscore Resource accessible here.
KPI::ResourceType resource_type_t
Alias to make the libsyscore ResourceType accessible here.
Defines scheduler resource classes for wrapping Processe and Thread objects as Resources in the Globa...