Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::processes::resources::BridgeResource Class Referencefinal

A generic wrapper for a Resource that exists on a userspace server which exposes its operations as Resource operations. More...

#include <resource_bridge.h>

Inheritance diagram for MaxOS::processes::resources::BridgeResource:

Public Member Functions

 BridgeResource (const string &name, size_t flags, resource_type_t type)
 
void open (size_t flags) final
 Opens the resource.
 
void close (size_t flags) final
 Closes the resource.
 
int read (void *buffer, size_t size, size_t flags) final
 Reads data from the resource.
 
int write (const void *buffer, size_t size, size_t flags) final
 write a certain amount of bytes to a resource
 
void attach_wrapper (BridgeHandler *wrapper)
 
bool get_on_bridge ()
 Attempt to get a resource on a bridge endpoint that may not be registered yet.
 
void create_on_bridge ()
 Passes the creation of a resource to the bridge.
 

Detailed Description

A generic wrapper for a Resource that exists on a userspace server which exposes its operations as Resource operations.

Definition at line 60 of file resource_bridge.h.

Constructor & Destructor Documentation

◆ BridgeResource()

BridgeResource::BridgeResource ( const string &  name,
size_t  flags,
resource_type_t  type 
)

Definition at line 189 of file resource_bridge.cpp.

190: Resource(name, flags, type)
191{
192}
KPI::Resource Resource
Alias to make the libsyscore Resource accessible here.
Definition resource.h:26

Member Function Documentation

◆ attach_wrapper()

void BridgeResource::attach_wrapper ( BridgeHandler *  wrapper)

Definition at line 239 of file resource_bridge.cpp.

239 {
240
241 m_handler = wrapper;
242 m_id = wrapper->allocate_id();
243
244}
size_t allocate_id()
Allocates an ID to identify a resource on the bridge.

◆ close()

void BridgeResource::close ( size_t  flags)
final

Closes the resource.

Parameters
flagsOptional flags to pass (unused by default but resource type specific)

Definition at line 210 of file resource_bridge.cpp.

210 {
211 m_handler -> send_to_bridge(m_id, ServiceResourceCommand::R_CLOSE, 0,0, flags);
212}

◆ create_on_bridge()

void BridgeResource::create_on_bridge ( )

Passes the creation of a resource to the bridge.

Definition at line 262 of file resource_bridge.cpp.

262 {
263
264 // Let the bridge construct the object on its end
265 m_handler -> send_to_bridge(m_id, ServiceResourceCommand::S_CREATE, name().c_str(),name().length() + 1, 0);
266
267}

◆ get_on_bridge()

bool BridgeResource::get_on_bridge ( )

Attempt to get a resource on a bridge endpoint that may not be registered yet.

Returns
True if the resource can be fetched, False otherwise

Definition at line 251 of file resource_bridge.cpp.

251 {
252
253 // Let the bridge get the object on its end
254 return m_handler -> send_to_bridge(m_id, ServiceResourceCommand::S_GET, name().c_str(),name().length() + 1, 0) > 0;
255
256
257}

◆ open()

void BridgeResource::open ( size_t  flags)
final

Opens the resource.

Parameters
flagsOptional flags to pass (unused by default but resource type specific)

Definition at line 201 of file resource_bridge.cpp.

201 {
202 m_handler -> send_to_bridge(m_id, ServiceResourceCommand::R_OPEN, 0,0, flags);
203}

◆ read()

int BridgeResource::read ( void *  buffer,
size_t  size,
size_t  flags 
)
final

Reads data from the resource.

Parameters
bufferThe buffer to read into
sizeThe number of bytes to read
flagsThe flags to pass to the reading
Returns
The number of bytes successfully read or -1 on error

Definition at line 223 of file resource_bridge.cpp.

223 {
224 return m_handler -> send_to_bridge(m_id, ServiceResourceCommand::R_READ, buffer, size, flags);
225}

◆ write()

int BridgeResource::write ( const void *  buffer,
size_t  size,
size_t  flags 
)
final

write a certain amount of bytes to a resource

Parameters
bufferThe buffer to read from
sizeHow many bytes to write
flagsOptional flags to pass (unused by default but resource type specific)
Returns
How many bytes were successfully written

Definition at line 235 of file resource_bridge.cpp.

235 {
236 return m_handler -> send_to_bridge(m_id, ServiceResourceCommand::R_WRITE, buffer, size, flags);
237}

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