Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::processes::resources::BridgeResourceRegistry Class Reference

A generic wrapper for a registry of resources that exist on a userspace server. More...

#include <resource_bridge.h>

Inheritance diagram for MaxOS::processes::resources::BridgeResourceRegistry:
MaxOS::processes::resources::ResourceRegistry< BridgeResource > MaxOS::processes::resources::BaseResourceRegistry

Public Member Functions

 BridgeResourceRegistry (const string &shared_memory_name, size_t resource_id)
 
Resource * get_resource (const string &name) final
 Gets a resource from the registry by name.
 
Resource * create_resource (const string &name, size_t flags, uintptr_t data) final
 Create a new resource on the bridge.
 
- Public Member Functions inherited from MaxOS::processes::resources::ResourceRegistry< BridgeResource >
 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.
 

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

A generic wrapper for a registry of resources that exist on a userspace server.

Definition at line 86 of file resource_bridge.h.

Constructor & Destructor Documentation

◆ BridgeResourceRegistry()

BridgeResourceRegistry::BridgeResourceRegistry ( const string &  shared_memory_name,
size_t  resource_id 
)

Definition at line 270 of file resource_bridge.cpp.

271: ResourceRegistry((resource_type_t)resource_id),
272 m_handler(shared_name, GlobalScheduler::current_process())
273{
274
275}
static Process * current_process()
Gets the process on the currently executing core.
A resource registry for a specific resource type.
Definition resource.h:61
KPI::ResourceType resource_type_t
Alias to make the libsyscore ResourceType accessible here.
Definition resource.h:25

Member Function Documentation

◆ create_resource()

Resource * BridgeResourceRegistry::create_resource ( const string &  name,
size_t  flags,
uintptr_t  data 
)
finalvirtual

Create a new resource on the bridge.

Parameters
nameThe name of the resource
flagsThe flags to pass
Returns
The new resource

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

Definition at line 308 of file resource_bridge.cpp.

308 {
309
310 // Create the resource
311 auto resource = new BridgeResource(name, flags, m_type);
312
313 // Creation failed
314 if(!register_resource(resource)) {
315 delete resource;
316 return nullptr;
317 }
318
319 // Handoff setup to bridge
320 resource->attach_wrapper(&m_handler);
321 resource->create_on_bridge();
322 return resource;
323}
resource_type_t m_type
The resource type that this registry manages.
Definition resource.h:40
bool register_resource(Resource *resource)
Registers a resource in the registry.
Definition resource.cpp:76
A generic wrapper for a Resource that exists on a userspace server which exposes its operations as Re...

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

◆ get_resource()

Resource * BridgeResourceRegistry::get_resource ( const string &  name)
finalvirtual

Gets a resource from the registry by name.

Parameters
nameThe name of the resource to find
Returns
The resource or nullptr if the resource was not found

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

Definition at line 279 of file resource_bridge.cpp.

279 {
280
281 // Resource already opened
282 auto resource = BaseResourceRegistry::get_resource(name);
283 if(resource != nullptr)
284 return resource;
285
286 // Setup a temporary resource
287 auto attempt_resource = new BridgeResource(name, 0, m_type);
288 attempt_resource->attach_wrapper(&m_handler);
289
290 // Try open on the server
291 if (attempt_resource->get_on_bridge()) {
292 register_resource(attempt_resource);
293 return attempt_resource;
294 }
295
296 // Must have failed to get on server
297 delete attempt_resource;
298 return nullptr;
299}
virtual Resource * get_resource(const string &name)
Gets a resource from the registry by name.
Definition resource.cpp:52

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


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