Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::processes::resources::ResourceRegistry< Type > Class Template Reference

A resource registry for a specific resource type. More...

#include <resource.h>

Inheritance diagram for MaxOS::processes::resources::ResourceRegistry< Type >:
MaxOS::processes::resources::BaseResourceRegistry

Public Member Functions

 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.
 
- Public Member Functions inherited from MaxOS::processes::resources::BaseResourceRegistry
 BaseResourceRegistry (resource_type_t type)
 Constructs a new BaseResourceRegistry object and registers it globally.
 
 ~BaseResourceRegistry ()
 Destructor for BaseResourceRegistry, removes it from the global list.
 
resource_type_t type ()
 Gets the type of resources this registry handles.
 
bool register_resource (Resource *resource)
 Registers a resource in the registry.
 
void close_resource (Resource *resource, size_t flags)
 Close the resource provided, if it exists in this registry.
 
virtual Resource * get_resource (const string &name)
 Gets a resource from the registry by name.
 

Additional Inherited Members

- Protected Attributes inherited from MaxOS::processes::resources::BaseResourceRegistry
common::Map< string, Resource * > m_resources
 The map of resource names to resource instances.
 
common::Map< string, uint64_t > m_resource_uses
 The map of resource names to how many processes are using them.
 
common::Spinlock m_lock
 The lock to make the registry threadsafe.
 
resource_type_t m_type
 The resource type that this registry manages.
 

Detailed Description

template<class Type>
class MaxOS::processes::resources::ResourceRegistry< Type >

A resource registry for a specific resource type.

Template Parameters
TypeThe resource type that this registry manages

Definition at line 61 of file resource.h.

Constructor & Destructor Documentation

◆ ResourceRegistry()

template<class Type >
MaxOS::processes::resources::ResourceRegistry< Type >::ResourceRegistry ( resource_type_t  type)
explicit

Constructor for ResourceRegistry of a specific type.

Template Parameters
TypeThe resource type that this registry manages
Parameters
typeThe resource type enum value

Definition at line 94 of file resource.h.

resource_type_t type()
Gets the type of resources this registry handles.
Definition resource.cpp:41
BaseResourceRegistry(resource_type_t type)
Constructs a new BaseResourceRegistry object and registers it globally.
Definition resource.cpp:22

Member Function Documentation

◆ create_resource()

template<class Type >
Resource * MaxOS::processes::resources::ResourceRegistry< Type >::create_resource ( const string &  name,
size_t  flags,
uintptr_t  data 
)
inlineoverridevirtual

Create a new resource of the specific type.

Parameters
nameThe name of the resource
flagsThe flags to open the resource with
Returns
The created resource, or nullptr on failure

Reimplemented from MaxOS::processes::resources::BaseResourceRegistry.

Reimplemented in MaxOS::processes::resources::ThreadResourceRegistry.

Definition at line 74 of file resource.h.

74 {
75
76 auto resource = new Type(name, flags, type());
77
78 // Creation failed
79 if(!register_resource(resource)) {
80 delete resource;
81 return nullptr;
82 }
83
84 return resource;
85 }
bool register_resource(Resource *resource)
Registers a resource in the registry.
Definition resource.cpp:76

References MaxOS::processes::resources::BaseResourceRegistry::register_resource(), and MaxOS::processes::resources::BaseResourceRegistry::type().

Referenced by MaxOS::processes::resources::ThreadResourceRegistry::create_resource().


The documentation for this class was generated from the following file: