Valkka  1.6.1
OpenSource Video Management
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
SharedMemSegment Class Referenceabstract

Handles a shared memory segment with metadata (the segment size) More...

#include <sharedmem.h>

Inheritance diagram for SharedMemSegment:
Inheritance graph
[legend]

Public Member Functions

 SharedMemSegment (const char *name, std::size_t n_bytes, bool is_server=false)
 Default constructor. More...
 
virtual ~SharedMemSegment ()
 Default destructor.
 
virtual std::size_t getSize ()=0
 Client: return size of payload.
 
virtual void put (std::vector< uint8_t > &inp_payload, void *meta_)=0
 Server: copy byte chunk into payload accompanied with metadata. Corrent typecast in child class methods.
 
virtual void put (uint8_t *buf_, void *meta_)=0
 
virtual void copyMetaFrom (void *meta_)=0
 Dereference metadata pointer correctly and copy the contents into this memory segment's metadata.
 
virtual void copyMetaTo (void *meta_)=0
 Dereference metadata pointer correctly and copy the contents from this memory segment's metadata.
 
void init ()
 Must be called after construction. Reserves shmem payload and correct metadata (depending on the subclass)
 
void close_ ()
 Must be called before destruction. Releases correct amount of metadata bytes (depending on the subclass)
 
bool getClientState ()
 Was the shmem acquisition succesfull?
 

Public Attributes

uint8_t * payload
 Pointer to payload.
 
std::size_t n_bytes
 Maximum size of the payload (this much is reserved)
 

Protected Member Functions

virtual void serverInit ()=0
 Server: Uses shmem_open with write rights. used by the constructor if is_server=true. Init with correct metadata serialization.
 
virtual bool clientInit ()=0
 Client: Uses shmem_open with read-only rights. Init with correct metadata serialization.
 
virtual void serverClose ()=0
 Erases the shmem segment. used by the constructor if is_server=true.
 
virtual void clientClose ()=0
 

Protected Attributes

std::string name
 Name to identify the posix objects.
 
std::string payload_name
 Name to identify the posix memory mapped file.
 
std::string meta_name
 Name to identify the posix memory mapped file for the metadata.
 
bool is_server
 Client or server process?
 
void * ptr
 
void * ptr_
 Raw pointers to shared memory.
 
bool client_state
 Was the shmem acquisition succesfull?
 

Detailed Description

Handles a shared memory segment with metadata (the segment size)

First, instantiate a shared memory segment in the server side, with is_server=true

Second, from another process, instantiate shared memory segment with the same name, but with is_server=false

Never instantiate both server and client side from the same process.

This is a virtual class. Child classes should define metadata and its serialization. This is done in serverInit, serverClose, clientInit and clientClose

Constructor & Destructor Documentation

◆ SharedMemSegment()

SharedMemSegment::SharedMemSegment ( const char *  name,
std::size_t  n_bytes,
bool  is_server = false 
)

Default constructor.

Parameters
nameString identifying the shmem segment in the posix shmem system
n_bytesSize of the byte buffer
is_serverIn the server side, instantiate with true, in client side, instantiate with false

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