Max OS 0.3
Loading...
Searching...
No Matches
resource_bridge.h
Go to the documentation of this file.
1
9#ifndef MAXOS_PROCESSES_RESOURCES_SERVICE_RESOURCES_H
10#define MAXOS_PROCESSES_RESOURCES_SERVICE_RESOURCES_H
11
12
13#include <stddef.h>
14#include <atomic>
15#include <stdint.h>
16
17#include <libkpi/resource.h>
18
20#include <processes/process.h>
21#include <processes/scheduler.h>
22#include <processes/ipc.h>
25
26namespace MaxOS::processes::resources {
27
33
34 private:
35 size_t m_next_id = 0;
36 common::Spinlock m_lock;
37
38 uintptr_t m_shared_region;
39 KPI::service_message_ring_t* m_message_ring;
40 uintptr_t m_data_region;
41
42 size_t store_data(const void* buffer, size_t size, bool reserve_only);
43 KPI::service_resource_message_t* aquire_slot();
44
45 Process* m_owner_process;
46
47 public:
48 BridgeHandler(string const& shared_name, Process* owner_process);
50
51 size_t allocate_id();
52
53 int64_t send_to_bridge(size_t id, KPI::ServiceResourceCommand command, const void* buffer, size_t size, size_t flags);
54 };
55
60 class BridgeResource final : public Resource {
61
62 private:
63 BridgeHandler* m_handler;
64 size_t m_id;
65
66 public:
67 BridgeResource(const string& name, size_t flags, resource_type_t type);
68 ~BridgeResource() final;
69
70 void open(size_t flags) final;
71 void close(size_t flags) final;
72
73 int read(void* buffer, size_t size, size_t flags) final;
74 int write(const void* buffer, size_t size, size_t flags) final;
75
76 void attach_wrapper(BridgeHandler* wrapper);
77 bool get_on_bridge();
78 void create_on_bridge();
79
80 };
81
86 class BridgeResourceRegistry : public ResourceRegistry<BridgeResource> {
87
88 private:
89 BridgeHandler m_handler;
90
91 public:
92 BridgeResourceRegistry(const string &shared_memory_name, size_t resource_id);
94
95 Resource* get_resource(const string& name) final;
96 Resource* create_resource(const string& name, size_t flags, uintptr_t data) final;
97 };
98
99}
100
101#endif //MAXOS_PROCESSES_RESOURCES_SERVICE_RESOURCES_H
Basic doubly linked list bump memory allocator.
Definition bump.h:47
A process that can be scheduled by the Scheduler, wraps & manages threads as well as its own address ...
Definition process.h:94
A handler to manage resource commands over shared memory.
size_t allocate_id()
Allocates an ID to identify a resource on the bridge.
int64_t send_to_bridge(size_t id, KPI::ServiceResourceCommand command, const void *buffer, size_t size, size_t flags)
Send a command and its associated data to the endpoint associated with this resource.
A generic wrapper for a registry of resources that exist on a userspace server.
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.
A generic wrapper for a Resource that exists on a userspace server which exposes its operations as Re...
void close(size_t flags) final
Closes the resource.
void create_on_bridge()
Passes the creation of a resource to the bridge.
int write(const void *buffer, size_t size, size_t flags) final
write a certain amount of bytes to a resource
void open(size_t flags) final
Opens the resource.
int read(void *buffer, size_t size, size_t flags) final
Reads data from the resource.
bool get_on_bridge()
Attempt to get a resource on a bridge endpoint that may not be registered yet.
A resource registry for a specific resource type.
Definition resource.h:61
Defines a InterruptManager and InterruptHandler for managing hardware and software interrupts.
Defines inter-process communication (IPC) methods such as shared memory and message endpoints.
Defines a MemoryManager class for handling memory allocation and deallocation.
Defines Process and Thread classes for managing processes and their execution contexts.
Defines classes for managing process resources such as files and devices.
KPI::Resource Resource
Alias to make the libsyscore Resource accessible here.
Definition resource.h:26
KPI::ResourceType resource_type_t
Alias to make the libsyscore ResourceType accessible here.
Definition resource.h:25
Defines a GlobalScheduler and Scheduler for managing processes and threads.